Skip to content

Commit 9c90039

Browse files
author
Robb Kidd
committed
the return of the ugly christmas sweater
1 parent e374a61 commit 9c90039

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

2022/ruby/day05.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def initialize(input=nil)
1515
def part1
1616
crane = CrateMover9000.new(parse_stacks, @moves)
1717
crane.follow_process
18+
puts crane.ugly_christmas_sweater
1819
crane.top_crates
1920
end
2021

@@ -36,6 +37,31 @@ def top_crates
3637
.map(&:last)
3738
.join("")
3839
end
40+
41+
def ugly_christmas_sweater
42+
highest_height = stacks.values.max_by{|v| v.length}.length
43+
output = []
44+
stacks.each {|idx, stack|
45+
crates = []
46+
crates << " #{idx} "
47+
stack.each_with_index { |c, i|
48+
if i == stack.length-1
49+
crates << "\e[32m[\e[0m\e[41m\e[1m#{c}\e[0m\e[32m]\e[0m"
50+
else
51+
crates << "\e[32m[\e[0m\e[41m\e[0m#{c}\e[0m\e[32m]\e[0m"
52+
end
53+
}
54+
crates += (highest_height - stack.length).times.map{|_| " "}
55+
output << crates
56+
output << Array.new(highest_height+1, " ")
57+
}
58+
output
59+
.transpose
60+
.reverse
61+
.map{|level| level.join("")}
62+
.unshift(["\n"])
63+
.join("\n")
64+
end
3965
end
4066

4167
class CrateMover9000 < CrateMover
@@ -54,6 +80,7 @@ def follow_process
5480
def part2
5581
crane = CrateMover9001.new(parse_stacks, @moves)
5682
crane.follow_process
83+
puts crane.ugly_christmas_sweater
5784
crane.top_crates
5885
end
5986

0 commit comments

Comments
 (0)