|
39 | 39 | # So, in this example, the bathroom code is 1985. |
40 | 40 | # |
41 | 41 | # Your puzzle input is the instructions from the document you found at the front desk. What is the bathroom code? |
| 42 | +# |
| 43 | +# --- Part Two --- |
| 44 | +# |
| 45 | +# You finally arrive at the bathroom (it's a several minute walk from the lobby so visitors can |
| 46 | +# behold the many fancy conference rooms and water coolers on this floor) and go to punch in the |
| 47 | +# code. Much to your bladder's dismay, the keypad is not at all like you imagined it. Instead, you |
| 48 | +# are confronted with the result of hundreds of man-hours of bathroom-keypad-design meetings: |
| 49 | +# |
| 50 | +# 1 |
| 51 | +# 2 3 4 |
| 52 | +# 5 6 7 8 9 |
| 53 | +# A B C |
| 54 | +# D |
| 55 | +# You still start at "5" and stop when you're at an edge, but given the same instructions as |
| 56 | +# above, the outcome is very different: |
| 57 | +# |
| 58 | +# You start at "5" and don't move at all (up and left are both edges), ending at 5. |
| 59 | +# Continuing from "5", you move right twice and down three times (through "6", "7", "B", "D", |
| 60 | +# "D"), ending at D. |
| 61 | +# Then, from "D", you move five more times (through "D", "B", "C", "C", "B"), ending at B. |
| 62 | +# Finally, after five more moves, you end at 3. |
| 63 | +# So, given the actual keypad layout, the code would be 5DB3. |
| 64 | +# |
| 65 | +# Using the same instructions in your puzzle input, what is the correct bathroom code? |
| 66 | +# |
| 67 | +# Although it hasn't changed, you can still get your puzzle input. |
42 | 68 |
|
43 | 69 | require_relative 'input' |
44 | 70 |
|
|
47 | 73 |
|
48 | 74 | # puts "solving day #{day} from input\n#{input}" |
49 | 75 |
|
50 | | -move = { |
| 76 | +move_square = { |
51 | 77 | '1' => { 'U' => '1', 'D' => '4', 'L' => '1', 'R' => '2' }, |
52 | 78 | '2' => { 'U' => '2', 'D' => '5', 'L' => '1', 'R' => '3' }, |
53 | 79 | '3' => { 'U' => '3', 'D' => '6', 'L' => '2', 'R' => '3' }, |
|
58 | 84 | '8' => { 'U' => '5', 'D' => '8', 'L' => '7', 'R' => '9' }, |
59 | 85 | '9' => { 'U' => '6', 'D' => '9', 'L' => '8', 'R' => '9' }, |
60 | 86 | } |
| 87 | +move_diamond = { |
| 88 | + '1' => { 'U' => '1', 'D' => '3', 'L' => '1', 'R' => '1' }, |
| 89 | + '2' => { 'U' => '2', 'D' => '6', 'L' => '2', 'R' => '3' }, |
| 90 | + '3' => { 'U' => '1', 'D' => '7', 'L' => '2', 'R' => '4' }, |
| 91 | + '4' => { 'U' => '4', 'D' => '8', 'L' => '3', 'R' => '4' }, |
| 92 | + '5' => { 'U' => '5', 'D' => '5', 'L' => '5', 'R' => '6' }, |
| 93 | + '6' => { 'U' => '2', 'D' => 'A', 'L' => '5', 'R' => '7' }, |
| 94 | + '7' => { 'U' => '3', 'D' => 'B', 'L' => '6', 'R' => '8' }, |
| 95 | + '8' => { 'U' => '4', 'D' => 'C', 'L' => '7', 'R' => '9' }, |
| 96 | + '9' => { 'U' => '9', 'D' => '9', 'L' => '8', 'R' => '9' }, |
| 97 | + 'A' => { 'U' => '6', 'D' => 'A', 'L' => 'A', 'R' => 'B' }, |
| 98 | + 'B' => { 'U' => '7', 'D' => 'D', 'L' => 'A', 'R' => 'C' }, |
| 99 | + 'C' => { 'U' => '8', 'D' => 'C', 'L' => 'B', 'R' => 'C' }, |
| 100 | + 'D' => { 'U' => 'B', 'D' => 'D', 'L' => 'D', 'R' => 'D' }, |
| 101 | +} |
61 | 102 |
|
62 | | -button = '5' |
| 103 | +square = '' |
| 104 | +button_square = '5' |
| 105 | +diamond = '' |
| 106 | +button_diamond = '5' |
63 | 107 | input.each_line do |line| |
64 | 108 | line.chomp.each_char do |dir| |
65 | | - button = move[button][dir] |
| 109 | + button_square = move_square[button_square][dir] |
| 110 | + button_diamond = move_diamond[button_diamond][dir] |
66 | 111 | end |
67 | | - print button |
| 112 | + square << button_square |
| 113 | + diamond << button_diamond |
68 | 114 | end |
69 | | -puts |
| 115 | + |
| 116 | +puts "Square: #{square}" |
| 117 | +puts "Diamond: #{diamond}" |
0 commit comments