This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-15
Channels
- # adventofcode (13)
- # aleph (5)
- # announcements (8)
- # beginners (87)
- # calva (9)
- # cider (102)
- # cljs-dev (71)
- # cljsrn (2)
- # clojure (198)
- # clojure-dev (28)
- # clojure-europe (3)
- # clojure-italy (27)
- # clojure-nl (3)
- # clojure-spec (1)
- # clojure-uk (43)
- # clojurescript (121)
- # component (11)
- # cursive (20)
- # data-science (13)
- # datascript (2)
- # datomic (102)
- # dirac (4)
- # duct (5)
- # emacs (14)
- # figwheel-main (7)
- # fulcro (37)
- # hoplon (11)
- # jackdaw (3)
- # jobs (2)
- # leiningen (16)
- # nrepl (2)
- # off-topic (51)
- # pathom (34)
- # pedestal (12)
- # perun (10)
- # portkey (1)
- # re-frame (6)
- # reitit (1)
- # shadow-cljs (21)
- # spacemacs (8)
- # tools-deps (2)
- # vim (2)
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
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.
I remember I started with Levenshtein distance too but that was really slow
I implemented what the question asked for directly
Compare two strings character by character 😉
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.
And I sometimes spent like more than a work day on an exercise
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.
Good to push yourself but if you get frustrated look for a hint 🙂
Or walk away for a bit
i'll mull over your approach about comparing two strings character by character. thanks
🙂 good luck!