adventofcode

2022-12-12T05:51:33.627279Z

Day 12 - Solutions

2022-12-12T05:52:13.957239Z

https://gitlab.com/maximoburrito/advent2022/-/blob/main/src/day12/main.clj Finally a nice fun search...

wevrem 2022-12-12T05:58:42.004079Z

https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2022/day_12_elevations.clj Used a Dijkstra datatype I put in place for prior years.

wevrem 2022-12-12T07:18:09.320899Z

Had one of those “aha!” thoughts as I was just about to head to bed, and totally revamped my approach for part II. Okay, maybe not so much “aha!” as “duh!”

Aleks 2022-12-12T07:28:49.964299Z

@michaeljweaver like your comments (thoughts) in the code

leinfink 2022-12-13T15:06:10.428389Z

refactored a bit https://github.com/leinfink/aoc-2022-clj/blob/main/src/aoc22/day12.clj

bhauman 2022-12-13T15:41:56.933099Z

@zengxh my coding was 1-26 and I was using 0 for start and 27 for end. I was a real puzzler for me…

Apple 2022-12-13T15:50:44.994999Z

1 for start and 26 for end then

Apple 2022-12-13T15:51:45.402559Z

i use 0 and 25 for the 0-25 range

Apple 2022-12-13T15:52:27.130749Z

doesn't matter really as long as the start and end falls in the range

bhauman 2022-12-13T17:11:45.382959Z

But the interesting question is why would [start = 0, a = 1 … z=26, end = 27] provide a different result ing edge length of 444 in this case (both in loom and my custom bfs), and when I changed the mapping to [start = 1, a = 1 … z=26, end = 26] I got the correct solution of 440 . The traversal rules work the same for both? hmmmm ….

leinfink 2022-12-13T17:12:52.023789Z

You can go from Y (25) to Z (26), but not to 27

💯 1
leinfink 2022-12-13T17:13:00.486279Z

I think?

Apple 2022-12-13T17:13:07.120079Z

y25 cannot get to E27

bhauman 2022-12-13T17:13:07.372219Z

yeah thats right

bhauman 2022-12-13T17:13:34.206149Z

so you can skip the last z

bhauman 2022-12-13T17:14:09.116949Z

I just didn’t think that was correct

bhauman 2022-12-13T17:15:50.944799Z

In fact you can skip all of the last z’s theoretically I just didn’t think the problem implied that at all

bhauman 2022-12-13T17:17:04.714719Z

I’m rereading the problem for the qoute I missed now

bhauman 2022-12-13T17:17:23.486779Z

Also included on the heightmap are marks for your current position (S) and the location that should get the best signal (E). Your current position (S) has elevation a, and the location that should get the best signal (E) has elevation z.

bhauman 2022-12-13T17:17:38.052239Z

pretty straightforward …

bhauman 2022-12-13T17:17:40.694339Z

ugh

leinfink 2022-12-13T17:18:40.473709Z

if you got lucky and had my input instead, i think your mistake wouldn't have mattered and your day would have been much more relaxing haha

bhauman 2022-12-13T17:18:56.227929Z

OMG

bhauman 2022-12-13T17:19:55.603169Z

😝 1
bhauman 2022-12-13T17:20:57.621999Z

bhauman 2022-12-13T17:21:30.934809Z

yep there are the extra steps

leinfink 2022-12-13T17:22:18.530599Z

ah I had that start too, so it still would have mattered

Aleks 2022-12-12T08:32:16.947079Z

old good bfs without any tricks https://github.com/zelark/AoC-2022/blob/master/src/zelark/aoc_2022/day_12.clj

Callum Oakley 2022-12-12T09:13:37.110019Z

https://github.com/callum-oakley/advent-of-code/blob/main/src/aoc/2022/12.clj always happy to have an opportunity to use my search functions. used the same trick as @michaeljweaver. searching in reverse 😌

Casey 2022-12-12T10:20:33.847999Z

Today was fun! I leaned on loom rather than come up with my own bfs alg. https://github.com/Ramblurr/advent-of-code/blob/main/src/aoc/2022/day12.clj

Aleks 2022-12-12T10:21:38.705219Z

Ok, I refactored it and use the same trick for part 2. Thanks @michaeljweaver https://github.com/zelark/AoC-2022/blob/master/src/zelark/aoc_2022/day_12.clj

Aleks 2022-12-12T10:23:09.873199Z

@c.oakley108 how does it work for part 2 if you don’t change the climbing condition?

Callum Oakley 2022-12-12T10:24:55.933829Z

I’m doing part 1 in reverse as well 🙂

Aleks 2022-12-12T10:25:32.026029Z

Ohh, I missed that 🙃

Aleks 2022-12-12T12:59:59.211549Z

Found out that my lowest destination on the way is just -2 from the current. Seems like nobody would break their legs.

😌 1
tschady 2022-12-12T13:53:52.416779Z

Re-used my grid library, leveraged ubergraph algorithm, Terra Incognita has infinite height. https://github.com/tschady/advent-of-code/blob/main/src/aoc/2022/d12.clj

👍 1
leinfink 2022-12-12T15:06:12.027619Z

I didn't keep track of particular paths, just spread out from the starting point with a counter for each step, using sets to avoid double checks. This worked flawlessly for multiple starting points (and goals also, I guess), so I think this was my luckiest part 2 so far. https://github.com/leinfink/aoc-2022-clj/blob/main/src/aoc22/day12.clj

2
bhauman 2022-12-12T17:26:16.841699Z

I’m high I’m low and I’m high again. Fun stuff!

🥴 1
bhauman 2022-12-12T17:29:08.285189Z

one of my problems is I’m using the graph library loom b/c I be darned if I implement dikstras, but now I don’t have insight into why its choosing a least optimal path, other than I’m creating the graph wrong.

