Add utility to draw the state of a hash.
This commit is contained in:
parent
6a0edb873b
commit
a5e6c4c145
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user