adventofcode

2023-12-09T05:20:22.657359Z

Day 9 - Solutions

rjray 2023-12-11T02:01:15.877149Z

Using @raghavsharma's iterate magic, I revised my Day 9: https://github.com/rjray/advent-2023-clojure/blob/master/src/advent_of_code/day09bis.clj

rjray 2023-12-11T02:01:33.168879Z

Cut the run-times in half.

rjray 2023-12-09T08:04:08.572589Z

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?

wevrem 2023-12-09T08:12:22.730269Z

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

rjray 2023-12-09T08:14:07.740999Z

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

rjray 2023-12-09T08:15:13.991979Z

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

wevrem 2023-12-09T08:19:23.706789Z

Is this helpful: my input had 200 lines.

rjray 2023-12-09T08:20:12.152799Z

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
rjray 2023-12-09T08:24:49.943479Z

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

karlis 2023-12-09T09:24:51.518979Z

Short and sweet with iterate + take-while and reduce https://github.com/skazhy/advent/blob/master/src/advent/2023/day9.clj

tschady 2023-12-09T11:49:46.322049Z

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
alpox 2023-12-09T12:03:25.267579Z

This was… much easier than expected πŸ‘€

borkdude 2023-12-09T12:48:40.245689Z

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

Arnaud Geiser 2023-12-09T13:42:24.019649Z

Not a smart solution, but it works : https://github.com/arnaudgeiser/advent-of-code/blob/master/2023/clojure/src/advent_of_code/day9.clj

Felipe 2023-12-09T14:27:36.269069Z

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

Ivana 2023-12-09T14:52:31.277359Z

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 +))

bhauman 2023-12-09T15:38:07.666619Z

Day 9 really rewards recursive thinking https://github.com/bhauman/adv2023/blob/main/src/adv2023/day09/sol.clj

borkdude 2023-12-09T16:43:44.100869Z

@bhauman amazing. https://squint-cljs.github.io/squint/?boilerplate=https%3A%2F%2Fgist.githubusercontent.com%2Fborkdude%2Fcf94b492d948f7f418aa81ba54f428ff%2Fraw%2Fa6e9992b079e20e21d753e8c75a7353c5908b225%2Faoc_ui.cljs&repl=true&src=OzsgSGVscGVyIGZ1bmN0aW9uczoKOzsgKGZldGNoLWlucHV0IHllYXIgZGF5KSAtIGdldCBBT0MgaW5wdXQKOzsgKGFwcGVuZCBzdHIpIC0gYXBwZW5kIHN0ciB0byBET00KOzsgKHNweSB4KSAtIGxvZyB4IHRvIGNvbnNvbGUgYW5kIHJldHVybiB4Cgo7OyBTb2x1dGlvbiBieSBiaGF1bWFuOgo7OyBodHRwczovL2dpdGh1Yi5jb20vYmhhdW1hbi9hZHYyMDIzL2Jsb2IvbWFpbi9zcmMvYWR2MjAyMy9kYXkwOS9zb2wuY2xqCgooZGVmIGlucHV0CiAgKC0%2BPiAoanMtYXdhaXQgKGZldGNoLWlucHV0IDIwMjMgOSkpCiAgICAoc3RyL3NwbGl0LWxpbmVzKQogICAgKG1hcCAjKGFzLT4gJSB4CiAgICAgICAgICAgIChzdHIgIlsiIHggIl0iKQogICAgICAgICAgICAoc3RyL3JlcGxhY2UgeCAiICIgIiwiKQogICAgICAgICAgICAoanMvSlNPTi5wYXJzZSB4KSkpKSkKCihkZWZuIGRpZmZzIFtsXQogICgtPj4gbCAocGFydGl0aW9uIDIgMSkgKG1hcHYgIyhhcHBseSAtIChyZXZlcnNlICUpKSkpKQoKKGRlZm4gbmV4dC1udW0gW251bS1zZXFdCiAgKGxldCBbZHMgKGRpZmZzIG51bS1zZXEpXQogICAgKGlmIChldmVyeT8gemVybz8gZHMpCiAgICAgIChsYXN0IG51bS1zZXEpCiAgICAgICgrIChsYXN0IG51bS1zZXEpCiAgICAgICAgKG5leHQtbnVtIGRzKSkpKSkKCjs7IHBhcnQgMQooY29tbWVudAogIChyZWR1Y2UgKyAobWFwIG5leHQtbnVtIGlucHV0KSkKICApCgooZGVmbiBwcmV2LW51bSBbbnVtLXNlcV0KICAobGV0IFtkcyAoZGlmZnMgbnVtLXNlcSldCiAgICAoaWYgKGV2ZXJ5PyB6ZXJvPyBkcykKICAgICAgKGZpcnN0IG51bS1zZXEpCiAgICAgICgtIChmaXJzdCBudW0tc2VxKQogICAgICAgIChwcmV2LW51bSBkcykpKSkpCgo7OyBwYXJ0IDIKKGNvbW1lbnQKICAocmVkdWNlICsgKG1hcCBwcmV2LW51bSBpbnB1dCkpCiAgKQ%3D%3D

rjray 2023-12-09T18:21:03.950189Z

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

bhauman 2023-12-09T21:41:11.320839Z

@borkdude oh very cool

bhauman 2023-12-09T21:51:12.385589Z

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

borkdude 2023-12-09T21:51:59.345429Z

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

bhauman 2023-12-09T21:53:14.575399Z

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

borkdude 2023-12-09T21:54:23.111889Z

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

bhauman 2023-12-09T21:54:59.811409Z

reloading namespaces?

borkdude 2023-12-09T21:56:01.662349Z

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

borkdude 2023-12-09T21:56:37.377399Z

here is an example of that https://github.com/squint-cljs/squint/tree/main/examples/vite-react

πŸ‘ 1
Raghav 2023-12-10T01:26:20.743689Z

Love me some iterate magix.

Ryan Martin 2023-12-14T16:40:15.632919Z

Day 9 is like a breath of fresh air: https://github.com/rmrt1n/advent-of-code-2023-clj/blob/main/src/aoc/day09.clj

erdos 2023-12-09T05:28:07.480489Z

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.

wevrem 2023-12-09T05:37:25.532219Z

My https://github.com/wevre/advent-of-code/blob/3193fdd801e4a25fc104ceda5597b0f62ce05dda/notes/notes-aoc2023.txt#L210 for day 09.

πŸ‘πŸ» 1
πŸ‘€ 1
AC 2023-12-09T05:39:32.873639Z

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

βž• 2
2023-12-09T05:43:01.677349Z

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

Apple 2023-12-09T05:51:13.979679Z

https://pastebin.com/raw/Jid9sHKf

wevrem 2023-12-09T05:51:18.274389Z

@erdos I like your reduce version.

erdos 2023-12-09T05:59:53.156089Z

@michaeljweaver I like your use of transduce!

Aleks 2023-12-09T06:31:14.513969Z

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

wevrem 2023-12-09T06:34:03.605899Z

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

❀️ 1
wevrem 2023-12-09T06:59:43.203739Z

A very, very https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2023/day_09_v2.clj after imbibing those of @erdos and @zelark.

πŸ‘ 1
πŸ‘πŸ» 1
wevrem 2023-12-09T07:17:59.785369Z

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

Aleks 2023-12-09T07:21:27.687209Z

@michaeljweaver sure, actually I copied it from https://groups.google.com/g/clojure-dev/c/NaAuBz6SpkY

Aleks 2023-12-09T07:37:21.131549Z

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