Fork me on GitHub
#adventofcode
<
2023-12-09
>
norman05:12:22

Day 9 - Solutions

erdos05:12:07

https://github.com/erdos/advent-of-code/blob/master/2023/day09.clj figured that a recursive solution is the simplest, although, it can be done with loop+recur and reduce as well.

AC05:12:32

a surprisingly straight-forward puzzle for a weekend. I was expecting something much more complicated.

2
norman05:12:01

I hadn't considered just using reverse for part 2.

wevrem05:12:18

@U2E1D7WUB I like your reduce version.

erdos05:12:53

@UTFAPNRPT I like your use of transduce!

alekszelark06:12:14

@UTFAPNRPT nice solution, it helped me simplified mine ^_^

wevrem06:12:03

I’ve learned a lot from you over the years, @U067R559Q, I’m glad you are posting solutions.

❤️ 1
wevrem07:12:59

@U067R559Q might I suggest you add a transducer arity to your take-until?

alekszelark07:12:21

Until the last year I strived to not use libraries at all. However, I guess it’d better to pick take-upto from medley now

rjray08:12:08

OK, I'm stumped. My puzzle data has to be corrupt or something. I wrote part 1, the answer I submitted was said to be too high. I've copy-pasted 4-5 different working solutions (in both Clojure and Python) and every one of them give the same answer for my input (the one my code produces). Anyone seen a similar problem?

wevrem08:12:22

Is there any chatter on reddit that puzzle data is iffy? It seems very unlikely that would go unnoticed.

rjray08:12:07

None so far. I just posted an explicit question to that effect.

rjray08:12:13

I tried two Python solutions from reddit, and Apple's pastebin, and norman's original. All 4 gave the same answer my code does.

wevrem08:12:23

Is this helpful: my input had 200 lines.

rjray08:12:12

Well, Wastl himself answered saying that I had the right answer for my input, I should try entering it again really really carefully. The third time, it worked...

👍 3
1
rjray08:12:49

And, thanks to knowing the "reverse" trick, part 2 is already done. I'm really chuffed about part 1, though.

tschady11:12:46

nothing new to offer, except my often used intervals helper:

(defn intervals
  "Returns the seq of intervals between each element of `xs`, step `n` (default 1)"
  ([xs] (intervals 1 xs))
  ([n xs] (map - (drop n xs) xs)))
https://github.com/tschady/advent-of-code/blob/main/src/aoc/2023/d09.clj

✔️ 1
alpox12:12:25

This was… much easier than expected 👀

borkdude12:12:40

