aboutsummaryrefslogtreecommitdiff
path: root/day16/part1
blob: f9bbd52886a43c7a07f5a65cecf1419f35dbd2be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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]