Sha256: 8823d21a704641feb407fec81307e3a99cedf89cacc2dfb5dd39621015aec78c
Contents?: true
Size: 1002 Bytes
Versions: 3
Compression:
Stored size: 1002 Bytes
Contents
# # https://adventofcode.com/2018/day/14 part 2 # # Does not use any cem functions \o/ #recipes = "51589" #recipes = "59414" #recipes = "652601" recipes = "030121" r2 = recipes.chars.map {|c| c.to_i} storage = [0] * 100000000 storage[0] = 3 storage[1] = 7 e0 = 0 e1 = 1 comp = [0] * r2.length i = 2 while true puts i if i % 100000 == 0 s0 = storage[e0] s1 = storage[e1] r = s0 + s1 if r >= 10 storage[i] = 1 i+=1 comp << 1 comp = comp.drop(1) if comp == r2 puts i - recipes.length exit end storage[i] = r - 10 i+=1 comp << r - 10 comp = comp.drop(1) if comp == r2 puts i - recipes.length exit end else storage[i] = r i+=1 comp << r comp = comp.drop(1) if comp == r2 puts i - recipes.length exit end end e0 = (1 + e0 + s0) % i e1 = (1 + e1 + s1) % i end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
cem-0.1.7 | examples/aoc2018/day14_2.rb |
cem-0.1.6 | examples/aoc2018/day14_2.rb |
cem-0.1.5 | examples/aoc2018/day14_2.rb |