advent_of_code/2022_1.rb
Code:
# Advent of Code 2022, Day 1: Calorie Counting
# https://adventofcode.com/2022/day/1
require_relative './helpers.rb'
def part_one(elves)
elves.max
end
def part_two(elves)
elves.sort.last(3).sum
end
def solve(dataset)
elves = [0]
dataset.each { |k| k == '' ? elves.push(0) : elves[-1] += k.to_i }
return part_one(elves), part_two(elves)
end
puts solve(get_dataset(year: 2022, day: 1, type: 'example'))
puts solve(get_dataset(year: 2022, day: 1, type: 'input'))
Output:
24000
45000
71506
209603