Skip to content

Instantly share code, notes, and snippets.

@kencoba
Created December 28, 2012 06:24
Show Gist options
  • Save kencoba/4395058 to your computer and use it in GitHub Desktop.
Save kencoba/4395058 to your computer and use it in GitHub Desktop.
print traces of graph.
(use 'clojure.set)
(def middle-cols 5)
(def max-col (inc middle-cols))
(def max-row 2)
(defn row [point] (first point))
(defn col [point] (second point))
(defn valid-row? [point]
(if (and (>= (row point) 0)
(<= (row point) max-row))
true
false))
(defn valid-col? [point]
(if (and (>= (col point) 1)
(<= (col point) max-col))
true
false))
(defn new-points-sub [point]
(let [r (row point)
c (col point)]
(set (list [(dec r) c] [(inc r) c] [r (dec c)] [r (inc c)]))))
(defn new-points
[point]
(filter #(if (and (valid-row? %) (valid-col? %)) true false)
(new-points-sub point)))
(defn new-points-with-trace [point trace]
(difference (set (new-points point)) (set trace)))
(defn start? [point] (if (<= (col point) 0) true false))
(defn goal? [point] (if (>= (col point) max-col) true false))
(defn ramens-sub [trace]
(doseq [t (map #(cons % trace) (new-points-with-trace (first trace) (rest trace)))]
(if (goal? (first t)) (println t)
(ramens-sub t))))
; print all valid traces
(do (ramens-sub '([0 1]))
(ramens-sub '([1 1]))
(ramens-sub '([2 1])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment