Add solution for day 3.
This commit is contained in:
22
common.cr
Normal file
22
common.cr
Normal file
@@ -0,0 +1,22 @@
|
||||
module Enumerable(T)
|
||||
def count_each(others)
|
||||
count_map = {} of T => Int32
|
||||
each do |other|
|
||||
count_map[other] = (count_map[other]? || 0) + 1
|
||||
end
|
||||
return count_map
|
||||
end
|
||||
end
|
||||
|
||||
class Rectangle
|
||||
def initialize(@x : Int32, @y : Int32, @width : Int32, @height : Int32)
|
||||
end
|
||||
|
||||
def each_coord(&block)
|
||||
(@x...(@x + @width)).each do |x|
|
||||
(@y...(@y + @height)).each do |y|
|
||||
yield x, y
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user