Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns blob)
- (defn abnormal? [color]
- (= color :abnormal))
- (defn color [grid x y]
- (get-in grid [x y]))
- (defn recolor [grid x y color]
- (assoc-in grid [x y] color))
- (defn column-count [grid]
- (count (first grid)))
- (defn row-count [grid]
- (count grid))
- (defn neighbors [grid x y]
- [[x (dec y)] [x (inc y)]
- [(dec x) y] [(inc x) y]])
- (defn collect-cells [grid x y visited]
- (if-not (abnormal? (color grid x y))
- visited
- (if (contains? visited [x y])
- visited
- (reduce (fn [vis [i j]]
- (collect-cells grid i j vis))
- (conj visited [x y])
- (neighbors grid x y)))))
- (defn count-cells [grid x y]
- (count (collect-cells grid x y #{})))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement