[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: buttons-pushing.gif (763 KB, 640x480)
763 KB
763 KB GIF
>Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like. People use them as a speed contest, interview prep, company training, university coursework, practice problems, or to challenge each other.
https://adventofcode.com/

/g/ leaderboard join code:
796940-44255af5
anonymous-only leaderboard:
383378-dd1e2041

previous thread: >>103588803
>>
File: solve.png (1.18 MB, 5546x5532)
1.18 MB
1.18 MB PNG
idiomatic Rust solution
solves >>103595105 in 3.1ms
>>
someone tell me what part 2 is so i can know if i should just be filtered now or actually try to finish part 1
>>
>>103596231
if your broot haven't finished for part1, you definitely don't have enough time to broot part2
>>
Just get your stars edition:
https://godbolt.org/z/GTM3fTfvP

Ξ = "029A 980A 179A 456A 379A".split()
from functools import cache
from random import random
@cache
def ϡ(α, ω):
ε = β if (α in β and ω in β) else μ
δ = ε[ω] - ε[α]; ζ, Ƶ = int(δ.real), int(δ.imag)
ɤ, ψ = ("^" * -Ƶ) + ("v" * Ƶ), ("<" * -ζ) + (">" * ζ)
if ε[" "] == ε[α] + Ƶ * 1j : return ψ + ɤ + "A"
if ε[" "] == ε[α] + ζ : return ɤ + ψ + "A"
return (ψ + ɤ if random() < .5 else ɤ + ψ) + "A"
@cache
def ϟ(γ, θ, σ = 0):
if θ == 0: return len(γ)
for ϙ, Δ in enumerate(γ): σ += ϟ(ϡ(γ[ϙ - 1], Δ), θ - 1)
return σ
def φ(γ, Ω):
ϡ.cache_clear(); ϟ.cache_clear()
return ϟ(γ, Ω) * int(γ[:-1])
def Θ(γ, Ω):
return min(φ(γ, Ω) for _ in range(666))
β = {'7': 0, '8': 1, '9': 2, '4': 1j, '5': 1 + 1j, '6':2 + 1j, '1': 2j,
'2': 1 + 2j, '3': 2 + 2j, ' ': 3j, '0': 1 + 3j, 'A':2 + 3j}
μ = {' ': 0, '^': 1, 'A': 2, '<': 1j, 'v': 1 + 1j, '>': 2 + 1j}
print(sum(Θ(γ, 2 + 1) for γ in Ξ)); print(sum(Θ(γ, 25 + 1) for γ in Ξ))
>>
>>103596241
not trying to brute just the getting my head around the logic is annoying so i am on the edge of filtered
>>
>>103596254
pro tip. you can brute part1.
>>
Just finished brute forcing part 1.

>part 2
Fuck
>>
>>103596254
you need to use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot enter a code on a keypad
hope this helped
>>
>>103596263
that sounds like part 1
>>
File: pressthebutton.png (555 KB, 500x747)
555 KB
555 KB PNG
I saw this funny meme on the previous thread.
Thoughts?
>>
>>103596245
What is j?
>>
>>103596264
oh sorry
part 2 is you need to use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot use a remote control that makes a robot enter a code on a keypad
hope this helped
>>
>>103596266
imaginary
>>
File: IMG_4088.gif (705 KB, 220x347)
705 KB
705 KB GIF
>part 2 solution gives the same answers as part 1 for appropriate n
>part 2 solution rejected when using real n
>>
>>103596273
alright im filtered
>>
>>103596275
what is number overflow
>>
Getting 68 instructions instead of 64 on the last example. Not sure how this works, I am using manhattan distance to generate instructions for movement.

So dx: 1 dy: -2 would be >vv etc
>>
>>103596259
what do you gain by doing this
>>
File: Untitled.png (64 KB, 500x440)
64 KB
64 KB PNG
>>103596265
>>
>>103596315
some optimal moves depends on moving up/down first before left/right (and other way around).
so just using or approach will not work
>>
File: 54b0ae0e.jpg (109 KB, 1280x722)
109 KB
109 KB JPG
>>103596078
woohoo, i managed to get it working by doing a series of min reduce and plus reduce on the lengths of the leafs in the tree.

> read part 2
> try to just change the iteration count to 25
> runs out of memory after 2 mins, not even solving a single code
> mfw
>>
>>103596354
i sort of understand this part and also sort of dont
because doesnt it have to travel to A again afterwards anyway?
>>
>>103596281
pythonchads need not concern ourselves with such human weaknesses
>>
>>103596362
you need over 70GiB of RAM to broot it
>>
>>103596315
My keypad moves for 379A are:


^A^^<<A>>AvvvA


Which generates direction robot moves

<A>A<AAv<AA^>>AvAA^Av<AAA^>A


Which requires human instructions

v<<A^>>AvA^Av<<A^>>AAv<A<A^>>AA<Av>AA^Av<A^>AA<A>Av<A<A^>>AAA<Av>A^A


But this is 68 instructions instead of 64

I am not sure how Manhattan distance does not give minimum answer but I guess I will just have to manually go through my code and the example
>>
>>103596365
sure. but for <<v and <v<. you need to end on A. but in the second sequence you 'move' more.
>>
>>103596362
try and break the problem down. what do you need from the first direction pad sequence to generate the next direction pad sequence.
does it matter what the actual 'order' is?
You only need the final length NOT order.
That might be a hint to a previous puzzle we did.
>>
>>103596375
there’s a small gotcha in the problem statement, look again
>>
>solve 029A example
>get command sequence of 168
wait. I don't have to solve my own dirpad, I only need the last robot. Length of 68
esl'd once again.
however I still get incorrect length for 379A example

string sequence = directional(directional(numeric(input)));
>>
File: 1691547324318.png (29 KB, 839x121)
29 KB
29 KB PNG
Fucking finally
>>
>>103596375
>I am not sure how Manhattan distance does not give minimum answer

note. you CANNOT move 'over' the empty spaces. so thats a catch.
and even if you use the correct number of left/right and up/down moves. the ORDER of them results in more or less moves in the later layer.
>>
>>103596399
Ouch, did not think about the second order effects, thanks
>>
File: 1660489088820.png (1.17 MB, 1430x6538)
1.17 MB
1.17 MB PNG
>>103596393
I am not washing this shit, I hate it.
>>
>>103596399
>the ORDER of them results in more or less moves in the later layer
yeah this makes sense
better to go >>^^ instead of >^>^, the next layer will be able to go AA
>>
>>103596407
correct.
>>
File: lut_lul.png (528 KB, 715x6069)
528 KB
528 KB PNG
LUT based solution.
there is not even a resemblance to the initial problem anymore...
bigboy takes 2ms (1.8 of which are input encoding).
once parsed it handles all codes simulatenously.
so the actual computation is independent of number of lines
>>
>>103596406
Looks similar to what I am thinking for mine, but I kinda hate the idea of even starting the memoization portion.
>>
File: 1721159603588408.png (691 KB, 1646x2973)
691 KB
691 KB PNG
So what's the canonical solution? I assume everything except the first few layers just tries to minimize the number of turns, but that seemed rather finicky so I used recursive shortest-path searches instead. Am I stupid?
>>
>>103596442
what is happening here sir?
>>
>>103596442
you DID NOT write that by hand
>>
>>103596463
>>103596466
try reading, dumb retards
>>
File: 14751492861.jpg (85 KB, 960x720)
85 KB
85 KB JPG
>>103596224
Are you guys SERIOUSLY solving this shit by hand?
Just plug it into AI like everyone else lmao
>>
>>103596486
Can your ai solve today's puzzle?
>>
>>103596486
this is bait. don't engage.
>>
>>103596486
It took over an hour for the leaderboard to fill today.
AI got wrecked.
>>
>>103596470
sorry i cant read
>>
>>103596375
^A^^<<A>>AvvvA

<A>A<AAv<AA>>^AvAA^Av<AAA>^A

v<<A>>^AvA^Av<<A>>^AAv<A<A>>^AAvAA<^A>Av<A>^AA<A>Av<A<A>>^AAAvA<^A>A

aAAAAAAAAAAaaaaaaaa
>>
>>103596486
All the high ranked people on the leader board are using AI. Everyone knows that.
>>
File: 1728706332670274.jpg (82 KB, 714x771)
82 KB
82 KB JPG
>>103596517
>>
AvAvAvAvAvA
>>
>>103596517
>>103596375
In your initial moves for 379A, you go up before going left (^^<<). Try going left before going up (<<^^).
>>
>>103596442
>>103596463
>>103596466
no a python script did.
as stated in >>103596037 I solved for all moves and there was a depth independent best move sequence for each.
each input is a sequence of moves and can be replaced by a sequence of moves.
giving each coordinate "0123456789A<^>v" an index each moves can be encoded as a number below 256. (index zero is a placeholder that means invalid transition)
since only the moves matter their order does not (we already encode from and to in the move)
=> each sequence can be encoded as a vector of 256 entries (count of moves/transitions)
then we just iterate the optimal replacement procedure.
funny thing, since the whole procedure is linear (basically matrix multiplication) we can just multiply each initial password by its numeric part and only need to solve once for all inputs combined.

this is not even close to optimized.
this solution could literally solve for billions of depths (using smart matrix powers) mod some number of course to prevent overflow.
>>
>>103596542
ty
i think i see what you getting at
>>
>>103596536
I solved it by code generation and manually fixing the few places where I broke the rules
>>
>>103596536
when encoding numerical transitions I chose to do the vertical axis first to avoid going over the illegal field in bottom left corner
I'll rewrite this
>>
im sorry eric for thinking you were gonna give me another shitty puzzle today
you can rape me instead
>>
>>103596661
almost quads of truth
>>
>>103596661
checked. and you should hope he use lube ( he has a big dong)
>>
Does anyone have the gold answer for the example?
I want to know what I am shooting for.
>>
>Day 22 (AoC++)
>You are given a list of picture frames of various sizes (your puzzle input)
>Place them on a wall minimizing gaps
>What is the smallest area in square feet that they occupy
>>
>>103596692
154115708116294
>>
>>103596697
> you have to place the picture frames in such a way to construct an optimal maze.
> solve this maze
>>
someone tell me if i am on the right track here
can i actually split this into small pieces? e.g. for code 029A, can i calculate for example
min length to go from A to 0 +
min length from 0 to 2 +
min from 2 to 9 +
min from 9 to A
and the same for sub calcs, thus caching them
>>
>>103596723
on the right track.
and yes, you dont care about the exact sequence, just the length.
>>
This is basically day 11 Plutonian Pebbles 2.
>>
>>103596723
Yes, because once you reached a button, you need to press A, thus resetting the position of the button pressing robot.
>>
>>103596703
Thank you.
>>
File: bqn.png (153 KB, 885x1277)
153 KB
153 KB PNG
long BQN
+ called part 2, instantly got that star by changing a number >>103593693
+ still did BFS in the end
+ PathTo is basically my complete first attempt
+ using my _memo 1-modifier again
- is this even BQN anymore? I gave up.
>>
>>103596838
nonidiomatic BQN solution
>>
>too high
555-come-on-now
>>
>>103596851
use shorter button press sequences
>>
>>103596865
sounds reasonable
I'll write an executor first, just to verify if my sequences are actually correct.
>>
File: rikka-smoke-cry.jpg (68 KB, 600x600)
68 KB
68 KB JPG
>>103596362
> rewrote BFS to memoized DFS
> works on example
> try to submit on input
> "That's not the right answer"
> realize i submitted the example input by mistake
> try again on actual input this time
> "Both parts of this puzzle are complete! They provide two gold stars: **"
>>
>>103596920
hot shit. well done!
>>
File: 1734657842853151.jpg (18 KB, 730x400)
18 KB
18 KB JPG
>>103596771
It's Tower of Hanoi with keypads.
>>
I can't rewrite my bfs to a dfs ive been trying for hours
>>
File: aoc24_21.png (527 KB, 818x3459)
527 KB
527 KB PNG
Good puzzle I was puzzled
>>
>>103596984
keep the bfs, but wrap it in a dfs to select the shorter paths
>>
>>103596993
I have literally no idea what you mean by this.
>>
File: calendar.jpg (3.74 MB, 7964x4044)
3.74 MB
3.74 MB JPG
>>
>>103597028
you start if bfs, then you just count down the items in your queue
>>
>day 25
>the elves would like to know if their program (your puzzle input) halts
>>
Gold: 1.4721460335923205e+45

there may be an issue with my program
>>
What the fuck are you niggers talking about? I have literally zero path finding algo in my code for today. No dfs, no bfs.
>>
>>103597065
post code
>>
>>103597065
we're talking about gay sex
lube or no lube
>>
>can take 2 different paths to get from key A to key B
>best path can change depending on depth
>except thats actually not true because some anons have hardcoded it 1:1
EXPLAIN THIS NOW
>>
>>103597065
>no code posted
filtered
>>
>>103597104
You must struggle with AOC if you have that low reading comprehension. There is NO key B
>>
>>103597104
i dont even know anymore
i overthought the problem too much and now nothing makes sense
its over
>>
>>103597141
I meant from any key to any other key
>>
>>103597104
see >>103596037
>>103597065
>not brute force search
>not DP cached function search
did you multiply your completely wrong answer by a magic number that turns it into the right one for your input, after confirming with someone else's program?
did you use one of your AoC++ puzzle-skips?
>>
>>103597148
sigh. There is no 'any' or 'other' key.
There are only 0,1,2,3,4,5,6,7,8,9,A,<,>,^,v keys
>>
>>103597149
how is this possible when I needed to consider both options to get a correct part 1
>>
hahaahahahaha

(numb)ers

you're being numbed

dumbass
>>
>>103597160
you had to consider all the options to pick the shorter one because you didn't know which would be shorter.
that your code asked the question doesn't mean the answer isn't always the same.
>>
File: 2.jpg (396 KB, 1280x720)
396 KB
396 KB JPG
>>
>wall of text
wtf did i just read
>>
>>103597065
Did you write any code today?
>>
File: img-2024-12-21-15-26-09.png (1.09 MB, 6016x2060)
1.09 MB
1.09 MB PNG
finally, another hard puzzle. hopefully his continues for the last 4 days
>>
>>103597170
How do people solve it without knowing this?
Right now i am trying to solve a recursive tree with over 2^25 branches and memoization cant help as depth matters. Do I have to find the key insight that depth doesnt matter and you always choose the same branch every time? Because it doesn't seem like everyone is doing that.
>>
>>103597104
moving the robot arm from 3 to 7 requires four key presses. let's take a look at two sequences
^^<<

and
<<^^


first is encoded as
<AAv<AA

second one as
v<<AA>^AA


at the beginning of each button press sequence the arm is over the A button
prefer using keys closer to A first. this will avoid additional trips from the key itself to A button in the next layer
>>
>>103597200
memoize {from-button, to-button, depth} = len
>>
>spend 3 hours solving the problem
>have now spent over 6 hours trying to wash my code
>>
>>103597218
if I do this it doesn't reduce the complexity at all because when it hits 0 len it doesn't know what branch to choose without going up a depth and checking.
>>
>>103597104
>Gold gives too high result
>Change the paths until minimum
>Stars received on both my accounts
See ya losers!
>>
A
A -> []
v -> [v<, <v]
< -> [v<<, <v<]
^ -> [<]
> -> [v]
v
A -> [^>, >^]
v -> []
< -> [<]
^ -> [^]
> -> [>]
<
A -> [>^>, >>^]
v -> [>]
< -> []
^ -> [>^]
> -> [>>]
^
A -> [>]
v -> [v]
< -> [v<]
^ -> []
> -> [v>, >v]
>
A -> [^]
v -> [<]
< -> [<<]
^ -> [^<, <^]
> -> []
>>
>>103597207
>prefer using keys closer to A first
Holy fuck I am free.
>>
>>103597225
you dont hit zero lenth, because going from and to the same key has length 1. You need to hit 'A'.
You 'expand' each 'from' 'to' pair to a list of button moves, then for each of those button moves you compute each from and to pairs. get new lists, compute, etc.
each time you decrease your depth from 24, to 23, to 22....until the base case depth 0.
>>
File: shoot_2024-12-21_09:34:36.png (1.6 MB, 1785x8785)
1.6 MB
1.6 MB PNG
I don't even know. Get me out of here.
>>
>>103597200
give the robot a number and use that as part of the key in your cache
>>103596838 is written in classical Egyptian but Brute is memoized by the (code,robot) parameters
PathTo only uses a temporary hashtable for pathfinding
you don't need a special insight at all for this problem, the only wrench is that 'equivalent' costs for a single robot aren't equivalent for the whole problem
that BQN gets both answers in 20ms
>>
File: xarbon.png (22 KB, 1204x676)
22 KB
22 KB PNG
>>103597075
There you go
>inb4 nooo it's actually is dfs because if you consider all the parameters to make up a node and consider those which get called neighbouring th-ACK
By this logic every recursive function is dfs
>>
If the number pad and directional pad didn't have exactly one empty space you had to avoid, my entire program would fail.
>>
>>103597309
>xolatile
kill yourself
>>
>>103597309
>do a dfs
>don't call it a dfs to make yourself feel special
>>
>>103597311
just hard code all the transitions like I did. I manually avoided the holes
>>
File: eric.png (300 KB, 400x400)
300 KB
300 KB PNG
If you complained about this year being too easy. APOLOGIZE.
>>
>>103597340
> there is a hole to the left
> I avoided it by manually pathing around it
> easy
>>
>>103597344
still too easy
>>
>>103597309
sum([solve(nkpm[s[j-1]][0],nkpm[s[j-1]][1],nkpm[s[j]][0],nkpm[s[j]][1],y,1) for j in range(1,len(s))])*n

idiomatic Python?
>>
>>103597344
Filter us more Eric! Too many are still through! Millions must die!!!
>>
>>103597332
It's called top-down dynamic programming and no, not every recursive function is dfs.
And how do you even do this with bfs?
>>103597313
And mentions him again. He must be extremely based to live in everyone's head in this board rent free. I'm not him, he even mentioned in the first aoc thread this year that he never participates just lurks here. Feel free to look it up.
>>
>>103596224
>but /g/ blows his experiments to smithereens, there is gloom and doom while things go boom in Erics lab!
>>
>>103597367
this is bottom up DP today?
>>
>>103597367
>speaking of yourself in the third person
cringe
>>
>>103596986
this is mostly very clean-looking code, but
>rv = 0x7fffffffffffffff
you can add underscores and probably use https://pkg.odin-lang.org/base/builtin/#max
>>
>part 3
>actually, the numpad is formatted differently from what you thought
>it actually reads "123" on the top row, "456" on the second row, "789" on the third row, and "A0 " on the bottom row (the A is flipped to the other side).
>now solve part 2 again
based on how you implemented today's puzzle, how fast would you be able to solve this part 3?
>>
>>103597392
Delusional schizo.
>>103597386
Good idea, I'll rewrite it to that to btfo these dfs seething niggers.
>>
>>103597445
it's just a one line diff
>>
>>103597344
i will not apologize for him making me sit through dogshit for the past 20 days
>>
can someone spoonfeed me cool pics for calendar, days 19-21?
I wasn't able to keep up with threads.
>>
>>103597445
well. time to update my hardcoded transition table function.
give me 5 mins
>>
>>103597466
see >>103597036
>>
>>103597451
>Good idea, I'll rewrite it to that to btfo these dfs seething niggers.
if you are not meme'ing. cool I would like to see that
>>
>>103597466
here is a funny one for today
>>103596265
>>
>>103597469
you will be many things this lifetime a woman is not one of them
>>
>>103597445
I'll do you one better:
>The robot that enters in the numeric code actually specializes in installing keycaps on blank keypads.
>The numeric keypad is blank right now, but luckily, the robot has a full supply of keycaps already.
>You may now place any digit and the A anywhere on the 3x4 grid, so long as the buttons don't overlap. How should you place the digits and the A to result in the minimum score when there are 25 robots?
Could also extend it to the directional keypad as well.
>>
>>103597497
ywbmttlawinoot
>>
>>103597196
>extreme
should I give up already?
>>
>>103597439
>https://pkg.odin-lang.org/base/builtin/#max
Ah I was looking for something like that, thanks
>>
>>103597507
you have 14hours left. do NOT give up
>>
File: Capture.png (58 KB, 572x667)
58 KB
58 KB PNG
guys I was wrong. I honestly think now this might be a '10' now
>>
>>103597520
I don't see it. Can you circle it in red and add some arrows?
>>
File: Capture.png (89 KB, 592x820)
89 KB
89 KB PNG
>>103597525
i got you senpai
>>
File: D21_washed.png (1.12 MB, 2400x4618)
1.12 MB
1.12 MB PNG
Washed Kotlin.
>>
>>103597539
I SEE IT NOW TYSM
>>
I feel today's problem is like the blinking stones, except you just have to manually derive the transformation rules
>>
still couldn't find the 456A edge case
it might just be over
>>
File: heap-of-hanoi.jpg (158 KB, 1280x720)
158 KB
158 KB JPG
>>103596980
I never noticed how much this resembles a pile of shit
>>
>>103597630
have you ever seen shit like that in real life?
it's like manga meat.
>>
File: aoc.png (144 KB, 572x667)
144 KB
144 KB PNG
>>103597520
>>
>>103597647
dog poo can almost look like that
>>
>>103597674
holy! I did not expect eric to bring religion into this!
>>
>>103597647
do you also complain about hearts on valentines day?
>>
>An entire hour for the leaderboard to fill up
Why didn't you make top 100, Anon? You know you're filtered if it takes you over an hour to solve the daily puzzle, right?
>>
>>103597753
If today was presented at an interview only about 40 people on the planet would pass it (+-50min because people shittalk for like 10min before you start)

still sounds easy?
>>
File: image.png (600 KB, 992x787)
600 KB
600 KB PNG
my humble BQN solution for day 21.

golfed it down quite a bit. probably can be golfed further but i think i'm done for now.

today was pretty brutal. i was suspecting this may happen since the last 3 days were super easy and weekend was coming up. gonna play some osu! and relax now.
>>
>>103597753
post your time for today
>>
>>103596838
>>103597771
does it feel like you're the earth's most powerful wizard when using BQN and company? lisp people definitely paint their language like that but i've never seen anyone sincerely advocating for array programming languages
>>
Not even sure how to approach this one. I think I may be filtered. First time in years.
>>
File: day21_dot.png (448 KB, 968x5996)
448 KB
448 KB PNG
okay now day 21 is literally 2 dot products.
I think I am done now...>>103596442

takes 15 microseconds.

try it if you doubt it https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=40ded88f6c1b87191faaa8b77d973f43
>>
>>103598000
cniles are real quiet right now
>>
>>103597957
its like the blinking stones problem, except you dont get the transitions for each 'move' to 'move' transition. you have to work it out yourself
>>
>>103597914
> does it feel like you're the earth's most powerful wizard when using BQN and company?
personally, i think it's kind of retarded for anything real-world (though that could be bias from my end since i mostly deal with system software) but for aoc puzzles it's pretty cozy.

takes a while to get used to though, you have to try vastly different approaches compared to usual iterative algorithms. instead of designing your data-structures to fit the problem (hashmap, queue, heap etc) you need to reformulate the problem instead to fit into an array paradigm. how to do this is not often obvious and can require some creative/geometric thinking.

parsing and string operations are also massive pain in the ass when starting out.

> lisp people definitely paint their language like that
most people i've seen who treat lisp as an *actually* good language (rather than merely being a interesting/fun one) are heavily braindead.
>>
>>103597466
my version for today's problem
>>
>>103598089
>wednesday column is red forming a T
>tranny start with T
tranny calendar
>>
>>103598102
the T stands for Testosterone
tranny calendar is this way >>103597036
>>
File: file.png (483 KB, 2048x2466)
483 KB
483 KB PNG
>another day where I needed 7 hours to write a 4 loc DP function
my brain is just too small for recursion
>>
>>103598000
I kneel
>>
File: shocked.gif (2.68 MB, 498x345)
2.68 MB
2.68 MB GIF
>>103598000
>>
>example works
>real input gives incorrect solution
>try to fix it
>also break example code
fff
>>
>>103598239
what is overflow
>>
>>103598000
>"wow it literally just takes 15 picoseconds when i effectively hardcode the answer! :OOO"
>>
>>103598250
it's not "hardcoding the answer" if it works on all inputs including the bigboy
>>
>>103597914
if you want some hype, there are several strains of hype that you might like. Got some "notation as a tool of thought", got some stuff about mechanical sympathy and data-oriented design, even memory management. Even RAD with Lisp-like interactivity. Some real good hype is derived from Arthur Whitney: instead of getting reliable software from high-effort engineering practices or from lots of compiler guarantees, you can get it from shrinking programs to the point of actually being able to fit them in a human brain.
I wrote a bunch of aspirational stuff like this about J on New Year's day, 2020, and then got kinda distracted and still am very bad at array programming.
All of the hype applies equally to all array languages. BQN's distinctive for its modernization pass that makes it a lot less pointlessly weird and a lot more like more common languages (like having lexical scope, closures, mutable hash tables), while still making it deliberately weird with the thoughtful character set and restrained primitives and cleaned-up function trains and combinators. The BQN website sells it well if you read it through. I really like BQN and will be doing more with it, but not likely for a job.
It's fun. It's kept me in these threads when more grids and pathfinding in Zig might've burned me out.
>>
>>103598250
>t. coping cnile
>>
at least it was nontrivial.
thank you Eric sama.
>>
>>103596260
if you did the plutonian one, you can do this one nigga. it's same problem basically at that point. the hardest part is properly handling numpad (keep min) -> n * expand (keep min)
>>
>>103598000
based and idiomatic pilled.
>>
>>103598031
>who treat lisp as an *actually* good language
it is
>rather than merely being a interesting/fun one
it also is
>>
>>103598321
brain damage
>>
>>103598248
why would it overflow during LUT creation?
>>
>>103598260
bigboys are flexible in scaling while being inflexible in the description of the problem itself. In the real world you can more often cheat on scaling than you can be inflexible with changes in requirements. Your not-hardcoded solution would be thrown away when Manager Eric comes back and says: actually we don't give a shit about small changes in length, but we want the robots to play ads.
>>
>>103598391
>but what if the problem changes?
>t. seething cnile
>>
>>103598000
So there is a tabular dp for this. Based as hell? How fast is it with a proper matmul library?
>>
I don't get the second order cost, I just can't visualize it.
>>
>>103598621
conceptualize the third order cost and then just devirtualize it to a second order cost.
>>
Where is the Eric apology form?
>>
File: im-1734801215019.png (47 KB, 518x932)
47 KB
47 KB PNG
wew
>>
>>103598637
babbys first dp
why should i apologize
its still stale and uncreative
>>
>>103598000
This is just solving the main part of the problem compile time.

>>103598391
This is just retarded cope.
>>
>>103598637
Hard puzzle does not equate quality
It's still boring dogshit
If anything he owes me a apology for wasting my time
>>
>>103598679
>>103598760
Ungrateful niggers why don't you try making puzzles.
>>
>>103598754
no, not compile time. I used a messy python script that took about 30 seconds to do that 256x256 matrix power. you gotta go slow to go fast
>>
File: youfuckinmakeitthen.png (588 KB, 547x794)
588 KB
588 KB PNG
>>103598679
>>103598760
>>
>>103598783
How does Eric's cock taste
>>
>>103598792
And when you have that fucking matrix hardcoded you have a compile time solution. Well, except for the compilation part I guess.
>>
File: 1716518572305068.jpg (110 KB, 368x468)
110 KB
110 KB JPG
Guys, I'm fucking retarded.
>>
>>103598837
forgiven
>>
>>103598837
true
>>
>>103598837
It's amazing during AoC how I go from feeling like a genius savant to a retarded caveman from day to day.

Today is a retard day.
>>
File: Day21.png (399 KB, 1277x3302)
399 KB
399 KB PNG
Where the CSharters at?
>>
File: tomorrowunhappy.jpg (139 KB, 462x476)
139 KB
139 KB JPG
>>103598837
>>
>>103598887
80-column rule
>>
>>103598805
I would do a better job if Eric gave me ownership
>>
>>103598506
right now the runtime is 90% parsing. I do not think that for the (now 121 entry) vec vec dotproduct any speedup would even be noticable.
When not "hardcoding" the depth/number of robots, the first step could be done by a separate lut, then you would only have to take 5x5 matrix powers. (number of keys on robot keypad)
with fast matrix power the limit of depth computable in 1 second is probably 2**(10**9) or sth absurd. (obv. there will be overflow)
>>
>fall asleep early last night
>wake up
>read puzzle
>have to wrangle a 2 year old all day
Yeah, it’s over. I will do it tonight after bedtime, but there is no way I am gonna have time to get under 24 hours on today’s puzzle. Oh well, it was a good run.
>>
File: 1733887359530571.png (629 KB, 822x744)
629 KB
629 KB PNG
Oh, what the fuck is this problem.

I should just become a stripper or something
>>
>>103599058
like blinking stones, but you just have to figure your the transitions between blinks yourself.
>>
fuck me
>>
I'm frustratingly close to making a breakthrough on this but I'm still off ever so slightly.
My approach is to generate all optimal transitions from one keypad position to another keypad position (that is, all transitions that would minimize the future number of keypresses) For example:
>029A
>[<A][^A][>^^A][vvvA]
>[v<<A][>>^A]...
>[<vA][<A][A]...
I'm not sure how to determine which transition is optimal though. The (really messy) approach I'm trying is to consider the transitions with the smallest Euclidean distance between steps and with the fewest button switches, but that's still making me consistently off by 2 on some of the sample inputs
>>
>>103599187
nice start, now think how you can use that like the blinking stone problem.
hint recursion + memoization
>>
>>103599058
Think about what you actually want to do.
>I want to move the final robot one step.
>For that, I need to move the robot before that one to a specific button.
>For that, I need to move the robot before that one to a specific button.
>...
Maybe that helps.
>>
my problem is i solved it without recursion, but rather a queue, so i can't memoize
>>
>>103599058
Yes, become anything else but a programmer.
You are extremely retarded, literally unable to think even on a basic level if you can't solve this babby's first dp problem.
And never post that disgusting netflix amerimutt tm goyslop shit image ever again.
>>
>>103599187
I started by hardcoding every possible transition, then culled the inefficient ones based on two factors. First, avoid dumb shit like ">v>v" in favor of ">>vv" or "vv>>". And secondly, chose the option that finishes closest to A, so "vv>>" is better than ">>vv" because it's only one move from > to A, but two moves from v to A.
>>
>>103599293
the subproblems are independent so you can just use a cache
>>
>>103599291
additionally I don't care about the sequence itself. only its length matters
>>
File: Adveent 2.png (410 KB, 1542x2686)
410 KB
410 KB PNG
>>103596224
Just finished part one of day 2. bit trickier than day one, but still fun.
>>
>>103599372
you’re like a tiny baby compared to after 21 days of flexing
Better get busy!
>>
>>103599382
lol just finished the semester, thought i try it but im a bit behind.
>>
File: xarbon.png (21 KB, 1588x532)
21 KB
21 KB PNG
>>103597479
>>103597386
>>103597332
>>103597075
>>103597139
>>103597193
Where's the DFS, niggers?
>>
>>103599420
You can catch up still this years only has a couple real grunky ones
>>
>>103597196
Interesting how LLMs haven't seemed to make a dent in the times yet.
>>
>>103599428
kys it looks like shit and it smells like cheese
>>
>>103599358
this seems most like a translation problem, where instead of worrying about the multiple levels of the bot you just need a dictionary for each set of arrows between each A toa single arrow. wouldnt matter how many keypads are between you and the numeric keypad, right?
>>
>>103599428
>stdin
you didn't solve it, xolatile
>>
>>103599441
filtered softwer shitter (((engineer)))
>>103599479
kek are you that same guy who spent 5 hours solving day 6?
>>
>>103599187
Holy shit I think I've got an idea. I should be starting my DP from the start (i.e. the controller the user is controlling) rather than the goal (the final keypad)
Let Ti(a,b) be the cost of moving robot i from state A to state B. T0(a,b) = 1 as that's the controller we're using and thus pressing any button is instantaneous. For Ti, we consider all paths A=A1, A2, ... Ak = B on the controller and minimize T(i-1)(A1, A2) + T(i-1)(A2, A3) + ... + T(i-1)(A(k-1), Ak). Concretely, T1('A', 'v') = min(T0('A', '<') + T0('<', 'v'), T0('A', 'v') + T0('v', '<')).
Some additional logic might be needed to handle the final keypad but that one shouldn't be too complicated I imagine.
>>
>part1 correct on example and normal input
>part2 gives me 17745619402636 for example input
that's incorrect, right? it should be >>103596703
>>
>>103599570
Yep
>>
I'm wasting all my weekend on this shit. Please go back to the easy problems.
>>
>>103597207
>write a dijkstra to get the optimal path for each number transition so i don't have hardcode it
>don't understand why I don't get 64 for the last example
>see that unwritted rule
Fuck you eric
>>
File: file.png (24 KB, 856x133)
24 KB
24 KB PNG
>>103599535
We are so fucking back
>>
>>103596224
wew lad
took me some time to get my hardcoded
directions working, lol

>>103597207
>prefer using keys closer to A first
i'm doing the opposite
it seems it doesn't matter as long as your approach (closest first or furthest first) is consistent accross all your transitions
>>
File: 1721361683369770.png (22 KB, 510x329)
22 KB
22 KB PNG
>>103598000
>>103598968
But does it work on a wideboy?
https://files.catbox.moe/3ox9ji.txt
>>
>>103599449
I wrote a simple function like
def enter_code(code):
output = ""
cur = "A"
for c in code:
output = transition[cur][c]
cur = c
return output


The problem is doing that nested 25 layers deep explodes quickly, so you'll need DP for part 2.
>>
>>103599622
>use part2 memoization code to compute part1 results
>correct for example and normal input
huh. I guess some of the generated sequence are incorrect
>>
Can I really memoize "Moving the Nth keypad from X,Y to Z,W" ? Don't the states of all the other keypads change?
>>
>>103599868
no because the robot below must be at "A" for you to press a key
>>
File: lut.png (481 KB, 1692x2584)
481 KB
481 KB PNG
>>103598000
>u128
>arrays of size 256
what are you doing, my transition matrix is only 65x65
>>
>>103600037
and where did those magical numbers come from?
>>
>>103599674
Okay. Literally just started changing random things until it worked out of nowhere. I'm glad it's over.
>>
>>103596389
>You only need the final length NOT order.
AAAAAGGGHHHH ERIC YOU NIGGER I WASTED SO MUCH TIME BUILDING A LOOKUP TABLE TO ACCOUNT FOR THAT FUCKING KEYPAD SHAPE
>>
>>103600199
how many hours did it take to type
        {
(0, 0): 7,
(1, 0): 8,
(2, 0): 9,
(0, 1): 4,
(1, 1): 5,
(2, 1): 6,
(0, 2): 1,
(1, 2): 2,
(2, 2): 3,
(1, 3): 0,
(2, 3): 'A',
}
>>
>>103600037
I hadn't reduced the lut yet. I just encoded all 15 Symbols +0 as placeholder, so transitions were 16*16 possibilities. I reduced it to 11*11 (A0123456789).I think you did seperate LUTs for step 1 and then the others. Mine was combined so larger. aren't there just 25 transitions after the initial one? since there are 5 positions?
>>
>>103600037
I don't understand what you guys are doing or why
If moving vertically first would cross the blank square, move horizontally then vertically
If moving horizontally first would cross the blank square, move vertically then horizontally
Otherwise, use the minimum of two stated combinations
with memoization my program averages 0.01 seconds
>>
>>103599792
when you replace the u128 with big ints (bnum) then yes
 
1911227629533568772309......97723406348998036872557282001211274
2382135687548606935241......22473794413308636125845857300750758
>>
File: 1731055506356415.png (6 KB, 690x34)
6 KB
6 KB PNG
don't give up, anon!
>>
File: python_ass.png (750 KB, 2152x4124)
750 KB
750 KB PNG
>>103600117
>>103600236
Here is my *somewhat* washed, recursive python solution that I used to create the matrices/vectors. Hopefully my code explains itself.
>>
What’s the points of doing the advent of code, if you’ll be filtered by o3 anyway???
>>
Now with 100% less coin tossing and 100% more soup:
https://godbolt.org/z/7M1x6qaqP
https://youtu.be/irA4-umtPMA

Ξ = "029A 980A 179A 456A 379A".split()
from functools import cache
def Ȣ(α, ω, ε):
m = Δ if α in Δ else Γ
δ = m[ω] - m[α]; r, i = int(δ.real), int(δ.imag)
Φ, θ = ('^' * -i) + ('v' * i), ('<' * -r) + ('>' * r)
if m[α] + r == m[' '] : return Φ + θ + 'O'
if m[α] + i * 1j == m[' '] : return θ + Φ + 'O'
return (θ + Φ if ε else Φ + θ) + 'O'
def ψ(α, ω, Ϫ):
return min(ϟ(Ȣ(α, ω, False), Ϫ), ϟ(Ȣ(α, ω, True), Ϫ))
@cache
def ϟ(ξ, Ϫ):
if Ϫ == 0: return len(ξ)
return sum(ψ(ξ[i - 1], o, Ϫ - 1) for i, o in enumerate(ξ))
def Ʊ(Ϫ):
return sum(ϟ(ξ, Ϫ) * int(ξ[:-1]) for ξ in Ξ)
Γ = {'7': 0, '8': 1, '9': 2, '4': 1j, '5': 1 + 1j, '6':2 + 1j,
'1': 2j, '2': 1 + 2j, '3': 2 + 2j, ' ': 3j, '0': 1 + 3j, 'A':2 + 3j}
Δ = {' ': 0, '^': 1, 'O': 2, '<': 1j, 'v': 1 + 1j, '>': 2 + 1j}
print(Ʊ(2 + 1), Ʊ(25 + 1))
>>
>>103600530
>Φ, θ = ('^' * -i) + ('v' * i), ('<' * -r) + ('>' * r)
clever, should've thought of that. I did bfs like a cheeseclown.
>>
>>103600530
fixed https://pastebin.com/DeF2MJTZ
>>
>>103599058
keep posting that image, I get stiff whenever I see it
>>
I can't get part2 to work at all. I even tried all* permutations of up/down/left/right
* by all I mean full sweep, no zigzagging. with the excecption of a few hard coded patterns of going around the blank
24 * 24 sequences and it's still wrong
I feel like taking a shit right now, maybe it'll clear up my mind
>>
This was a fantastic problem, one of the best
>>
>>103599437
LLMs had no hope on this
I couldn't even get a correct refactoring of my top-down recursive solution to bottom-up iterative
>>
File: Ʊ.jpg (400 KB, 1920x1080)
400 KB
400 KB JPG
Removed unnecessary stuff:
Ƶ = "029A 980A 179A 456A 379A".split()
from functools import cache
def ψ(α, ω, Ϫ):
m = Δ if α in Δ else Γ
δ = m[ω] - m[α]; r, i = int(δ.real), int(δ.imag)
Φ, θ = '^' * -i + 'v' * i, '<' * -r + '>' * r
if 0 == m[α] + r: return ϟ(Φ + θ + 'U', Ϫ)
if 0 == m[α] + i * 1j: return ϟ(θ + Φ + 'U', Ϫ)
return min(ϟ(θ + Φ + 'U', Ϫ), ϟ(Φ + θ + 'U', Ϫ))
@cache
def ϟ(σ, Ϫ):
if 0 == Ϫ: return len(σ)
return sum(ψ(σ[i - 1], o, Ϫ - 1) for i, o in enumerate(σ))
def Ʊ(Ϫ):
return sum(ϟ(σ, Ϫ) * int(σ[:-1]) for σ in Ƶ)
Γ = {'7': -3j, '8': 1 - 3j, '9': 2 - 3j, '4': -2j, '5': 1 - 2j, '6': 2 - 2j,
'1': -1j, '2': 1 - 1j, '3': 2 - 1j, '0': 1, 'A': 2}
Δ = {'^': 1, 'U': 2, '<': 1j, 'v': 1 + 1j, '>': 2 + 1j}
print(Ʊ(2 + 1), Ʊ(25 + 1))

https://godbolt.org/z/hje5r3zMM
>>
File: xarbon.png (22 KB, 1780x516)
22 KB
22 KB PNG
compact python
Final washed, elegant version
zero functions, only loops
(130ms for both parts)
>>
File: file.png (359 KB, 1468x2248)
359 KB
359 KB PNG
I really don't get what's wrong here
029A: v<A<AA>>^AvAA^<A>Av<<A>>^AvA^Av<A>^A<Av<A>>^AAvA^Av<A<A>>^AAAvA^<A>A
980A: v<<A>>^AAAvA^Av<A<AA>>^AvAA^<A>Av<A<A>>^AAAvA^<A>Av<A>^A<A>A
179A: v<<A>>^Av<A<A>>^AAvAA^<A>Av<<A>>^AAvA^Av<A>^AA<A>Av<A<A>>^AAAvA^<A>A
456A: v<<A>>^AAv<A<A>>^AAvAA^<A>Av<A>^A<A>Av<A>^A<A>Av<A<A>>^AAvA^<A>A
379A: v<<A>>^AvA^Av<<A>>^AAv<A<A>>^AAvAA^<A>Av<A>^AA<A>Av<A<A>>^AAAvA^<A>A

They all seem to be correct except the last one
>>
>>103601323
Look at: >>103597207
>>
Is part 2 just “add more robots between you and the number pad”? I have written an algorithm on paper while I am away from my PC that will work but won’t scale if that is Part 2.
>>
>>103601476
Yeah, part 2 is 25 robots instead of 2.
>>
>>103601476
No, part 2 is that now you can press A any time for all robots.
>>103601524
kek
>>
>>103601476
Part 2 breaks half of your navigation buttons, but you can now loop back if you are going out of bounds.
>>
>>103601476
Part 2 has 25 robots and they walk between rooms changing order
>>
bros this problem sucks. 1% thinking about how to map inputs 99% dealing with awkward edge cases. Take out the missing corner and shortest code requirement and put it in week 1.
>>
>>103601476
Part 2 you have to rescue the historian who got sucked into space when you opened a depressurised door
>>
>>103601680
>edge cases
doinitwrong
>>
Yeah, I don't understand the complaint about edge cases
>>
>>103601680
instantly worked for me on first run
you're just a shitty programmer
>>
Just starting part four, my plan for now is to make a 2d array, than check all 8 directions of each cell for matches, with extra code for thee edges of the grid.
>>
>>103601680
>this problem sucks because it is harder than a week 1 problem and it's not week 1
>>
>>103601680
My solution doesn't check for any edgecases, just check every possible shortest path with memoization.
>>
>>103601775
You didn't solve it
>>
>>103601797
I literally did, it works in 4ms, so it is not brooooting.
>>
if you're doing DFS/BFS you got filtered
>>
>>103597207
I solved both parts, and know different movements somehow expand differently in deeper layers, but your example is very poor: after moving from 3 to 7, you still need to hit the A button on the arrow path to punch the 7, which makes both sequences equal length again, because the A button is farther away in the first:

first is encoded as
<AAv<AA>>^A

the second as
v<<AA>^AA>A


I couldn't find an example myself.
>>
>>103601848
based
>>
File: tiresome.png (414 KB, 460x434)
414 KB
414 KB PNG
i think this is it for me lads i can't for the life of me figure it out
>>
>>103601945
Don't worry. You're obviously a gay nigger and there are plenty of DEI positions for you in FAANG
>>
>>103601848
Ha I used dijkstra
Dijkstrafags can’t stop winning in 2024
>>
>>103601945
Are you stuck at part a or b?
>>
>>103601974
That's bfs.
>>
Man I feel so stupid. I was having so much trouble with part 2 until I realize that it is much easier if you count down instead. Literally all you need to do. Worked like a charm.
>>
>>103601975
a.....
>>
>>103601945
See >>103602000
>>
>>103602000
>>>/b/
>>
Where's the TGF anon?
>>
>>103602018
Try it before you deny it
>>
File: 21.jpg (2.38 MB, 3515x9681)
2.38 MB
2.38 MB JPG
readable rust solution
>>103601975
nigga it's parts 1 and 2
>>
File: 1690189092881849.jpg (91 KB, 530x960)
91 KB
91 KB JPG
>>103601988
did I say dijkstra? I meant Floyd warshall
Did I say Floyd warshall? I meant kruskal
Did I say kruskal? I meant bellman ford
Get on my level pytoddler
>>
Is there a big brain way to know which direction to move in first, or do you have to broot it?

All I can think of is zigzagging (yx, xy, yx, xy) but how do you deal with each case of zeros where you only save a move when the zigzag falls the right way? And this is only one layer removed from the numpad, how does it affect higher layers?
>>
>>103601877
There are cases like that.
Before doing it right I just flipped a coin to choose vertical or horizontal, and trying several times with the same door sequence to choose the shortest. It only takes a fraction of a second, even with Python.
>>
>>103602034
I know all of these algorithms nigger, I do competitive programming and read CP3.
>>
>>103602046
I didn't do it this way, but I think some anons said if you prioritize the directions by distance from A it works
>>
>>103602128
It doesn't work for part 2 because it can't be generalized for several layers, at least not with a rule that simple.
>>
>>103602245
Did you actually try it? The optimal rules end up being the same for each layer.
>>
File: 5435b4.jpg (8 KB, 215x250)
8 KB
8 KB JPG
>can't write code until I have rigorous proof of shortest path
>"uhh try close to A it all works out in the end I think"

I'm literally too intelligent to solve this
>>
>>103602251
I gave up fast on that strategy. And as far as I have seeing, the solutions that work with that strategy use huge tables.
>>
>nigga it's parts 1 and 2
whoops sorry that was my internal naming convention.
>>
>>103602279
Just enumerate all possible paths and use the best, there are only a few and it's guaranteed correct.
>>
File: Day21.png (564 KB, 1251x4979)
564 KB
564 KB PNG
Absolutely horrific unwashed C#. Barely scraped through today, probably getting filtered tomorrow.
>>
>>103602000
but does it work for 0-length moves?
>>
>>103602279
Intelligence is by definition measures how efficiently can you accomplish some goal
If you're unable to do it you're a filtered dumb nigger
>>
I seem to recall there was a problem last year that involved pressing buttons hundreds of trillions of times to get some simple device working. This seems to be a common flaw with elven machinery.
>>
>>103602303
>9 new posts
Yeah, it does! Sort of. You just check for zero length moves with a regex first and filter them out.
>>
>>103602294
>2 paths per move
>16 path per code per layer
>16^3 paths per code for part 1
>16^26 paths per code for part 2
>"just enumerate all possible paths"

And no, you can't prune path before the end layer unless you have a rigorous proof that doing so can't lead to a longer route in a later layer.

>>103602332
Every intellectual achievement in human history is thanks to people like me who ask why, because we need to understand what's happening on a deeper level. You wouldn't get it. You're the retard who sits in Africa for a million years and never invents fire because "bash monkey with stick just werks".
>>
>>103601945
ok i can't i'm going to sleep see you next year if there is a next year gn
>>
>>103602296
>probably getting filtered tomorrow
this is SURELY erica's hardest 2024 puzzle.......
[spoiler]hold me anons[/spoiler]
>>
>Silver: 126384
>Gold: 91028765362212
I'm not going to make it.
>>
Question about yesterdays problem; i haven’t written anything yet, but i’m imagining the program would be something like this:

1.walk down tha path, noting each cell position
2. assign each cell position a number with which cell it is in the shortest path, starting from path length and counting to zero
3. for each cell, look at all cells within 2 cells of them and check if the number on those cells are 100 less the number on your current cell. if it is, it’s a good cheat.

is that a good starting point for this problem?
>>
>>103602296
No, i need my CShart broooos to finish
>>
I'm not going to say I'm filtered but I'm getting sick of rewriting my solution and I'm not getting any closer to solving it
>>
>have my solutions for silver
>break the top layer up into moves used to do each move in the middle layer
>recur up to another 24 layers adding and memoizing the lengths of the moves required to do the moves required to do the moves required to do the moves required to do the moves
>wrong answer
I'm gonna die.
>>
>>103602507
You don't need to recompute paths you already expanded for n times. It is basically day 11 again.
>>
File: 1704831240549202.jpg (180 KB, 1416x2048)
180 KB
180 KB JPG
>>103602507
>Every intellectual achievement in human history is thanks to people like me who ask why, because we need to understand what's happening on a deeper level
>gets filtered by dynamic programming 101
>>
>>103602652
Yes, but be ready to debug, since it's a maze problem.
>>
File: file.png (68 KB, 729x535)
68 KB
68 KB PNG
it's so over
>>
File: day21-mathematica.png (285 KB, 2799x2312)
285 KB
285 KB PNG
I really enjoyed that.
>>
>>103603046
Absolute destruction.
>>
>>103603046
Based Eric dabbing on IQlets
>>
I'm stuck at the point of wondering if I should completely rewrite my silver solution again, or keep tweaking my attempt at gold.
>>
>>103603046
Is this more or less of a bloodbath than elephant valves?
>>
File: day21-mathematica.png (235 KB, 1713x2341)
235 KB
235 KB PNG
>>103603190
He redeemed himself from the string of easy grid days. It takes some time to get an insight on how to get a handle on the problem, which is certainly something I couldn't do tired last night.

Also mild washing of >>103603073 without the style effect which deletes some symbols.
>>
>>103603233
If changing a 2 to a 25 in your silver solution doesn't solve gold, you're not approaching the problem correctly
>>
File: 1728225515900636.jpg (9 KB, 214x268)
9 KB
9 KB JPG
>write a "solution"
>for the initial numpad iteration, have a specific order to prioritize directions in
>for the keypad iterations, have a different order
>keep getting 4/5 examples correct
>write a stupid thing to go through every single permutation of numpad/keypad direction sets (576 total) and reruns the whole program with those set
>none of them give me 5/5 examples correct
fuck you 379A and your 68 bullshit. is generating one layer at a time not the correct way?? I figure it's some bullshit like a nonoptimal one on layer 2 produces a more optimal on layer 3... every time you generate a combination are you supposed to check it against all combinations it generates and find the one that produces the smallest? but what if the problem persists 2 layers ahead or more? I don't know
>>
File: day21.png (88 KB, 856x806)
88 KB
88 KB PNG
BQN day 21

First day I really struggled with.
>>
>>103597914
>does it feel like you're the earth's most powerful wizard when using BQN and company?
BQN is the array magic of APL, the tacit programming magic of J, and the functional programming magic of Lisp all combined.
Yes, you feel extremely powerful.
>>
>>103603464
>array magic
in python this is just import numpy
>tacit programming magic, functional programming magic
in python this is just import functools
>>
>>103603360
You are definitely on the right track. The problem is that you're probably expanding too much at one time from one layer to the next.
>>
>>103603250
Unironically I think people who say stuff like this just got lucky.

The most reasonable heuristic is at every stage, you choose a sequence with the fewest contiguous groups. This works for 4/5 input but fails for 379A. So it's possible for an optimal (or at least joint optimal) outcome at one layer to produce a suboptimal outcome at a higher layer.

Nobody itt can give a solid answer as to what's a 100% reliable method to detect the min path. Just "uhh I tried X and it worked". AKA your solution grows exponentially (in which case you fail part 2) or the random number gods smiled on however your CPU chooses between equal elements.
>>
>>103603360
one layer at a time is fine. for layer n-1 there are many same-length solutions, but only some of those give minimal one for layer n

if you get 68 you used one of those movements for the previous layer
28 <A>A<AAv<AA>>^AvAA^A<vAAA^>A 68
28 <A>A<AAv<AA>>^AvAA^A<vAAA>^A 68
28 <A>A<AAv<AA>>^AvAA^Av<AAA^>A 68
28 <A>A<AAv<AA>>^AvAA^Av<AAA>^A 68


instead of one of those
28 <A>Av<<AA>^AA>AvAA^A<vAAA^>A 64
28 <A>Av<<AA>^AA>AvAA^A<vAAA>^A 64
28 <A>Av<<AA>^AA>AvAA^Av<AAA^>A 64
28 <A>Av<<AA>^AA>AvAA^Av<AAA>^A 64
>>
>>103603728
>at every stage, you choose a sequence with the fewest contiguous groups
At every stage you try every sequence and pick the best one
There's no luck involved, just your failure to memoize completely
>>
Alternate Bigboy. Using Eric's example inputs
029A
980A
179A
456A
379A

Solve part2 for 1,000 robots. Answer:
11973914949486945556017391388066235477933002429724847303169555906690883313813851331895475448073124229675135072283508337481900900206546270101682279682338202777651363553698160381867355714258025929308505293919391747981608852597465702489722043124252580252077717994835068711542799285583997290949489428608399922188692686691305078646004922869091793244421698757005571009121805602193543425058939686614577905532
>>
i just steal solutions from here when I get stuck, not filtered :^)
>>
At this point, I just want it to be over.
>>
>>103603911
Then why do the contest at all? The point is to have fun.
>>
>>103603733
what I don't get is how you determine what *will* be optimal, for instance at every layer I take each instruction subset (<A, >A, >>^A, etc) and expand those into set 1, then for each in set 1 I check how large the instructions they produce are, putting that into a subset 2. then I pick any set1 value that has a low subset2 value and I use that as the final expansion of the original instruction subset. somehow this still gives me 68, so evidently this isn't how you properly check it?
>>
>>103603793
>get wrong answer to past 1
>try with same code, except if there's a tie all best paths are taken into the next stage
>get right answer
>aka there are multiple best answers per round, aka exponential growth
>sure enough part 2 runs until a memory error

