Skip to content

Commit ead3e7b

Browse files
author
Robb Kidd
committed
day 9, part 1
A naive map-reduce implementation pretty much as described by the day's prose. But it works.
1 parent e055dc8 commit ead3e7b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

2023/ruby/day09.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require_relative 'day'
2+
3+
class Day09 < Day # >
4+
5+
# @example
6+
# day.part1 #=> 114
7+
def part1
8+
input
9+
.each_line
10+
.map { |line| line.split(" ").map(&:to_i) }
11+
.map { |history|
12+
sequences = [history]
13+
while !sequences.last.all?(0) do
14+
sequences << sequences.last.each_cons(2).map { |a,b| b - a }
15+
end
16+
sequences
17+
.reverse
18+
.map(&:last)
19+
.reduce(&:+)
20+
}
21+
.reduce(&:+)
22+
end
23+
24+
# @example
25+
# day.part2 #=> 'how are you'
26+
def part2
27+
end
28+
29+
EXAMPLE_INPUT = <<~INPUT
30+
0 3 6 9 12 15
31+
1 3 6 10 15 21
32+
10 13 16 21 30 45
33+
INPUT
34+
end

0 commit comments

Comments
 (0)