This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

## 2023-12-11

## Channels

- # adventofcode (33)
- # babashka (1)
- # beginners (11)
- # biff (3)
- # calva (2)
- # cider (24)
- # clj-kondo (9)
- # cljfx (5)
- # clojure (39)
- # clojure-austin (2)
- # clojure-europe (11)
- # clojure-nl (1)
- # clojure-norway (22)
- # clojure-uk (10)
- # community-development (18)
- # data-science (24)
- # datahike (3)
- # events (3)
- # hyperfiddle (11)
- # lsp (22)
- # malli (3)
- # matrix (1)
- # off-topic (24)
- # other-languages (3)
- # overtone (7)
- # pathom (5)
- # reitit (2)
- # shadow-cljs (34)
- # sql (20)
- # squint (13)

My https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2023/day_11_galaxies.clj.

https://github.com/erdos/advent-of-code/blob/master/2023/day11.clj used sorted-set to quickly find the empty rows/cols in the path between two galaxies.

I like the use of sorted set. I’ve never used that before. I just rolled my own. :-)

sorted-set only helps if you keep track of the gaps instead of the galaxies (this universe is dense so there are much more galaxies than gaps)

that makes sense. I also just kept track of the gaps, but not with a sorted set. Just with a sorted list and then (this is what I meant by “rolled my own”) I filtered based on the two subject galaxies. I assume that is basically what a sorted set does, though perhaps more efficiently?

yes, sorted-set is practically a tree that can be used for fast interval search.
but since you used `filter`

, sorting the seq was really not necessary?

true. I think it was left over from an initial plan of maybe using drop and take. Just stayed in the code there even though it was no longer needed.

Tomorrow I’m going to learn more about sorted set and play around with a version 2. Good night!

not fancy, but it just does its job https://github.com/zelark/AoC/blob/master/src/zelark/aoc_2023/day_11.clj

@U2E1D7WUB I like your solution. Don’t remember if I’ve ever used `subseq`

before. Looks like a good place to employ it

first pass, used the excellent `tails`

I got from somebody here last year to get the combos:
https://github.com/tschady/advent-of-code/blob/main/src/aoc/2023/d11.clj

Same as others I suppose. https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2023/day11.clj

Got rid of the extra passes of the input. All we need is galaxies coordinates, so we can build sets of it and then use it to find spaces https://github.com/zelark/AoC/blob/master/src/zelark/aoc_2023/day_11.clj

I chose "brutal" list operations to get coordinates instead of smart arithmetic... https://github.com/caseneuve/aoc2023/blob/master/day11/solution.clj

After some fixes & improvements

```
(let [scale 1000000 ;; 2
gals (->> input (keep-indexed #(when (= \# %2) %1)))
d (-> input (str/index-of \newline) inc)
[grs gcs] (map (fn [f] (->> gals (map #(f % d)) set)) [quot rem])
dn (fn [a b s] (->> (range (min a b) (max a b))
(reduce (fn [acc i] (+ acc (if (get s i) 1 scale))) 0)))]
(->> (for [a gals
b gals
:when (< a b)]
(let [[[r1 c1] [r2 c2]] (map #(vector (quot % d) (rem % d)) [a b])]
(+ (dn r1 r2 grs) (dn c1 c2 gcs))))
(apply +)))
```

