aboutsummaryrefslogtreecommitdiff
path: root/day01/part1
diff options
context:
space:
mode:
authorNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-01 11:57:19 +0000
committerNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-01 11:57:19 +0000
commit2e15fbd3a5baaefbd325453f965eb58c7b56be76 (patch)
treeb2cf8111a0cced007b35bf7ee3cc483d8d1273ec /day01/part1
Initial commit, day01
Diffstat (limited to 'day01/part1')
-rwxr-xr-xday01/part112
1 files changed, 12 insertions, 0 deletions
diff --git a/day01/part1 b/day01/part1
new file mode 100755
index 0000000..f230be3
--- /dev/null
+++ b/day01/part1
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+
+input = gets.chomp.chars.map(&:to_i)
+l = input.length
+
+sum = 0
+
+(0...l).each do |i|
+ sum += input[i] if input[i] == input[(i + 1) % l]
+end
+
+puts sum