Fork me on GitHub
#adventofcode
<
2019-02-15
>
Chase16:02:19

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

Chase16:02:25

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.

erwinrooijakkers16:02:42

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

erwinrooijakkers16:02:37

I implemented what the question asked for directly

erwinrooijakkers16:02:55

Compare two strings character by character 😉

Chase16:02:13

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.

erwinrooijakkers16:02:55

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

Chase16:02:56

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.

erwinrooijakkers16:02:10

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

erwinrooijakkers16:02:23

Or walk away for a bit

Chase16:02:51

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

Chase16:02:37

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

erwinrooijakkers16:02:43

🙂 good luck!