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 'json' | |
class Atom | |
attr_accessor :val, :prv, :nxt, :become | |
def initialize(val) | |
@val = val | |
end | |
def leftmost |
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 'json' | |
class Atom | |
attr_accessor :val, :prv, :nxt, :become | |
def initialize(val) | |
@val = val | |
end | |
def leftmost |
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
def bits(n) | |
[(n & 0b1000) >> 3, | |
(n & 0b0100) >> 2, | |
(n & 0b0010) >> 1, | |
n & 0b0001] | |
end | |
def from_bits(bs) | |
bs.each_with_index.sum {|b, i| b * (1 << (bs.length - i - 1))} | |
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
def bits(n) | |
[(n & 0b1000) >> 3, | |
(n & 0b0100) >> 2, | |
(n & 0b0010) >> 1, | |
n & 0b0001] | |
end | |
def from_bits(bs) | |
bs.each_with_index.sum {|b, i| b * (1 << (bs.length - i - 1))} | |
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
require 'set' | |
# i had to learn dijkstra's algo for this... | |
class Cell | |
def initialize(cave, x, y) | |
@cave = cave | |
@x = x | |
@y = y | |
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
require 'set' | |
# i had to learn dijkstra's algo for this... | |
class Cell | |
def initialize(cave, x, y) | |
@cave = cave | |
@x = x | |
@y = y | |
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
def expand(rules, dat) | |
next_dat = Hash.new(0) | |
dat.each do |(l, r), ct| | |
m = rules[[l, r]] | |
next_dat[[l, m]] += ct | |
next_dat[[m, r]] += ct | |
end | |
next_dat | |
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
def expand(rules, dat) | |
return to_enum(__method__, rules, dat) unless block_given? | |
dat.each_cons(2).each do |c| | |
yield c[0] | |
yield rules[c] | |
end | |
yield dat[-1] | |
end | |
rules = {} |
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
def expand(rules, dat) | |
return to_enum(__method__, rules, dat) unless block_given? | |
dat.each_cons(2).each do |c| | |
yield c[0] | |
yield rules[c] | |
end | |
yield dat[-1] | |
end | |
rules = {} |
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' | |
def fold(line, val) | |
if val < line | |
val | |
elsif val > line | |
line - (val - line) | |
else | |
raise "dot on line!" | |
end |
NewerOlder