blob: f7a7c24973cdb54ccbbd03948eaec5ae67a19daa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
TEST_S = <<-TEST
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
TEST
def elves_food(input_str)
return input_str.split(/^$/).map do
|elf_rations|
elf_rations.strip.split("\n").map(&:to_i)
end
end
def calories_by_elf(input_str)
elves_food(input_str).map(&:sum)
end
def max_calories(input_str)
calories_by_elf(input_str).max
end
def top_3_calories(input_str)
calories_by_elf(input_str).sort.reverse.take(3).sum
end
def day1
File.open('day1.txt') do |f|
input_str = f.read
puts "part1: #{max_calories(input_str)}"
puts "part2: #{top_3_calories(input_str)}"
end
end
day1()
#puts elves_food(TEST_S)
|