Skip to content

Commit a5b5363

Browse files
author
Robb Kidd
committed
lift Bill Mill's idea for proper ANSI art
1 parent b0280f6 commit a5b5363

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

2023/ruby/day10.rb

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ def initialize(input)
4747
@input = input
4848
@start = nil
4949
@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+
}
5154
end
5255

5356
def loop_path
@@ -109,35 +112,36 @@ def towards(from_coords, direction)
109112

110113
# [step travel direction, pipe type] => next step travel direction
111114
PIPE_FLOWS = {
115+
# "│─└┘┐┌░╳"
112116
# | is a vertical pipe connecting north and south.
113-
[:north, "|"] => :north,
114-
[:south, "|"] => :south,
117+
[:north, ""] => :north,
118+
[:south, ""] => :south,
115119
# - is a horizontal pipe connecting east and west.
116-
[:east, "-"] => :east,
117-
[:west, "-"] => :west,
120+
[:east, ""] => :east,
121+
[:west, ""] => :west,
118122
# L is a 90-degree bend connecting north and east.
119-
[:south, "L"] => :east,
120-
[:west, "L"] => :north,
123+
[:south, ""] => :east,
124+
[:west, ""] => :north,
121125
# J is a 90-degree bend connecting north and west.
122-
[:south, "J"] => :west,
123-
[:east, "J"] => :north,
126+
[:south, ""] => :west,
127+
[:east, ""] => :north,
124128
# 7 is a 90-degree bend connecting south and west.
125-
[:east, "7"] => :south,
126-
[:north, "7"] => :west,
129+
[:east, ""] => :south,
130+
[:north, ""] => :west,
127131
# F is a 90-degree bend connecting south and east.
128-
[:west, "F"] => :south,
129-
[:north, "F"] => :east,
132+
[:west, ""] => :south,
133+
[:north, ""] => :east,
130134
# . is ground; there is no pipe in this tile.
131-
"." => :cannot_enter_ground,
135+
"" => :cannot_enter_ground,
132136
# S is the starting position of the animal;
133137
# there is a pipe on this tile, but your sketch doesn't
134138
# show what shape the pipe has.
135139
# Let start be entered from any direction and then
136140
# 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,
141145
}
142146

143147
def to_ugly_sweater

0 commit comments

Comments
 (0)