diff options
author | Nat Lasseter <Nat Lasseter nathan@bytemark.co.uk> | 2017-12-01 11:57:19 +0000 |
---|---|---|
committer | Nat Lasseter <Nat Lasseter nathan@bytemark.co.uk> | 2017-12-01 11:57:19 +0000 |
commit | 2e15fbd3a5baaefbd325453f965eb58c7b56be76 (patch) | |
tree | b2cf8111a0cced007b35bf7ee3cc483d8d1273ec /day01/part2 |
Initial commit, day01
Diffstat (limited to 'day01/part2')
-rwxr-xr-x | day01/part2 | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/day01/part2 b/day01/part2 new file mode 100755 index 0000000..c8356df --- /dev/null +++ b/day01/part2 @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby + +input = gets.chomp.chars.map(&:to_i) +l = input.length +r = l / 2 + +sum = 0 + +(0...l).each do |i| + sum += input[i] if input[i] == input[(i + r) % l] +end + +puts sum |