You're wrong. Nobody itt has solved the problem. Nobody can give a method that avoids exponential growth. Like I said, either you got nice inputs, or you got lucky with how your CPU breaks ties, or you tried a bunch of shit until you happened to stumble on a working method but you can't explain it because you don't understand it.

Am I wrong? Go ahead, show me up. You won't because you can't. I understand this problem better than anyone itt who lucked into a right answer.
>>
>>103603728

Ok, tell me where the "heuristic" or "randomness" is here. This is essentially a pseudo-code'ish cleaned-up version of my solution to part2

@cache
def get_num_presses(movements, depth=0, max_depth=25):
if depth == max_depth:
return len(line)

num_presses = 0
for start, end in movements:
num_presses += min([
get_num_presses(buttons_pressed_on_path(path), depth+1, max_depth)
for path in every_shortest_path(start, end)
])
return num_presses
>>
2h46m left, some of you have some apology letters to write
>>
>>103603944
Break your instructions into pieces, and expand those pieces N times. Then it becomes a DP problem you've probably already solved.

The trick is to work out how long those pieces should be, which you can see by just expanding out a few layers.
>>
>>103603949
>Nobody can give a method that avoids exponential growth.
You're retarded. The space and time complexities of the final algorithm are
O(robots)

The buttons, the paths between them, the codes associated with these paths are constant, so they do not count.
>>
>>103603949
There's a very small number of paths between each pair of buttons, maybe 20 or so total
All you need to know is the best path between each pair at each level
It's a few hundred values you have to cache
>>
>>103603871
126384
Silver: 30.013398ms
11973914949486945556017391388066235477933002429724847303169555906690883313813851331895475448073124229675135072283508337481900900206546270101682279682338202777651363553698160381867355714258025929308505293919391747981608852597465702489722043124252580252077717994835068711542799285583997290949489428608399922188692686691305078646004922869091793244421698757005571009121805602193543425058939686614577905532
Gold: 15.233344ms


