This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-10
Channels
- # adventofcode (174)
- # announcements (5)
- # aws (9)
- # babashka (17)
- # beginners (259)
- # boot-dev (1)
- # calva (6)
- # cider (19)
- # circleci (7)
- # clj-kondo (9)
- # cljfx (51)
- # cljs-dev (4)
- # clojure (83)
- # clojure-australia (2)
- # clojure-dev (9)
- # clojure-europe (78)
- # clojure-nl (3)
- # clojure-spec (4)
- # clojure-switzerland (1)
- # clojure-uk (18)
- # clojurescript (22)
- # conjure (17)
- # cursive (17)
- # data-science (1)
- # datomic (15)
- # defnpodcast (1)
- # events (2)
- # fulcro (39)
- # graalvm (16)
- # graphql (1)
- # kaocha (5)
- # lambdaisland (11)
- # malli (6)
- # meander (1)
- # off-topic (26)
- # pathom (10)
- # re-frame (10)
- # reitit (6)
- # rewrite-clj (7)
- # sci (3)
- # shadow-cljs (28)
- # sql (12)
- # test-check (10)
- # tools-deps (31)
going live in a few moments https://youtu.be/VnXw58zGqDs
Been having some setup issues... new stream link https://youtu.be/1yLBj6kYTKc
I went for combinatorics and found this solution which runs in 1ms with my input data:
(defn ! [n]
(reduce *' (range 1 (inc n))))
(defn combinations [n r]
(if (= 1 n)
0
(let [n! (! n)
r! (! r)
r-n! (! (- n r))]
(/ n! (* r! r-n!)))))
(->> parsed-input
(sort)
(cons 0)
(#(concat % [(+ 3 (last %))]))
(partition 2 1)
(map #(- (second %) (first %)))
(partition-by identity)
(keep #(seq (filter #{1} %)))
(map count)
(map #(inc (combinations % 2)))
(apply *))
(Maybe I should memoize the factorial function? But doesn’t much matter on my input maybe, where the longest 1-distance streaks are 7.)got a solution now as well, much more complex then it needs to be, but also runs in ~2ms
reusing my earlier combos
function, but only applied to sections of the input. Basically I look for elements that can't be removed, use those to split the input in two parts, do that recursively until I can't split it further, then count the combinations for the parts and multiply them.
(defn divide [input]
(let [split-points (remove #(can-be-removed? input %) (range 1 (dec (count input))))]
(if (seq split-points)
(let [split-idx (long (nth split-points (quot (count split-points) 2)))
left (take (inc split-idx) input)
right (drop split-idx input)]
[left right])
(combos (vec input) 1))))
(defn conquer [input]
(let [parts (divide input)]
(if (number? parts)
parts
(apply * (map conquer parts)))))
(time
(let [input (add-boundaries real-input)]
(conquer input)))
;; => 396857386627072