Fork me on GitHub
#adventofcode
<
2021-01-14
>
Jeff Evans22:01:12

why is this not being lazy? (this is for day 15, part 1)

(defn get-spoken-num [accumulator number last-val]
  (lazy-seq
    (let [last-seen (get accumulator last-val)
          last-round-num (dec number)
          seen-before? (and (some? last-seen) (< last-seen last-round-num))
          this-round (if seen-before? (- last-round-num last-seen) 0)]
      (cons 
        this-round 
        (get-spoken-num
          (assoc accumulator this-round number) 
          (inc number) 
          this-round)))))

Jeff Evans22:01:08

hmm, actually maybe it is ( take 10 (…) works fine). I guess evaluating the full lazy sequence in the REPL actually traverses it