It's interesting that the initial pathfinding takes more time than iterating over 1000 robots.
>>
>>103603944
As I said, for a current layer you should get not one shortest solution, but several. Then you give all those to the next layer for checking. The ones that give shortest solutions for next layer are optimal for the previous one (except for the last one, where it does not matter). When you keep previous solutions in memory you can solve part 1, but not 2. For part 2 you just need to convert it to recursion+memoization and will just work. Or just write it like that from the beginning, but depending on your experience, it might be harder.
>>
File: code.png (1.03 MB, 2076x6228)
1.03 MB
1.03 MB PNG
Python

Fuck functools.cache
I always forget how to use it and
get the TypeError: unhashable type: 'dict' every time.
I reworked half the fucking code a hundred times.
>>
>>103604061
I see, I'm going to carry over best paths to the next layer and see if that works
>>
>>103604117
https://stackoverflow.com/a/1151705
>>
>>103603728
>Nobody itt can give a solid answer as to what's a 100% reliable method to detect the min path.
I can't post code since I'm phoneposting from my bed, but my method was based on the following observations:
1) The length of the shortest path will always be the manhattan distance between the coordinates of the two keys. In other words it will consist of x moves either left or right, and y moves either up or down.

2) You should always group the same directions in a path together, since pressing the same key multiple times is less expensive than switching between keys.

