Clojure Day 9 Advent of Code 2022 Rope Bridge

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ม.ค. 2025

ความคิดเห็น • 3

  • @_lkn_
    @_lkn_ 2 ปีที่แล้ว +2

    FYI the plus/minus functions aren't needed, you can just use `mapv` eg (mapv + [1 2] [1 2]) => [2 4]

  • @puranto23
    @puranto23 2 ปีที่แล้ว

    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))))