diff --git a/src/advent/util.cr b/src/advent/util.cr index 00acd6b..e99fd0a 100644 --- a/src/advent/util.cr +++ b/src/advent/util.cr @@ -54,6 +54,9 @@ struct Tuple(*T) { {% for t, i in T %} self[{{i}}].signum, {% end %} } {% end %} end + + def abs + end end struct Number @@ -62,3 +65,17 @@ struct Number self // self.abs end end + +class Hash(K, V) + def draw(maps) + min_x, max_x = keys.minmax_of &.[0] + min_y, max_y = keys.minmax_of &.[1] + (max_y-min_y+1).times do |y| + (max_x-min_x+1).times do |x| + next unless has_key?({x,y}) + print maps[self[{x,y}]] + end + puts + end + end +end