Unable to load image

rDrama Advent of Code Day 17: It's the weekend, why are you here? Edition

Summary for those just joining us:

Advent of Code is an annual Christmas themed coding challenge that runs from December 1st until christmas. Each day the coding problems get progressively harder. We have a leaderboard and pretty good turnout, so feel free to hop in at any time and show your stuff!

Whether you have a single line monstrosity or a beautiful phone book sized stack of OOP code, you can export it in a nice little image for sharing at https://carbon.vercel.app

What did you think about today's problem?

https://adventofcode.com/2023

Our Code is 2416137-393b284c (No need to share your profile, you have the option to join anonymously if you don't want us to see your github)

31
Jump in the discussion.

No email address required.

>dijkstra doesn't work since there's no way of knowing if a cheaper/equal path might cause a 4-line in the future

I'm gonna find Eric's minecraft base and puts lots of TNT under it

EDIT: YES FUCK THANK GOD I'M NOT FILTERED

DY DX←⍴r←⍎¨↑⊃⎕NGET'17.ex'1
⍝ Set to 0 3 for part 1, or 4 10 for part 2.
I J←4 10
q←,⊂0 1 1 0 0 0
v←⍬

us←{c←(0 1)(0 ¯1)(1 0)(¯1 0\. ⋄ m1←⍵∘≢¨⊂¨c ⋄ m2←(-⍵)∘≢¨⊂¨c ⋄ c/⍨m1∧m2}
a←{
    t←⊂w y x dy dx l←⊃⍵
    (dy≡0)∧(dx≡0):⍬
    (l>¯1+J):⍬
    y2←y+dy ⋄ x2←x+dx
    y2<1:⍬ ⋄ y2>DY:⍬ ⋄ x2<1:⍬ ⋄ x2>DX:⍬
    ⊂(w+(⊂y2 x2)⊃r) y2 x2 dy dx (l+1)
}
u←{
    t←⊂w y x dy dx l←⊃⍵
    (l<I)∧(~(dy≡0)∧(dx≡0)):⍬
    n←us⊂dy dx
    e←{dy dx←⍵ ⋄ ny nx←(y+dy)(x+dx)
        0(ny)(nx)(dy)(dx)1}¨n
    e←({_ y x _ _ _←⍵ ⋄ (0<y)∧(DY≥y)∧(0<x)∧x≤DX}¨⊢⍤/⊢)e
    w←{_ y x _ _ _←⍵ ⋄ ((⊂y x)⊃r)+w}¨e
    w,¨1↓¨e
}
b←{
    n1←a ⍵ ⋄ n2←u ⍵
    0⊣q⊢←(⊂∘⍋⌷⊣)∪q,n1,n2
}
p←{
    w y x dy dx l←⊃t←1⌷q
    s←⊂y x dy dx l
    (DY≡y)∧(DX≡x)∧(l≥I):t
    q⊢←1↓q
    s∊v:0
    v⊢←v,s
    y<1:0 ⋄ y>DY:0 ⋄ x<1:0 ⋄ x>DX:0
    0⊣b t
}
⎕←⊃⊃p⍣{0≢⍺}⊢0
Jump in the discussion.

No email address required.

can't apply djikstras when a trivial knot is thrown in

ngmi

Jump in the discussion.

No email address required.

t. using a fake language where you "import heap" aka have a library solve it for you. Real programmers implement their algorithms from scratch, at least until they realise the matrix has 6 dimensions and holy shit this is not happening :marseyitsover:

Jump in the discussion.

No email address required.

ACschewly it's import heapq

:#marseyakshually:

Jump in the discussion.

No email address required.

:marseyitsover: :taycringe:

barely know how to do standard djikstras

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/17028080590931756.webp

Spent a lot of time wondering why my part 1 didnt work, only to realize that at one point I changed the input data to test something and never changed it back :marseysad:

Jump in the discussion.

No email address required.

It was a nightmare for me, I stepped on every possible rake it seems. Somehow got it into an infinite loop by checking if current score is <= best score for a key. Missed the possibility of starting facing down for no cost. Missed the part where in the second half you need to check for minimal distance when stopping at the end. Ugh.

Also it takes 12 and 17 seconds for me for a dumb BFS that might need to revisit some nodes (which it certainly does a lot, I feel). Do I have to learn how to A* or what?

Jump in the discussion.

No email address required.

I kinda like the thing I ended with after all that, it's pretty straightforward if I say so myself.

https://i.rdrama.net/images/1702796059593613.webp

Jump in the discussion.

No email address required.

works on the provided example, is stuck running on the actual input (10 mins and counting), but I know my solution won't go above ~30 mb of ram or crash

maybe instead of figuring out what I did wrong, I''ll just let it run as I sleep, and wake up to a present from my computer?

:#marseysanta:

Jump in the discussion.

No email address required.

works on the provided example, is stuck running on the actual input (10 mins and counting)

Check if your condition for revisiting a node is strictly less-than current score. I hit an infinite loop somehow by having it "<=", no idea how this is even possible, but I guess with Jesus all things are possible and this is Advent so...

Jump in the discussion.

No email address required.

Debugging a pathfinding algo when your code passes the sample but not your input :marseytrollcrazy:

https://i.rdrama.net/images/17027990360809767.webp

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/1702830058347118.webp

I used the tricks you guys showed me yesterday @TriHard @everyone

Jump in the discussion.

No email address required.

I can't be arsed today :marseyyawn: .

Here is a figure of the map in lieu of code https://i.rdrama.net/images/17028213456442957.webp .

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/17028560915609746.webp

Part 2 solution - I groaned when I realized I had to handle an additional vertex for every possible combination of directions and lengths it takes a visitor to reach each square, but it ended up not being too bad in the end.

Jump in the discussion.

No email address required.

Had to relearn djikstra's algorithm, but straightforward once I remembered how it worked, aside from a really annoying bug with using (x1, y2) as the break condition

https://i.rdrama.net/images/17028587936104956.webp

Jump in the discussion.

No email address required.

I think today's fucked my streak :( I just can't get it. Any help greatly appreciated, it's probably in the dijkstra method because I've debugged get_next_moves() and that returns only valid next steps.

https://i.rdrama.net/images/17028399072966845.webp

Jump in the discussion.

No email address required.

You are only storing the position in visited, but you also need to store the direction you are moving in and the how often you have moved in that direction in the past.

Jump in the discussion.

No email address required.

I'm not really getting it. I am storing those things in to_visit but then you're right I don't care about them once I insert into visited. Why do I need it in visited? I only use visited to check if I've seen that coord yet.

Jump in the discussion.

No email address required.

Because it makes a difference on how you have visited the coord. Visiting the cord with steps_in_direction == 3 will have different outcome than visiting it with 0.

(also it seems like you are just checking if you have visited the coordinate, but I think you need to compare the current heat to the stored heat, and only reject if current heat > stored heat)

Jump in the discussion.

No email address required.

Thanks again, more for me to chew on. I think I need to learn Dijkstra and revisit this, I haven't done it since uni.

Jump in the discussion.

No email address required.

Thanks I'd been messing around with things like that earlier on but couldn't quite get it right. I'll give it another go.

Jump in the discussion.

No email address required.

Oh lol I see it


Give me your money and I'll annoy people with it :space: https://i.rdrama.net/images/16965516366194396.webp

Jump in the discussion.

No email address required.

I'll do anything please just let me know

Jump in the discussion.

No email address required.

that'd go against the spirit :marseyzeldalinktoon: of advent of code

:marseyshrug#:


Give me your money and I'll annoy people with it :space: https://i.rdrama.net/images/16965516366194396.webp

Jump in the discussion.

No email address required.

I think that collaboration and learning are key parts of Advent of Code. I think I've got it now anyway.

Jump in the discussion.

No email address required.

Good job :marseyexcited: it's always the little things


Give me your money and I'll annoy people with it :space: https://i.rdrama.net/images/16965516366194396.webp

Jump in the discussion.

No email address required.

Pls pls pls

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/17034043794353719.webp

Jump in the discussion.

No email address required.

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.