aboutsummaryrefslogtreecommitdiff
path: root/day16/part1
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2019-12-19 17:00:18 +0000
committerNat Lasseter <user@4574.co.uk>2019-12-19 17:00:18 +0000
commite13f5c8cf9a0c6d1540de00fd128337c5ba02bea (patch)
tree02becb401ee47dfb1b5f5a099a587a9db9ae37d2 /day16/part1
parent2bb84ae6c6c71d51b445bf0b232c0eb6ca38e89b (diff)
Day16, part2 untested, runs forever
Diffstat (limited to 'day16/part1')
-rwxr-xr-xday16/part125
1 files changed, 25 insertions, 0 deletions
diff --git a/day16/part1 b/day16/part1
new file mode 100755
index 0000000..f9bbd52
--- /dev/null
+++ b/day16/part1
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+
+BASE = [0, 1, 0, -1]
+
+input = $stdin.readlines[0].strip.chars.map(&: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[0...8]