Skip to content

Commit 55791ae

Browse files
committedDec 2, 2022
day 1
0 parents  commit 55791ae

File tree

3 files changed

+2280
-0
lines changed

3 files changed

+2280
-0
lines changed
 

‎01/a.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
max = 0
2+
sum = 0
3+
4+
File
5+
.readlines("01/input.txt")
6+
.each do |line|
7+
if line.strip == ""
8+
max = [max, sum].max
9+
sum = 0
10+
else
11+
sum += line.to_i
12+
end
13+
end
14+
15+
p max

‎01/b.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
top = [0, 0, 0]
2+
sum = 0
3+
4+
File
5+
.readlines("01/input.txt")
6+
.each do |line|
7+
if line.strip == ""
8+
top << sum
9+
top = top.sort[1..3]
10+
sum = 0
11+
else
12+
sum += line.to_i
13+
end
14+
end
15+
16+
p top.sum

‎01/input.txt

+2,249
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.