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-15T16:44:19.057100Z

so I solved part 1 of day 2 but it looks kind of hacky to me. Any suggestions?

(def data
  (->> (slurp "resources/y2018.d02.txt")
       (str/split-lines)))

(defn double-letter? [s]
  (some #(= 2 %) (vals (frequencies s))))

(defn num-of-doubles [coll]
  (get (frequencies (map double-letter? coll)) true))

(defn triple-letter? [s]
  (some #(= 3 %) (vals (frequencies s))))

(defn num-of-triples [coll]
  (get (frequencies (map triple-letter? coll)) true))

(defn part1 [coll]
  (* (num-of-doubles coll) (num-of-triples coll)))

(part1 data)
;; => 6200

Chase 2019-02-15T16:47:25.060300Z

and I'm struggling with part 2 again. I remember doing this simple spellchecker tutorial: https://www.bernhardwenzel.com/articles/clojure-spellchecker/ so was thinking this "levenshtein distance" could get me there. It's not working though as even the first string is saying it has a match with a 0 distance. But that isn't right. But now I can't get my brain off this strategy! If it continues to elude me I'll check out @potetm's video and other people's solutions. I'm thinking part 2's are going to be a bit outside my current ability but not sure when to call it and try to learn from others or keep fighting it. I don't know if spending days on one solution is fruitful at my level.

erwinrooijakkers 2019-02-15T16:54:42.060900Z

I remember I started with Levenshtein distance too but that was really slow

erwinrooijakkers 2019-02-15T16:55:37.061100Z

I implemented what the question asked for directly

erwinrooijakkers 2019-02-15T16:55:55.061300Z

Compare two strings character by character 😉

Chase 2019-02-15T16:56:13.061500Z

that's actually been one of my fears. I actually technically solve a problem but don't realize it's so inefficient that I gave up on it too soon.

erwinrooijakkers 2019-02-15T16:56:55.061700Z

And I sometimes spent like more than a work day on an exercise

Chase 2019-02-15T16:56:56.061900Z

but then maybe i should keep searching for a better solution anyways right? I think I read all problems should be able to be solved in less than 15 seconds or something.

erwinrooijakkers 2019-02-15T16:57:10.062100Z

Good to push yourself but if you get frustrated look for a hint 🙂

erwinrooijakkers 2019-02-15T16:57:23.062300Z

Or walk away for a bit

Chase 2019-02-15T16:57:51.062500Z

yeah, i do take long walks. my version of "hammock" time

Chase 2019-02-15T16:59:37.062700Z

i'll mull over your approach about comparing two strings character by character. thanks

erwinrooijakkers 2019-02-15T16:59:43.062900Z

🙂 good luck!