I took @U2E1D7WUB his solution and added stuff to *#C03U8L2NXNC* until it worked (mostly sorted-set and subseq)
https://squint-cljs.github.io/squint/?repl=true&boilerplate=https%3A%2F%2Fgist.githubusercontent.com%2Fborkdude%2Fcf94b492d948f7f418aa81ba54f428ff%2Fraw%2Fa6e9992b079e20e21d753e8c75a7353c5908b225%2Faoc_ui.cljs&src=OzsgSGVscGVyIGZ1bmN0aW9uczoKOzsgKGZldGNoLWlucHV0IHllYXIgZGF5KSAtIGdldCBBT0MgaW5wdXQKOzsgKGFwcGVuZCBzdHIpIC0gYXBwZW5kIHN0ciB0byBET00KOzsgKHNweSB4KSAtIGxvZyB4IHRvIGNvbnNvbGUgYW5kIHJldHVybiB4Cgo7OyBSZW1lbWJlciB0byB1cGRhdGUgdGhlIHllYXIgYW5kIGRheSBpbiB0aGUgZmV0Y2gtaW5wdXQgY2FsbC4KKGRlZiBpbnB1dCAoLT4%2BIChqcy1hd2FpdCAoZmV0Y2gtaW5wdXQgMjAyMyAxMSkpCiAgICAgICAgICAgICBzdHIvc3BsaXQtbGluZXMpKQooZGVmIGdyaWQgKG1hcHYgdmVjIGlucHV0KSkKCihkZWYgZW1wdHktcm93cwogIChpbnRvIChzb3J0ZWQtc2V0KQogICAgKGtlZXAtaW5kZXhlZCAo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m9yIFthIGdhbGF4aWVzLGIgZ2FsYXhpZXNdIChtYW5oYXR0YW4yIGEgYiBzY2FsZSkpCiAgICAocmVkdWNlICspCiAgICAoKiAxLzIpIChsb25nKQogICAgKHRpbWUpKSkKCihjb21tZW50CiAgKHNvbHZlICJGaXJzdCIgMikKICAoc29sdmUgIlNlY29uZCIgMTAwMDAwMCkKICAp

took me a while to realize that

```
(defn shortest-path-length [[j1 i1] [j2 i2]]
(let [[[j1 i1] [j2 i2]] [[(min j1 j2) (min i1 i2)] [(max j1 j2) (max i1 i2)]]]
(count
(take-while #(not= % [j2 i2])
(iterate (fn [[p1 p2]]
(if (< (dist [(inc p1), p2 ] [j2 i2])
(dist [ p1, (inc p2)] [j2 i2]))
[(inc p1), p2]
[ p1, (inc p2)]))
[j1 i1])))))
```

is just
```
(defn shortest-path-length [[j1 i1] [j2 i2]]
(+ (abs (- j1 j2)) (abs (- i1 i2))))
```

map expansion logic was also a bit tricky to get right. happy with my solution!
https://github.com/FelipeCortez/advent-of-code/blob/master/2023/11.cljI always have the ugliest code to deal with grids represented as nested vecs. this is very nice:

```
[[i row] (map-indexed vector grid)
[j cell] (map-indexed vector row)
```

There were already a lot of tasks with 2D-array model input. And most of the participants parsed it from string to vector of vectors, and then feel pain vith indexing, iteration, filtering etc. I suggest you keep it as it is - as string 😀 It supports `get`

by index, it implements `associative?`

and return nils on indices outside of its range, it may be easy processed with `keep-indexed`

, `str/index-of`

, regex etc. Only thing you have to do for modelling 2D array with it - convert one linear index to 2 2D. But keep in mind, that even raw C-like 2D arrays are actually 1D arrays with indices converting by `quot & rem`

, so you may do it by yourself and get away from naive "2D" arrays model of most langs (Java/C/etc). You may look into my this aoc tasks code solutions for examples & details

@U05T4JC21J6 nice! makes sense

My solution: https://github.com/rjray/advent-2023-clojure/blob/master/src/advent_of_code/day11.clj Not my best code, because I did part 1 by actually expanding the matrix representation of the input "image". The pure-math code for part 2 can easily be made to work with part 1. I'll do a revision of this one later.

It went quite well, thanks to clojure.math.combinatorics : https://github.com/arnaudgeiser/advent-of-code/blob/master/2023/clojure/src/advent_of_code/day11.clj

`(comb/permuted-combinations locations 2)`

may be simply implemented as
```
(->> (for [a locations
b locations
:when (< a b)]
```

without extra libsThank you Ivana for the hint!

Actually in your case when location is vector `<`

may not work but you may use `(pos? (compare a b))`

Works like a charm : https://github.com/arnaudgeiser/advent-of-code/blob/master/2023/clojure/src/advent_of_code/day11.clj#L25

Day 11 - for part 2 I just translated the initial coords into the new expanded coord system. https://github.com/bhauman/adv2023/blob/main/src/adv2023/day11/sol.clj

I know from many years of running that if you want to get from point A to point B, it's the same number of blocks regardless of what path you take. 😃

https://github.com/mtravers/aoc2023/blob/main/src/aoc2023/day11.clj Fortunate that I did part 1 in a way that made part 2 trivial.

I accumulated coordinate adjustments with `reductions`

:
https://gist.github.com/RokLenarcic/00a3a14c975d0ace582ff9a3695226b0