diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-12-04 19:26:27 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-12-04 19:26:27 +0100 |
commit | fef0d1516af784639da5cc56611da625073a3b3c (patch) | |
tree | c80cbc7e4dcd8245e0cf217048ffb1633aac1e3e | |
parent | fa3710ada8343210155caff4498ff80277ce1b45 (diff) | |
download | adventofcode2017-fef0d1516af784639da5cc56611da625073a3b3c.tar.gz adventofcode2017-fef0d1516af784639da5cc56611da625073a3b3c.tar.xz adventofcode2017-fef0d1516af784639da5cc56611da625073a3b3c.zip |
(day03.rb)
-rw-r--r-- | day03.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/day03.rb b/day03.rb new file mode 100644 index 0000000..e8b2d86 --- /dev/null +++ b/day03.rb @@ -0,0 +1,31 @@ +require 'pp' + +d = 368078 + +N = 20 +a = Array.new(N) { Array.new(N, 0) } + +x = y = N/2 +a[x][y] = 1 + +y += 1 + +2.step(10, 2) { |n| + steps = Array.new(n-1, [-1, 0]) + + Array.new(n, [ 0,-1]) + + Array.new(n, [ 1, 0]) + + Array.new(n+1, [ 0, 1]) + steps.each { |(dx,dy)| + a[x][y] = a[x-1][y-1] + a[x-1][y] + a[x-1][y+1] + + a[x ][y-1] + a[x ][y+1] + + a[x+1][y-1] + a[x+1][y] + a[x+1][y+1] + if a[x][y] > d + p a[x][y] + exit + end + x += dx + y += dy + } +} + +a.each { |l| p l } |