File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ require_relative 'day'
2
+
3
+ class Day08 < Day # >
4
+
5
+ # @example
6
+ # day.part1 #=> 2
7
+ def part1
8
+ parse ( input )
9
+ steps = 0
10
+ node = "AAA"
11
+ @instructions
12
+ . cycle do |instruction |
13
+ break if node == "ZZZ"
14
+ steps += 1
15
+ node = @network [ node ] [ instruction ]
16
+ end
17
+ steps
18
+ end
19
+
20
+ # @example
21
+ # day.part2 #=> 'how are you'
22
+ def part2
23
+ end
24
+
25
+ # @example
26
+ # inst, net = day.parse(EXAMPLE_INPUT)
27
+ # inst #=> ["R", "L"]
28
+ def parse ( input )
29
+ stanzas = input . split ( "\n \n " )
30
+
31
+ @instructions = stanzas [ 0 ] . chars
32
+
33
+ @network = { }
34
+ stanzas [ 1 ]
35
+ . each_line
36
+ . map { |line | line . scan ( /\w +/ ) }
37
+ . each { |node , left , right |
38
+ @network [ node ] = { "L" => left , "R" => right }
39
+ }
40
+
41
+ [ @instructions , @network ]
42
+ end
43
+
44
+ EXAMPLE_INPUT = <<~INPUT
45
+ RL
46
+
47
+ AAA = (BBB, CCC)
48
+ BBB = (DDD, EEE)
49
+ CCC = (ZZZ, GGG)
50
+ DDD = (DDD, DDD)
51
+ EEE = (EEE, EEE)
52
+ GGG = (GGG, GGG)
53
+ ZZZ = (ZZZ, ZZZ)
54
+ INPUT
55
+
56
+ SIX_STEPS_INPUT = <<~INPUT
57
+ LLR
58
+
59
+ AAA = (BBB, BBB)
60
+ BBB = (AAA, ZZZ)
61
+ ZZZ = (ZZZ, ZZZ)
62
+ INPUT
63
+ end
You can’t perform that action at this time.
0 commit comments