diff options
author | Nat Lasseter <user@4574.co.uk> | 2019-10-22 18:40:19 +0100 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2019-10-22 18:40:19 +0100 |
commit | 487c3425a23ef52c6de3c045f1110d5e7342d042 (patch) | |
tree | 157a5c790ee7072a95dabf4a1f66e252dadcece9 /day14/part2 | |
parent | 85757e46552653685abe692d28bde663d6b4d779 (diff) |
Day 14, part 2 not working (very slow)
Diffstat (limited to 'day14/part2')
-rwxr-xr-x | day14/part2 | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/day14/part2 b/day14/part2 new file mode 100755 index 0000000..9a2c9f3 --- /dev/null +++ b/day14/part2 @@ -0,0 +1,32 @@ +#!/usr/bin/env ruby + +input = $stdin.readlines[0].strip.chars.map(&:to_i) +ilen = input.length + +scores = [3, 7] +elf1 = 0 +elf2 = 1 + +loop do + se1 = scores[elf1] + se2 = scores[elf2] + + sum = se1 + se2 + scores += sum.to_s.chars.map(&:to_i) + + slen = scores.length + + elf1 = (elf1 + 1 + se1) % slen + elf2 = (elf2 + 1 + se2) % slen + + m1 = scores[-ilen..-1] + m2 = scores[-ilen-1..-2] + + if m1 == input then + puts slen - ilen + break + elsif m2 == input then + puts slen - ilen - 1 + break + end +end |