adventofcode

roklenarcic 2024-12-12T06:11:19.457149Z

Day 12 - Solutions

2024-12-12T06:18:18.641959Z

https://gitlab.com/maximoburrito/advent2024/-/blob/main/src/day12/main.clj This is definitely ugly. I struggled to name things and payed the price. I also payed the price for not having handy search abstractions built up. Normally I find it fun to write it by hand each time, but this time with a search on top of a search, it was quite awkward. Maybe this will get cleaned up tomorrow with some sleep.

roklenarcic 2024-12-12T06:21:17.319799Z

Can’t be worse than mine: https://gist.github.com/RokLenarcic/931023da7afbc13f53b2aa3799027288

roklenarcic 2024-12-12T06:22:04.855089Z

Awful part 1 rank on this one and bad for part 2

🀯 1
2024-12-12T06:25:04.505199Z

at first glance, I think we did exactly the same thing for the sides, searching the graph of [perimeter direction] nodes

roklenarcic 2024-12-12T06:36:10.036319Z

Which is awful lol

roklenarcic 2024-12-12T06:36:27.040519Z

I will replace this with a proper solution

roklenarcic 2024-12-12T06:36:44.586469Z

Even part1 I was 4300th place, took me way too long.

erdos 2024-12-12T08:52:14.142629Z

I had this stupid idea of representing boundary points as floats.. and then wasted a lot of time there. https://github.com/erdos/advent-of-code/blob/master/2024/day12.clj

Maravedis 2024-12-12T11:10:11.492549Z

My solution works for every test input I can find, but too high on real input on part2 😞

vollcheck 2024-12-12T12:43:23.675739Z

@malaingreclement ugh, I hate days like this... I know this might sound awfully obvious, but - as someone else said - it's best to have correct solution on the first try πŸ˜›

Felipe 2024-12-12T12:52:21.191989Z

hmmm, my part 1 works for all three examples, but too low for the real input

Felipe 2024-12-12T12:55:40.251379Z

@erdos I represented mine as rationals

Felipe 2024-12-12T13:01:53.481899Z

wonder if I'm missing something in my perimeter calculation

(defn perimeter [region]
  (count
   (reduce (fn [s position]
             (into s (keep (fn [delta]
                             (let [neighbor (mapv + position delta)]
                               (when-not (contains? region neighbor)
                                 (mapv + neighbor (mapv (partial * 1/2) delta)))))
                           deltas)))
           #{}
           region)))

genmeblog 2024-12-12T13:09:42.915229Z

My idea was to store fence as a pair of fields in->out (this helped me to avoid crossed fence case eventually). https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2024/day12.clj

genmeblog 2024-12-12T13:14:31.146519Z

@felipecortezfi your neighbor is a vector and you call contains? on this vector (not elements of it). Is it right? Maybe you wanted to filter neighbors?

Felipe 2024-12-12T13:46:38.097829Z

think it's right. region is #{[1 2] [2 2]}, I want to see if e.g. [2 2] + [-1 0] is a position in the region

genmeblog 2024-12-12T13:47:32.228139Z

Ah, ok, got it. It's just a vector adding.

Felipe 2024-12-12T13:47:47.786979Z

yep!

vncz 2024-12-12T13:57:29.363069Z

Is it a safe assumption that every letter is its own unique region? It appears that the input reuses letter for unrelated regions.

Felipe 2024-12-12T13:58:37.538539Z

@vincenz.chianese no! the X O example shows that

Felipe 2024-12-12T13:58:45.146409Z

> Plants of the same type can appear in multiple separate regions

Felipe 2024-12-12T13:59:22.751999Z

think I found my issue. I'm forgetting to detect some regions

vncz 2024-12-12T14:00:01.171319Z

Oh ok, it's more of a plant type

Kirill Chernyshov 2024-12-12T14:25:01.513349Z

"corner counting" for part two https://gist.github.com/DeLaGuardo/b6e073a9551290fe8683fd688d095b38

πŸ‘ 1
πŸ‘πŸ» 1
tildedave 2024-12-12T14:32:29.512829Z

