From aca1f4d76bae221b1207292029f57f01b2cf7035 Mon Sep 17 00:00:00 2001 From: Tudor Pavel Date: Mon, 28 Oct 2024 19:44:10 +0200 Subject: [PATCH] Year 2021 Day 1 --- 2021/day01.rb | 7 +++++++ 2021/examples/day01.txt | 10 ++++++++++ 2 files changed, 17 insertions(+) create mode 100644 2021/day01.rb create mode 100644 2021/examples/day01.txt 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