3) Combining the observations of 1 and 2, the optimal path will always be a straight line or an L shape. The straight line doesn't cause any issues, however the L shape paths may cause an issue if the "corner" of the L is out of bounds.

4) There are two potential L shaped paths between two keys (horizontal moves first, or vertical moves first). You can check if either one takes you out of bounds, then pick the other one.

5) For every other situation that doesn't take you out of bounds, the default preference for the order of moves is based on how expensive each different move is. < is the furthest away, so it should be done first, then v is the second furthest away. ^ and > are both adjacent to A, however at higher levels, ^ becomes more expensive because it involves moving left. So for any other situation that doesn't involve going out of bounds on the keypad, the default order should be <v^>.
>>
>>103603966
return len(line)

is of course
return len(movements)
>>
>>103604130
Does it work with defaultdict?
>>
>>103604207
probably
just bad things happen if you start changing the dict after you hashed it
>>
Bigboy for Day 19 to demonstrate the Aho-Corasick supremacy:
https://files.catbox.moe/wd7m0x.7z
Silver: 1
Gold: https://files.catbox.moe/bsc8tt.txt

Silver: 315.097016ms
Gold: 93.491926ms
>>
>>103604285
Very cool. I may have been the one to suggest someone use it, and an example like that makes it worthwhile. Now the other guy can try to beat it with his DP approach.
>>
>>103602021
sorry anon, I almost forgot
>>
>>103604322
Brutal day.
>>
>>103604117
If you wanted a hacky way of making dicts hashable, you could simply use an integer as a parameter, then maintain a separate dict which takes those ints as a key and has the original dicts you wanted to use as parameters as values.
>>
The filter is ... strong
Which is weird since day 11 was the same.
>>
>>103604322
I'm filtered.
>>
>>103604387
>since day 11 was the same.
I do not see how day 11 is the same.
Day 11 was easy.
>>
File: Untitled.png (1.51 MB, 2345x2425)
1.51 MB
1.51 MB PNG
>>103604322
im all in
>>
>>103604387
It's because Eric tricks people into implementing the algorithm that he describes for part 1, then in part 2 he asks you to repeat the process a number of times that makes bruteforcing impossible. So people are then forced to rework half their solution, which throws them off.
>>
>>103604395
It is the same algorithm, you have a sequence, and every element turns into multiple elements after each step, you need to find the length of a sequence after n steps. The only difference is that here there are multiple ways to expand a member and you need to find the one that gives you the shortest sequence after n steps.
>>
Alright. I have decided to start again from the beginning.
Hopefully today won't take too long, but I'll get this gold at some point before the 25th.
>>
NEW THREAD
>>103604614
>>103604614
>>103604614
>>
>finish a difficult puzzle
>thread full of posts claiming it's too hard, they're filtered, they'll come back next year, etc
>but I was able to do it
Ahhh, now THIS is the true meaning of Christmas.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.