diff --git a/2021/day01.rb b/2021/day01.rb new file mode 100644 index 0000000..966a4b7 --- /dev/null +++ b/2021/day01.rb @@ -0,0 +1,7 @@ +measurements = STDIN.read.split("\n").map(&:to_i) + +def solve(measurements, size) + measurements.each_cons(size).map(&:sum).each_cons(2).count { |a, b| a < b } +end +puts solve(measurements, 1) +puts solve(measurements, 3) diff --git a/2021/examples/day01.txt b/2021/examples/day01.txt new file mode 100644 index 0000000..167e291 --- /dev/null +++ b/2021/examples/day01.txt @@ -0,0 +1,10 @@ +199 +200 +208 +210 +200 +207 +240 +269 +260 +263