From fbee56d2a579d4c4122273bb0fb12ce13a825726 Mon Sep 17 00:00:00 2001 From: Tudor Pavel Date: Mon, 28 Oct 2024 19:52:28 +0200 Subject: [PATCH] Year 2022 Day 1 --- 2022/day01.rb | 7 +++++++ 2022/examples/day01.txt | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 2022/day01.rb create mode 100644 2022/examples/day01.txt diff --git a/2022/day01.rb b/2022/day01.rb new file mode 100644 index 0000000..187bae9 --- /dev/null +++ b/2022/day01.rb @@ -0,0 +1,7 @@ +elves = STDIN.read.split("\n\n").map { |str| str.split("\n").map(&:to_i) } + +def solve(elves, size) + elves.map(&:sum).max(size).sum +end +puts solve(elves, 1) +puts solve(elves, 3) diff --git a/2022/examples/day01.txt b/2022/examples/day01.txt new file mode 100644 index 0000000..2094f91 --- /dev/null +++ b/2022/examples/day01.txt @@ -0,0 +1,14 @@ +1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000