File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ def initialize(input=nil)
15
15
def part1
16
16
crane = CrateMover9000 . new ( parse_stacks , @moves )
17
17
crane . follow_process
18
+ puts crane . ugly_christmas_sweater
18
19
crane . top_crates
19
20
end
20
21
@@ -36,6 +37,31 @@ def top_crates
36
37
. map ( &:last )
37
38
. join ( "" )
38
39
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
39
65
end
40
66
41
67
class CrateMover9000 < CrateMover
@@ -54,6 +80,7 @@ def follow_process
54
80
def part2
55
81
crane = CrateMover9001 . new ( parse_stacks , @moves )
56
82
crane . follow_process
83
+ puts crane . ugly_christmas_sweater
57
84
crane . top_crates
58
85
end
59
86
You can’t perform that action at this time.
0 commit comments