Skip to content

Instantly share code, notes, and snippets.

@daveray
Created November 4, 2011 03:33
Show Gist options
  • Save daveray/1338599 to your computer and use it in GitHub Desktop.
Save daveray/1338599 to your computer and use it in GitHub Desktop.
4clojure problem 117 issue
; http://www.4clojure.com/problem/117
(fn [g]
(let [w (count (first g))
h (count g)
xys (for [x (range w) y (range h)] [x y])
at (fn [[x y]] (if (and (< -1 x w) (< -1 y h)) (get-in g [y x]) \#))
c? (fn [[n0 n1]] (and (not= \# (at n0)) (not= \# (at n1))))
ns (fn [x y]
(for [[dx dy] [[-1 0] [1 0] [0 1] [0 -1]]]
[(+ x dx) (+ y dy)]))
es (->> (for [[x y] xys n (ns x y)] [[x y] n]) (filter c?))
M (some #(if (= \M (at %)) %) xys)
C (some #(if (= \C (at %)) %) xys)]
(let [all xys
m (merge
(into {} (for [i all j all] [[i j] (if (= i j) 0 1)]))
(into {} (for [p es] [p 0])))
m (->> (for [k all i all j all] [i j k])
(reduce
(fn [m [i j k]]
(update-in m [[i j]] min (+ (m [i k]) (m [k j]))))
m))]
(zero? (m [M C])))))
; java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment