adventofcode

Happy Advent 2020! Please put answers in the pinned threads or create one if it does not exist yet. | https://github.com/adventofcode-clojurians/adventofcode-clojurians | Join the private leaderboard with code 217019-4a55b8eb
Chase 2019-02-11T18:18:33.001200Z

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)
      freq
      (let [seen (conj seen freq)
            freq (reduce + (cycle data))]
        (recur seen freq)))))

Chase 2019-02-11T18:20:07.003Z

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.

dpsutton 2019-02-11T18:30:06.003800Z

(defn first-duplicate
  ([l] (first-duplicate l #{}))
  ([l seen]
   (let [[head & tail] l]
     (if (contains? seen head)
       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

dpsutton 2019-02-11T18:32:40.004Z

@chase-lambert ^

Chase 2019-02-11T18:46:38.005Z

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.

2019-02-11T22:59:14.007100Z

@chase-lambert I did a version of your approach here: https://github.com/potetm/advent-of-code/blob/master/src/advent_2018/day_1.clj#L32

2019-02-11T22:59:23.007400Z

You can watch the vid here: https://potetm.com/video/aoc-2018-d01.html