Unable to load image

rDrama Advent of Code Day 12: Hooke 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)

15
Jump in the discussion.

No email address required.

My favorite days are when the thread goes up and nobody comments for like 2-3 hours that's when you know it's fun

Edit: I had a nice recursive solution that worked by shifting each group one slot at a time and completed the example basically instantly but it's still running as slow as brute force I'm going to kms :marseyc#rygenocide:

Jump in the discussion.

No email address required.

>I had a nice recursive solution

Cache it and you're done

Jump in the discussion.

No email address required.

Yeah, saw everyone mentioning it but my code is on my work pc so I have to wait until I get into the office

Jump in the discussion.

No email address required.

found the incel

Jump in the discussion.

No email address required.

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

I paid for the whole processor, I'm gonna use the whole processor.

yeah I think I'll have to think this one more thoroughly, not even -O3 -march=native can save me :marseycry:


me rn:

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

Jump in the discussion.

No email address required.

holy shit bros, I was trying to optimize the absolute shitfrick out of my function, still had it crawl past at a snail's pace until I added memoization, and the lines rolled past so fast that I genuinely thought I had a bug. I literally creamed my pants. Yeah, I nutted from code. I'm codesexual.

Jump in the discussion.

No email address required.

I just did it and got the wrong answer for another hour of debugging because I overflowed an integer lmao but finally working

Jump in the discussion.

No email address required.

This started as a recursive solution but I ended up unwinding it. I don't know how people can solve this shit within minutes

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

Jump in the discussion.

No email address required.

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

Part 1 is just a simply brute force with recursion. For part 2 my first attempt was to just store the results in some cache and it immediately worked.

So just a generic use brute force then do dp problem

Jump in the discussion.

No email address required.

am I being dumb and missing an easier "correct" way to do it, or am I right to keep riffling through this constraint solver library's documentation?

Jump in the discussion.

No email address required.

I did part one with regex, looked at part 2 and went to bed.

:marseygiveup:

Jump in the discussion.

No email address required.

Recursion is a harsh mistress

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

Jump in the discussion.

No email address required.

⎕PP←20
s v←↓⍉↑' '(≠⊆⊢)¨⊃⎕NGET'12.in'1 ⋄ v←⍎¨v ⋄ ca←⍬ ⋄ cv←⍬
s2←{¯1↓(5+5×≢⍵)⍴⍵,'?'}¨s ⋄ v2←((5×≢)⍴⊢)¨v
f←{
    S←≢⍺ ⋄ l e←1(↑,⍥⊂↓)⍵ ⋄ n←⍺↓⍨u←¯1×(0<≢e)×(≢e)++/e
    (|u)>≢⍺:0
    i←⍸(l\1)⍷'.'≠n ⋄ b1 b2←(1∘↑,¯1∘↑)⍸'#'=n ⋄ t←~∨/'#'=n
    m←∊⍺∘{((S<l+⍵)∨'#'≠⍺⊃⍨⌊/S (l+⍵))∧(⍵=1)∨'#'≠⍺⊃⍨⌈/1 (⍵-1)}¨i
    i←(i≤⍺⍳'#')/i←m/i
    0≡≢e:≢(∊{(~∨/'#'=n)∨(b2<l+⍵)∧(b1≥⍵)}¨i)/i
    0≡≢i:0
    +/g∘e¨↓∘⍺¨l+i
}
g←{i←⊂⍺ ⍵ ⋄ x←ca⍳i ⋄ x≤≢ca:x⊃cv ⋄ o←⍺ f ⍵ ⋄ ca⊢←ca,i ⋄ cv⊢←cv,o ⋄ o}
h←{ca⊢←⍬ ⋄ cv⊢←⍬ ⋄ ⍺ g ⍵}
⎕←+/s h¨v
⎕←+/s2 h¨v2

Runtime: 7.35 seconds

:#marseyletsfuckinggo2:

Jump in the discussion.

No email address required.

Bit of a late entry. I would have saved a lot of time if I remembered memoization sooner :marseycry:

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

Jump in the discussion.

No email address required.

tfw the memoization technique was easy enough to infer but I got stuck for hours because I forgot to change an int to a long :marseydoomer:

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

Jump in the discussion.

No email address required.

I did the exact same thing this morning dw

Jump in the discussion.

No email address required.

this sounds like it's a math formula problem inputting available #x remaining and #n1#n2.. not so much a spacial one the problem suggests

too dumb for this, SKIP

Jump in the discussion.

No email address required.

use memoziation friend

literally

@funccowtools.cache

and ur done

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.