aboutsummaryrefslogtreecommitdiff
path: root/day01/part2
diff options
context:
space:
mode:
Diffstat (limited to 'day01/part2')
-rwxr-xr-xday01/part213
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