Fork me on GitHub
#adventofcode
<
2020-12-11
>
st3fan02:12:24

Can someone help me with the following (may contain a spoiler)

st3fan02:12:32

(frequencies (map #(* -1 (apply - %)) (partition 2 1 [0 1 4 5 6 7 10 11 12 15 16 19 22])))
;; => {1 7, 3 5}

(defn jolt-distribution [jolts]
  (frequencies (map #(* -1 (apply - %)) (partition 2 1 jolts))))

(jolt-distribution [0 1 4 5 6 7 10 11 12 15 15 19 22])
;; => {1 6, 3 4, 0 1, 4 1} ???

st3fan02:12:58

I am pretty tired, so maybe I just don’t see it - but why do I get a different result .. the function is exactly what the expression above it does

st3fan02:12:57

Maybe I should restart the REPL

st3fan02:12:42

I don’t get it 😕

Stuart02:12:56

look at line 4

Stuart02:12:59

12 15 15 19

st3fan02:12:24

Hope I can solve part 1 before I pass out 🙂

Stuart02:12:36

today was tough

st3fan02:12:13

Uhoh now I am afdraid of what to get for part 2 🙂

st3fan02:12:52

I need to get better at thinking in recursion

🐢 2
Stuart02:12:58

are you onto part 2?

Average-user06:12:04

How long take your programs for day 11?

plexus07:12:19

Part 2 of day 11 on the real input runs in just under a second for me. Probably could be a lot faster but good enough for me 🙂

Vincent Cantin06:12:15

If you find it difficult today, just remember: “C’est la vie !” (that’s life)

🎮 2
Vincent Cantin12:12:50

😱 I replaced get-in by 2 consecutive get and I cut my runtime by half !!!

😮 1
Vincent Cantin16:12:20

From slower to faster:

(swap! acc update row assoc col c)

(swap! acc assoc-in [row col] c)

(swap! acc (fn [grid]
             (update grid row (fn [row]
                                (assoc row col c))))))))

pez21:12:31

My solution for Day 11, step 2 takes 6 seconds to run… But at least I have the stars.

😁 4
Stuart00:12:45

just finished part 1 and it took 24 seconds. This does not bode well.

curlyfry21:12:11

I've been getting some good mileage out of iterate in some of the problems. Haven't gotten the opportunity to use it that much before, it's so nice when the problen fits! I started writing the body for a loop/recur and then realised that I could just feed it to iterate and it turned out much nicer

metal 3
andrea.crotti21:12:46

Ah nice yeah I forgot about iterate

andrea.crotti21:12:12

I feel like I should use a proper matrix library instead of the usual vector of vectors

andrea.crotti21:12:29

What's the best library for this kind of stuff atm?

curlyfry22:12:13

@andrea.crotti The ones I've seen (like core.matrix) are a bit more math focused I'd say. One of the main matrix processing tools in core is https://clojuredocs.org/clojure.walk/prewalk

curlyfry22:12:37

I don't really think either is very useful for today's problem though since you need to keep track of indices and stuff

curlyfry22:12:02

If you find a way to use one of the walk functions in a nice way in the problem I'd love to hear it! That was the ugliest part of my solution

1
markw22:12:52

@vincent.cantin may the lisp gods forgive this abomination inspired by your comment:

(defmacro update-in-faster [m [k & ks] f & args]
  (if ks
    `((fn [m#]
        (assoc m# ~k (update-in-faster (m# ~k) ~ks ~f [email protected])))
      ~m)
    `(update ~m ~k ~f [email protected])))

parrot 1
👍 1