This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adapted from Wikipedia page here: https://en.wikipedia.org/wiki/Cross-entropy_method | |
import numpy as np | |
def cem(mean, variance, maxits, num_samples, num_keep, objective_fn): | |
for t in range(1, maxits + 1): | |
# Sample according to current distribution | |
x = np.random.normal(loc=mean, scale=np.sqrt(variance), size=num_samples) | |
# Evaluate samples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'set' | |
class Set | |
def to_csv | |
self.reduce("") do |accum, el| | |
accum << ",#{el}"; accum | |
end[1..-1] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var InfiniteScrollMixin = { | |
SCROLL_RATIO: 0.75, | |
CONTAINER: window, | |
CONTENT: document, | |
componentDidMount: function() { | |
this._fetchInitialData(); | |
$(this.CONTAINER).on("scroll", this._onScroll); | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'colorize' | |
class Tile | |
attr_reader :value, :given | |
def initialize(value = 0) | |
@value = value | |
@given = value != 0 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Maze | |
attr_accessor :data, :workqueue, :seen, :start, :finish, :solution | |
def initialize(filename) | |
@data = read_data(filename) | |
@start = find_letter("S") | |
@finish = find_letter("E") | |
@workqueue = [ Node.new(start, [start]) ] | |
@seen = [start] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EightQueens | |
def initialize | |
@workset = (0...64).map { |i| [i] } | |
end | |
def queen_attacks(pos) | |
(horizontal_attacks(pos) + | |
vertical_attacks(pos) + | |
main_diagonal_attacks(pos) + | |
secondary_diagonal_attacks(pos)).uniq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
# first argument: file containing uscf id numbers | |
# second argument: file you wish to write ratings to | |
if ARGV.length < 2 then return nil end | |
# gets unofficial rating | |
def get_rating(id) | |
# opens page for corresponding to id number | |
f = open("http://www.uschess.org/msa/MbrDtlTnmtHst.php?#{id}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sudoku | |
# board should be a string with numbers and dashes for spaces | |
def initialize(board) | |
@board = board.chars.to_a | |
end | |
# prints board | |
def show | |
(0...9).each {|r| |