@@ -47,7 +47,10 @@ def initialize(input)
47
47
@input = input
48
48
@start = nil
49
49
@grid = Grid . new ( input )
50
- @grid . parse { |coords , value | @start = coords if value == "S" }
50
+ @grid . parse { |coords , value |
51
+ @start = coords if value == "S"
52
+ @grid . set ( coords , value . tr ( '|\-LJ7F.S' , "│─└┘┐┌░╳" ) )
53
+ }
51
54
end
52
55
53
56
def loop_path
@@ -109,35 +112,36 @@ def towards(from_coords, direction)
109
112
110
113
# [step travel direction, pipe type] => next step travel direction
111
114
PIPE_FLOWS = {
115
+ # "│─└┘┐┌░╳"
112
116
# | is a vertical pipe connecting north and south.
113
- [ :north , "| " ] => :north ,
114
- [ :south , "| " ] => :south ,
117
+ [ :north , "│ " ] => :north ,
118
+ [ :south , "│ " ] => :south ,
115
119
# - is a horizontal pipe connecting east and west.
116
- [ :east , "- " ] => :east ,
117
- [ :west , "- " ] => :west ,
120
+ [ :east , "─ " ] => :east ,
121
+ [ :west , "─ " ] => :west ,
118
122
# L is a 90-degree bend connecting north and east.
119
- [ :south , "L " ] => :east ,
120
- [ :west , "L " ] => :north ,
123
+ [ :south , "└ " ] => :east ,
124
+ [ :west , "└ " ] => :north ,
121
125
# J is a 90-degree bend connecting north and west.
122
- [ :south , "J " ] => :west ,
123
- [ :east , "J " ] => :north ,
126
+ [ :south , "┘ " ] => :west ,
127
+ [ :east , "┘ " ] => :north ,
124
128
# 7 is a 90-degree bend connecting south and west.
125
- [ :east , "7 " ] => :south ,
126
- [ :north , "7 " ] => :west ,
129
+ [ :east , "┐ " ] => :south ,
130
+ [ :north , "┐ " ] => :west ,
127
131
# F is a 90-degree bend connecting south and east.
128
- [ :west , "F " ] => :south ,
129
- [ :north , "F " ] => :east ,
132
+ [ :west , "┌ " ] => :south ,
133
+ [ :north , "┌ " ] => :east ,
130
134
# . is ground; there is no pipe in this tile.
131
- ". " => :cannot_enter_ground ,
135
+ "░ " => :cannot_enter_ground ,
132
136
# S is the starting position of the animal;
133
137
# there is a pipe on this tile, but your sketch doesn't
134
138
# show what shape the pipe has.
135
139
# Let start be entered from any direction and then
136
140
# there are no further steps.
137
- [ :north , "S " ] => :stop ,
138
- [ :south , "S " ] => :stop ,
139
- [ :east , "S " ] => :stop ,
140
- [ :west , "S " ] => :stop ,
141
+ [ :north , "╳ " ] => :stop ,
142
+ [ :south , "╳ " ] => :stop ,
143
+ [ :east , "╳ " ] => :stop ,
144
+ [ :west , "╳ " ] => :stop ,
141
145
}
142
146
143
147
def to_ugly_sweater
0 commit comments