Fork me on GitHub

I still can't get past part 2 of Day 1. Lol! Yeesh. I was hoping I would be farther along in my skills by this point. Ok, hopefully this shows what I'm trying to get at:

(defn part2 [data]
  (loop [seen #{}
         freq 0]
    (if (contains? seen freq)
      (let [seen (conj seen freq)
            freq (reduce + (cycle data))]
        (recur seen freq)))))


I figure I have to keep a running tally of frequencies and then compare the current frequency to that. That made me think I probably want a set right because it can't have any repeats. Now that I write it out though, not sure that will be necessary. But something isn't working in my else clause (obviously the meat of the function). Any tips on where I'm going wrong here.


(defn first-duplicate
  ([l] (first-duplicate l #{}))
  ([l seen]
   (let [[head & tail] l]
     (if (contains? seen head)
       (recur tail (conj seen head))))))
make a function that does what you need. here's a simple loop until it gets something already seen


thank you. I'll try and process this. Reflecting on the process, I'm realizing I just have a vague notion of some of these concepts and then just blindly flailing about it in the repl.