This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-16
Channels
- # adventofcode (99)
- # announcements (2)
- # babashka (37)
- # beginners (111)
- # cider (4)
- # cljsrn (5)
- # clojure (51)
- # clojure-australia (2)
- # clojure-chicago (3)
- # clojure-europe (141)
- # clojure-nl (2)
- # clojure-provo (2)
- # clojure-spec (48)
- # clojure-sweden (2)
- # clojure-uk (26)
- # clojurescript (34)
- # conjure (1)
- # core-logic (5)
- # cursive (16)
- # datomic (2)
- # events (2)
- # fulcro (54)
- # graphql (13)
- # jobs-discuss (116)
- # kaocha (14)
- # meander (101)
- # off-topic (41)
- # pathom (6)
- # planck (3)
- # re-frame (53)
- # reagent (10)
- # reitit (1)
- # reveal (13)
- # shadow-cljs (35)
- # spacemacs (22)
(let [[rules mine other] (parse i)
valid? (->> rules vals (reduce into #{}))
valid (->> other
(remove #(seq (remove valid? %)))
(map vec))
transposed (apply map vector valid)
candidates (fn [pred]
(->> transposed
(map-indexed
(fn [idx col]
(when (every? pred col)
idx)))
(remove nil?)))
labels (loop [done {}
todo (->> rules
(map-vals candidates)
(sort-by #(-> % val count) <)
(into PersistentQueue/EMPTY))]
(if (empty? todo)
done
(let [[label cols] (peek todo)
todo (pop todo)
cols (remove done cols)]
(if (-> cols count (= 1))
(recur (assoc done (first cols) label) todo)
(recur done (conj todo [label cols]))))))]
(->> labels
(filter #(-> % val (str/starts-with? "departure")))
(map key)
(map mine)
(reduce *)))
ofc it would loop forever, if at some point every unmapped label had more than 1 candidate idx. that'd be job for core.logic
ah indeed
did not think about core.logic but this is core.logic
Namaste. I have a "philosophical" question about the first problem of day 1. I saw solutions like this around the internet:
(for [x input y input :when (= 2020 (+ x y))]
(* x y))
but what if my input
list is (1010
? Isn't going to stop on the first element?
That's probably true
Another check to make sure the numbers are not the same is enough
But apparently it wasn't necessary given the input data
I agree, but given the statement: > Specifically, they need you to find the two entries that sum to `2020` and then multiply those two numbers together.
They won't be two entries, but one
Anyway checking that are different can be enough
but if I have, let's say (1010
the elements are two
Maybe I'm a little pedantic...
hehe well I think noone cares about the perfect solution as long as it works and it's fast enough 😄