aboutsummaryrefslogtreecommitdiff
path: root/day16/part2
diff options
context:
space:
mode:
Diffstat (limited to 'day16/part2')
-rwxr-xr-xday16/part227
1 files changed, 27 insertions, 0 deletions
diff --git a/day16/part2 b/day16/part2
new file mode 100755
index 0000000..653822e
--- /dev/null
+++ b/day16/part2
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+BASE = [0, 1, 0, -1]
+
+input = $stdin.readlines[0].strip.chars.map(&:to_i) * 10000
+
+o = input[0...7].join.to_i
+
+def get_base(n = 1, l = 0)
+ rbase = BASE.map { |b|
+ [b] * n
+ }.flatten
+ t = ((l + 1) / rbase.length) + 1
+ (rbase * t)[1..l]
+end
+
+l = input.length
+100.times do
+ newinput = []
+ l.times do |i|
+ newinput[i] = input.zip(get_base(i+1, l)).map{|a, b| a * b}.sum.abs % 10
+ end
+ input = newinput
+end
+
+
+puts input.join[o...(o+8)]