Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am mgates on github.
* I am mgates (https://keybase.io/mgates) on keybase.
* I have a public key ASCV7FBXzr9moaH-DaMuR1r37ah3laWozCoc7I5GXxkbhQo
To claim this, I am signing this object:
digraph euclid {
"I-1" -> "po-3"
"I-1" -> "po-1"
"I-1" -> "de-15"
"I-1" -> "cn-1"
"I-2" -> "po-1"
"I-2" -> "po-2"
"I-2" -> "po-3"
"I-2" -> "cn-3"
@mgates
mgates / 09.rb
Created December 16, 2019 02:40
advent 2019 day 09
class Thing
def do_it_all(input)
opts = []
[0,1,2,3,4].permutation.each do |perms|
out = 0
#puts perms.inspect
(0..4).each do |amp|
inp = [perms[amp], out]
#puts inp.inspect
out = do_it(inp, input)
@mgates
mgates / 11.rb
Created December 16, 2019 02:40
advent 2019 day 11
require "set"
class Thing
def paint_it(nums)
@painted = {}
@blarf = Set.new
@dir = :up
@loc = [0,0]
@first_panel = true
@last_out = :direction
do_it([], nums, [], "foo")
@mgates
mgates / 13.rb
Created December 16, 2019 02:40
advent 2019 day 13
class Thing
def game(nums)
@screen = {}
nums[0] = 2
do_it([], nums, [], :foo)
end
def par_mode(par, is_addr, nums, pos, offset)
if is_addr
nums[pos + offset]
@mgates
mgates / 12.rb
Created December 12, 2019 18:25
advent 2019 day 12
require 'set'
class Blerg
# test
# x repeat is 2028
# y repeat is 5898
# z repeat is 4702
#
# Actual
# x repeat is
@mgates
mgates / 10.rb
Created December 12, 2019 13:55
advent 2019 day 10
require 'set'
class Ug
def foo(input)
astroids = Set.new
input.lines.map(&:chomp).each_with_index do |line, x|
line.chars.each_with_index do |char, y|
astroids << [y,x] if char == "#"
end
end
counts = {}
@mgates
mgates / 08.rb
Created December 9, 2019 01:00
advent 2019 day 8
class Blarg
def ug(input)
layer = input.chars.each_slice(25*6).min_by{|l| l.count("0") }
puts layer.inspect
puts layer.count("1") * layer.count("2")
end
def blerg(input)
output = Array(25 * 6)
input.chars.each_slice(25*6).to_a.reverse.each do |layer|
@mgates
mgates / 07.rb
Last active December 9, 2019 03:53
advent 2019 day 7
class Thing
def do_it_all(input)
opts = []
[0,1,2,3,4].permutation.each do |perms|
out = 0
#puts perms.inspect
(0..4).each do |amp|
inp = [perms[amp], out]
#puts inp.inspect
out = do_it(inp, input)
@mgates
mgates / 06.rb
Last active December 6, 2019 05:59
advent 2019 day 6
class Orbits
def do_it(lines)
@orbits = lines.lines.map(&:chomp).map {|s| s.split(")")}
total = 0
@orbits.map(&:first).each do |o|
total += count_orbits(0, o)
end
puts total
end
def count_orbits(count, orbit)