Some helpful code for people trying the problem out and need some debugging help. (defn visualize "Takes a set of `points`. Ex: #{[0 0] [0 1] [2 1]} Can be used to visualize the path of an segement of the rope or even the position of the rope itself! HINT (map first trajectories)" [points] (let [right-bound (transduce (map first) max 0 points) left-bound (transduce (map first) min 0 points) top-bound (transduce (map last) max 0 points) bottom-bound (transduce (map last) min 0 points)] (doseq [y (reverse (range bottom-bound (inc top-bound)))] (->> (range left-bound (inc right-bound)) (map (fn [x] (cond (= [0 0] [x y]) "s" (contains? points [x y]) "#" :else "."))) (apply str) println))))
FYI the plus/minus functions aren't needed, you can just use `mapv` eg (mapv + [1 2] [1 2]) => [2 4]
Some helpful code for people trying the problem out and need some debugging help.
(defn visualize
"Takes a set of `points`. Ex: #{[0 0] [0 1] [2 1]}
Can be used to visualize the path of an segement of the rope or even the position of the rope itself! HINT (map first trajectories)"
[points]
(let [right-bound (transduce (map first) max 0 points)
left-bound (transduce (map first) min 0 points)
top-bound (transduce (map last) max 0 points)
bottom-bound (transduce (map last) min 0 points)]
(doseq [y (reverse (range bottom-bound (inc top-bound)))]
(->> (range left-bound (inc right-bound))
(map (fn [x] (cond
(= [0 0] [x y]) "s"
(contains? points [x y]) "#"
:else ".")))
(apply str)
println))))