I used a similar trick to last year's "squeeze through the pipes" problem, e.g. expand the graph so it's easier to count the borders. then it's flood fill + counting for p1, flood fill + following the border for p2. I spent a bunch of time on p2 trying to follow the border without tracking an explicit direction, which got me very close (passed on all examples) but I had to rewrite it. https://github.com/tildedave/advent-of-code/blob/main/src/advent2024/day12.clj I kind of wonder if for p1 perimeter you could just count cells that are NSEW adjacent to something with a different letter. (haven't checked reddit yet)

tildedave 2024-12-12T14:34:54.339349Z

corner counting is quite clever.

Aleks 2024-12-12T15:27:22.005849Z

Phew, I finally managed to get it done.

πŸ™Œ 1
Aleks 2024-12-12T16:01:38.987049Z

Cleaned up it a bit https://github.com/zelark/AoC/blob/master/src/zelark/aoc_2024/day_12.clj

Felipe 2024-12-12T17:33:04.659299Z

(defn perimeter [region]
  (count
   (reduce (fn [s position]
             (into s (keep (fn [delta]
                             (let [neighbor (mapv + position delta)]
                               (when-not (contains? region neighbor)
                                 (mapv + neighbor (mapv (partial * 1/2) delta)))))
                           deltas)))
           #{}
           region)))