bhauman 2022-12-12T18:07:42.306369Z

LGTM

👍 1
👏 1
🗻 2
bhauman 2022-12-12T18:49:23.064349Z

yeah I guess there is an off by one error somewhere but looking at the output it really seems like the minimal path so I’m going to let it go for now, and come back to it this evening

Casey 2022-12-12T18:51:02.124629Z

Consider that in the example explanation for Day12 they are counting steps, not the number of nodes visited

Casey 2022-12-12T18:51:15.936699Z

That could be causing an off by 1

Casey 2022-12-12T18:52:23.719169Z

(I also used loom 😊)

bhauman 2022-12-12T18:52:33.248489Z

Thanks! That’s good advice. But … that’s already been accounted for as I dec the result.

bhauman 2022-12-12T18:52:45.122219Z

awesome, loom users unite!

Aleks 2022-12-12T18:57:37.763439Z

@bhauman Could you miss out this statement “This also means that the elevation of the destination square can be much lower than the elevation of your current square”?

bhauman 2022-12-12T18:58:45.316209Z

thanks, yeah thats in there to and my path has to allow for that as it goes [ab … nopnopqr …]

👍🏻 1
Felipe 2022-12-12T20:49:28.007409Z

ugly as hell dijkstra code, but it gets the job done https://github.com/FelipeCortez/advent-of-code/blob/master/2022/12.clj

genmeblog 2022-12-12T22:57:14.760579Z

When your paths end nowhere, read this sentence after a couple of hours of debugging :/ > (This also means that the elevation of the destination square can be much lower than the elevation of your current square.)

🤦 1
🤦🏻 1
chucklehead 2022-12-12T23:59:57.565239Z

Came here to say basically the same thing

🙂 1
chucklehead 2022-12-13T00:00:15.788769Z

Couldn’t figure out why my bfs worked on the sample but not the full

bhauman 2022-12-13T05:50:00.385539Z

I did figure out my problem from earlier, I was setting start to 0 and end to 27 thinking that I was being clever. Still not sure why that added 4 steps to the result but … I’ll look into it more tomorrow

Apple 2022-12-13T06:36:43.622429Z

y25 cannot get to E27

Miķelis Vindavs 2022-12-14T09:00:27.846559Z

@leinfink apparently your algo has a name: https://en.wikipedia.org/wiki/Lee_algorithm

leinfink 2022-12-14T09:11:40.716029Z

@mikelis.vindavs oh, interesting. I wonder if the fact that I didn't need to do the backtrace part mitigates some of that slowness / memory usage? but i guess thats negligible

leinfink 2022-12-14T09:15:26.135339Z

ohh and i like the idea of propagating waves from source and target at the same time

➕ 1
leinfink 2022-12-14T12:45:39.815949Z

welp, tried it, didn't give any noticeable performance benefit tho

Benjamin 2022-12-12T15:09:52.800879Z

tips for day 12?

Benjamin 2022-12-12T15:10:27.876859Z

I have a function that finds all possible paths but the time complexity doesn't work for the input

Aleks 2022-12-12T15:43:51.489069Z

breadth-first search

Miķelis Vindavs 2022-12-12T15:46:45.913769Z

you could google Dijkstra’s algorithm

Miķelis Vindavs 2022-12-12T15:49:04.316259Z

also, clojure has a somewhat hidden datastructure called PersistentQueue It is fast to add to the back and remove from the end Create an empty one with clojure.lang.PersistentQueue/EMPTY (no parens needed) Add to the end (right) with conj Look at the first element (left) with peek Return a new queue without the first element with pop

Callum Oakley 2022-12-12T15:49:43.190489Z

hard to say without seeing what you’ve already got, but given you say you already have a function to find all possible paths I have a hunch you’ll already be doing BFS (or something equivalent) and the time complexity issue will be because of double counting. make sure you’re not finding multiple paths to the same place! (you only care about the shortest one)

💯 3
👀 1
Aleks 2022-12-12T15:51:30.322579Z

a handy helper for PersistentQueue

(defn queue [& args]
  (into PersistentQueue/EMPTY args))

➕ 1
Miķelis Vindavs 2022-12-12T15:55:04.927419Z

That’s exactly the one I have in my support namespace as well 😄

🙌🏻 1
Callum Oakley 2022-12-12T15:58:51.306419Z

while we’re sharing convenient type wrappers for search, here’s my https://github.com/callum-oakley/advent-of-code/blob/main/src/aoc/search.clj#L8-L13 based on clojure.data.priority-map (useful for Dijkstra)

👍 1
👍🏻 1
J 2022-12-12T15:59:04.865039Z

I have used PriorityQueue

Miķelis Vindavs 2022-12-12T16:05:05.920189Z

oh nice i didn’t know clojure.data.priority-map existed

Miķelis Vindavs 2022-12-12T16:05:20.954809Z

i guess you could also build it using a sorted-map

Miķelis Vindavs 2022-12-12T16:08:30.914089Z

@c.oakley108 that’s a very nice support lib!

😁 1
2022-12-12T20:26:18.721039Z

I'm a ways behind, just catchup up with day 10 now. I have a question about part 2. Question in thread to avoid spoilers.

2022-12-12T20:29:12.217529Z

I'm not sure what's asking me to do. I dont see the relevance of what I did in part 1. I have all the values for x at each cycle (240 of them). So essentially in pseudo code is it asking

for n = 1 to 240:
   if x-values[n] is within +/- 1 of n (mod 40):
      draw dark pixel
      draw light pixel 
Is that right?

2022-12-12T20:42:26.149229Z

Argh, I had (<= 1 ,,, ), where I should have had (<= ,,, 1) Solved now