Skip to content

Instantly share code, notes, and snippets.

View davidrobles's full-sized avatar

David Robles davidrobles

View GitHub Profile
def cycle(a):
n = len(a)
idx = 0
if a[idx] == 0:
return len(a) == 1
for i in range(n):
idx = (idx + a[idx]) % n
return idx == 0
assert cycle([0]) == True
@davidrobles
davidrobles / index.html
Last active August 29, 2015 14:14
Depth-First Search Game Tree
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>Tic-Tac-Toe Game Tree</title>
</head>
<body>
<script src="http://www.davidrobles.net/js/visualizing-game-trees-with-d3/underscore.js"></script>
<script src="http://www.davidrobles.net/js/visualizing-game-trees-with-d3/backbone.js"></script>
<script src="http://www.davidrobles.net/js/visualizing-game-trees-with-d3/d3.js"></script>
@davidrobles
davidrobles / index.html
Last active March 13, 2018 06:40
Breadth First Search Game Tree
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>Tic-Tac-Toe Game Tree</title>
</head>
<body>
<script src="http://www.davidrobles.net/js/visualizing-game-trees-with-d3/underscore.js"></script>
<script src="http://www.davidrobles.net/js/visualizing-game-trees-with-d3/backbone.js"></script>
<script src="http://www.davidrobles.net/js/visualizing-game-trees-with-d3/d3.js"></script>
@davidrobles
davidrobles / index.html
Last active August 29, 2015 14:14
Tic-Tac-Toe Game Tree
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>Tic-Tac-Toe Game Tree</title>
</head>
<body>
<script src="http://www.davidrobles.net/js/visualizing-game-trees-with-d3/underscore.js"></script>
<script src="http://www.davidrobles.net/js/visualizing-game-trees-with-d3/backbone.js"></script>
<script src="http://www.davidrobles.net/js/visualizing-game-trees-with-d3/d3.js"></script>
@davidrobles
davidrobles / gist:4042515
Created November 8, 2012 23:12
Printing Othello bitboards
public static void printBitBoard(long bitboard)
{
for (long i = 0; i < Othello.NUM_SQUARES; i++)
{
System.out.print(((bitboard & (1L << i)) != 0) ? " X " : " - ");
if (i % Othello.SIZE == Othello.SIZE - 1)
System.out.println();
}
@davidrobles
davidrobles / othello.java
Created November 8, 2012 22:57
Othello implementation
package dr.games.othello;
import dr.games.core.AbstractGame;
import dr.games.core.Game;
import dr.games.core.Outcome;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@davidrobles
davidrobles / gist:2864704
Created June 3, 2012 19:28
Markov Decision Process
class MDP:
def __init__(self, name, age):
self.name = name
self.age = age
def start(self):
pass
def actions(self, state):
@davidrobles
davidrobles / gist:2475231
Created April 24, 2012 01:11
Ruby Tic-Tac-Toe
class TicTacToe
WINS = ['000000111', '000111000', '111000000',
'001001001', '010010010', '100100100',
'100010001', '001010100'].map! {|x| x.to_i(2) }
attr_writer :crosses, :noughts
def initialize
reset