duh. completely wrong. (mapv + neighbor (mapv (partial * 1/2) delta) -> (mapv + position (mapv (partial * 1/4) delta)

Felipe 2024-12-12T17:33:27.930719Z

got both parts!

Felipe 2024-12-12T17:34:28.378259Z

exitsandman 2024-12-12T17:35:31.167109Z

how does one create collapsible code blocks aside from dragging files in again? not very clear from the slack interface

Maravedis 2024-12-12T17:35:55.517259Z

FINALLY

πŸ‘ 1
πŸ‘πŸ» 1
Felipe 2024-12-12T17:36:14.238679Z

@doppiaelle1999 I don't drag the files. have to copy the contents, go to the bottom left corner and click the plus, text snippet

1
Maravedis 2024-12-12T17:36:20.542199Z

@doppiaelle1999 shift+ctrl+enter or click on the + on the bottom left and click on "create snippet"

πŸ‘ 1
Maravedis 2024-12-12T17:37:12.349359Z

It took me a decade and I had to go sleep in between but I'm finally done ><

Felipe 2024-12-12T17:37:35.965839Z

@malaingreclement hammock time πŸ™‚

Felipe 2024-12-12T17:38:28.382179Z

proud of my little clojure.lang.Rational trick today

Maravedis 2024-12-12T17:44:43.321029Z

My solution is... kinda awful? I walk the outeredge and remember the coordinates of the void on the left, to then generate all the neighbors of the current region. Remove the outer edge from that and bam, got the islands.

Maravedis 2024-12-12T17:45:15.710709Z

It's a bit stupid imho, but it works, so it's not stupid.

Maravedis 2024-12-12T17:55:34.829399Z

This is so bad it's almost funny.

Aleks 2024-12-12T18:00:04.170959Z

It doesn't matter, what matters is you nailed it!

1
3
exitsandman 2024-12-12T18:17:14.137039Z

The corner counting never occurred to me due to using graph searches as a golden hammer from the start, so part 2 is (especially) fugly

bhauman 2024-12-12T18:18:21.076509Z

Here’s today’s and I got tree-seq in there: https://github.com/bhauman/adv2024/blob/main/src/adv2024/day12/sol.clj

πŸŽ„ 2
Maravedis 2024-12-12T18:18:46.579359Z

Second time I see you using tree-seq. I should learn to use it, it looks fun.

πŸ‘ 1
bhauman 2024-12-12T18:19:23.930509Z

bhauman 2024-12-12T18:48:46.601989Z

Conrer counting! Well that would have been nice to know. πŸ˜‚ Now I have to give it a try.

vollcheck 2024-12-12T19:01:21.317399Z

yeah, corner counting would be much faster to implement than mine: https://github.com/vollcheck/aoc/blob/master/src/y24/day12.clj I'm grouping boundaries by the direction they look to and then by x or y axis + checking if they are contiguous

πŸ‘ 1
bhauman 2024-12-12T20:07:52.967739Z

Actually, after trying it, I don’t know that counting corners is significantly easier in terms of code, it might be conceptually easier????

misha 2024-12-12T20:16:53.621829Z

corner counting since first solution hit both OOM and garbage collector walls :) not pretty. "Elapsed time: 111.823166 msecs" total

vollcheck 2024-12-12T20:28:30.364169Z

Okay I agree, maybe corner counting isn’t that easy

tschady 2024-12-12T20:31:20.986769Z

I counted corners. busy with work today, I think I can tighten this up.

2024-12-12T22:16:55.462489Z

Excited to see the simpler ways everyone solved part 2, mine really got out of hand πŸ˜… https://github.com/alexlapp/aoc_clojure/blob/main/src/advent_of_code/2024/day12.clj#L62 I found regions in part 1 by creating sets of [x y] coordinates where they shared edges. I found sides by looking at each cell and counting the which of the 4 sides did not touch other cells in the region. For part 2, I take the set of coordinates that represents a region, split it into rows, split each row into blocks (for cases where the shape "touches" a column in multiple sections), and then map those blocks into values of either :exposed or :covered if there is a block above them, then partition-by those values, filter out the covered sections, and count what's left. Doing the partition-by organizes these into sets of shared sides. Then I do the same for the row looking at exposed or covered for below, then split the region into columns and do the same for each column looking to the left and right.

Andrew Byala 2024-12-12T23:28:33.263599Z

I finally did my writeup for today. β€’ Blog: https://github.com/abyala/advent-2024-clojure/blob/main/docs/day12.md β€’ Code: https://github.com/abyala/advent-2024-clojure/blob/main/src/advent_2024_clojure/day12.clj

πŸ‘πŸ» 1
Apple 2024-12-13T19:47:09.869799Z

alright so they decide in regards to A the highlighted part has 4 sides instead of 2. what a bummer for me.

Maravedis 2024-12-13T19:52:24.719259Z

Yeah.

Maravedis 2024-12-13T19:54:08.729639Z

Also don't forget : if one of those B were a C, the calculation for A would stay the same (the total would change, ofc, but it doesn't change the number of sides from A 's point of view).

Apple 2024-12-13T19:54:09.672329Z

thought i found an elegant way to solve it until only 4/5 pass

Apple 2024-12-13T20:05:03.189649Z

for part1 perimeter: the regions of garden plots are determined first. within each region, i map each garden plot [y x] to 4 edges in this form [y x y+1 x] [y x y x+1] [y+1 x y+1 x+1] [y x+1 y+1 x+1] then do a freq on the collections of all edges, and keep only those with count equals 1 then it's the perimeter

Apple 2024-12-13T20:06:53.083809Z

for part2 i try to build on top of part1 based on the 4 tuple form edges and unfortunately it fails for that particular case. looks like i need to walk the border garden plot. 😞

Apple 2024-12-13T20:07:58.292039Z

Maravedis 2024-12-12T07:32:19.991979Z

Godammit, the problem warned me about inside fencing and I still forgot -_-

3
Zach 2024-12-13T17:28:52.409709Z

This one really got me too. I'm still stuck πŸ˜…

Maravedis 2024-12-12T10:33:07.830529Z

So I don't see any, but maybe I'm wrong. Can someone spoil this for me: is there deeper nesting than one level in the real input ?

exitsandman 2024-12-12T12:06:16.350449Z

can't see any in mine tbh

Maravedis 2024-12-12T12:06:58.433509Z

Found my bug. Didn't account for co-linear nested inputs. Like

AAAA
ABCA
AAAA

2024-12-12T16:53:41.917589Z

we're back at the top of the hour!

2024-12-12T16:53:53.704519Z

Day 9 https://www.twitch.tv/timpote