@U6JS7B99S his solution https://squint-cljs.github.io/squint/?boilerplate=https%3A%2F%2Fgist.githubusercontent.com%2Fborkdude%2Fcf94b492d948f7f418aa81ba54f428ff%2Fraw%2Fa6e9992b079e20e21d753e8c75a7353c5908b225%2Faoc_ui.cljs&amp;repl=true&amp;src=OzsgSGVscGVyIGZ1bmN0aW9uczoKOzsgKGZldGNoLWlucHV0IHllYXIgZGF5KSAtIGdldCBBT0MgaW5wdXQKOzsgKGFwcGVuZCBzdHIpIC0gYXBwZW5kIHN0ciB0byBET00KOzsgKHNweSB4KSAtIGxvZyB4IHRvIGNvbnNvbGUgYW5kIHJldHVybiB4Cgo7OyBPcmlnaW5hbCBzb2x1dGlvbiBieSBFbGlhcyBCZXJuaGF1dAoKOzsgUmVtZW1iZXIgdG8gdXBkYXRlIHRoZSB5ZWFyIGFuZCBkYXkgaW4gdGhlIGZldGNoLWlucHV0IGNhbGwuCihkZWYgaW5wdXQgKGpzLWF3YWl0IChmZXRjaC1pbnB1dCAyMDIzIDkpKSkKCihkZWZuIHBhcnNlLWxpbmUgW2xpbmVdIChtYXB2IHBhcnNlLWxvbmcgKHJlLXNlcSAjIi0%2FXGQrIiBsaW5lKSkpCgooZGVmbiBwYXJzZS1pbnB1dCBbaW5wdXRdIChtYXB2IHBhcnNlLWxpbmUgKHN0ci9zcGxpdC1saW5lcyBpbnB1dCkpKQoKKGRlZm4gZGlmZmVyZW5jZXMgW251bWJlcnNdICh2ZWMgKGZvciBbW2xlZnQgcmlnaHRdIChwYXJ0aXRpb24gMiAxIG51bWJlcnMpXQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICgtIHJpZ2h0IGxlZnQpKSkpCgooY29tbWVudAogIChwYXJzZS1pbnB1dCBpbnB1dCkKICAoZGlmZmVyZW5jZXMgWzEgMiAzXSkKICApCgooZGVmbiBkaWZmLXRyZWUgW251bWJlcnNdICgtPj4gKGl0ZXJhdGUgZGlmZmVyZW5jZXMgbnVtYmVycykKICAgICAgICAgICAgICAgICAgICAgICAgICAgICh0YWtlLXdoaWxlICMobm90IChldmVyeT8gemVybz8gJSkpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgKHJldmVyc2UpKSkKCihjb21tZW50CiAgKGRpZmYtdHJlZSBbMSAyIDNdKQogICkKCihkZWZuIGdlbmVyYXRlLW5leHQgW3JlZHVjZXIgbnVtYmVyc10KICAocmVkdWNlIHJlZHVjZXIgMCAoZGlmZi10cmVlIG51bWJlcnMpKSkKCihkZWZuIHJ1biBbaW5wdXQgcmVkdWNlcl0KICAoLT4%2BIChwYXJzZS1pbnB1dCBpbnB1dCkKICAgIChtYXAgKHBhcnRpYWwgZ2VuZXJhdGUtbmV4dCByZWR1Y2VyKSkKICAgIChhcHBseSArKSkpCgooZGVmbiBwYXJ0LTEgW2lucHV0XSAocnVuIGlucHV0IChmbiBbYWNjIHJvd10gKCsgYWNjIChsYXN0IHJvdykpKSkpCihkZWZuIHBhcnQtMiBbaW5wdXRdIChydW4gaW5wdXQgKGZuIFthY2Mgcm93XSAoLSAoZmlyc3Qgcm93KSBhY2MpKSkpCgooY29tbWVudAogIChwYXJ0LTEgaW5wdXQpCiAgKHBhcnQtMiBpbnB1dCkKICAp

Felipe14:12:36

spent a long time looking for a catch. no catch! was kind of proud until I saw the one liners https://github.com/FelipeCortez/advent-of-code/blob/master/2023/09.clj

Ivana14:12:31

Easy task, both parts in a same evaluation:

(->> input
     str/split-lines
     (map (fn [s]
            (let [d (read-string (str "[" s "]"))
                  data (loop [v d
                              r (list d)]
                         (let [t (mapv - (rest v) v)]
                           (if (every? zero? t)
                             (cons t r)
                             (recur t (cons t r)))))]
              (reduce (fn [{:keys [f l]} v]
                        {:f (- (first v) f)
                         :l (+ l (last v))})
                      {:f 0 :l 0} data))))
     (apply merge-with +))

rjray18:12:03

OK, now that I've slept and am a little less salty about the input glitching... https://github.com/rjray/advent-2023-clojure/blob/master/src/advent_of_code/day09.clj

bhauman21:12:12

I really like @U2E1D7WUB’s recursive solve and the diffs method as well. (defn diffs [coll] (map - (next coll) coll)) Nice!

borkdude21:12:59

@U064J0EFR if you want to switch to cherry, just change /squint/ to /cherry/ in the url

bhauman21:12:14

@U04V15CAJ oh interesting. What’s the reload-ability story for squint?

borkdude21:12:23

what do you mean reload-ability? as in incremental REPL behavior?

bhauman21:12:59

reloading namespaces?

borkdude21:12:01

in the playground, if the REPL mode is on (see on the right). you can evaluate form by form using Cmd-Enter reloading namespaces: I usually rely on vite for hot-reloading with squint front-end projects + squint watch for re-compiling changes files

Raghav01:12:20

Love me some iterate magix.

rjray02:12:33

Cut the run-times in half.