[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: 1734353660546549.png (1.27 MB, 2168x1207)
1.27 MB
1.27 MB PNG
through the maze edition

>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: >>103533936
>>
File: 1734351996338348m.jpg (46 KB, 1024x424)
46 KB
46 KB JPG
I am too dumb for any of this all I do is monkey crud
>>
what is a dijkstra's edition:
import math
import sys

sys.setrecursionlimit(int(1e9))

g = list(map(list, open(0).read().split('\n'))); g.pop()
rows, cols = len(g), len(g[0])
cache = [[math.inf] * cols for _ in range(rows)]

m = {}
def dfs(pos, d, cost):
if pos == (1, cols - 2):
return cost
(r, c) = pos
cache[r][c] = min(cache[r][c], cost)
dx = ((-1, 0), (0, +1), (+1, 0), (0, -1))
minimum = math.inf

# continue
(dr, dc) = dx[d]
(rr, cc) = (r + dr, c + dc)
if g[rr][cc] in '.E' and cache[rr][cc] > cost - 1e3:
minimum = min(minimum, dfs((rr, cc), d, cost + 1))

# turn left and continue
(dr, dc) = dx[tmp := d-1 & 3]
(rr, cc) = (r + dr, c + dc)
if g[rr][cc] in '.E' and cache[rr][cc] > cost:
minimum = min(minimum, dfs((rr, cc), tmp, cost + 1001))

# turn right and continue
(dr, dc) = dx[tmp := d+1 & 3]
(rr, cc) = (r + dr, c + dc)
if g[rr][cc] in '.E' and cache[rr][cc] > cost:
minimum = min(minimum, dfs((rr, cc), tmp, cost + 1001))

if minimum not in m:
m[minimum] = set()
m[minimum].add((r, c))
return minimum

p2 = len(m[p1 := dfs((rows - 2, 1), 1, 0)]) + 1
print(p1, p2)
>>
File: solve.png (796 KB, 5546x3842)
796 KB
796 KB PNG
idiomatic Rust solution
>>
>>103538073
while let Some((cp

you rust pedophiles disgust me
>>
>>103538087
the child consented though
>>
>>103538057
top kek
>>
glad I made sure to keep a tab open explaining dijkstra for the past ten days, it really came in handy today
>>
>>103538460
sorry but you don't need dijkstra's today: >>103538070
keep that tab open
>>
>>103538498
>cache
yeah that's dijkstra's
>>
>>103538540
no dijkstra's is BFS but with a priority queue
>>
>>103538540
dijkstra's guarantees that when a node is visited that its distance is final.
not only does my code not make that guarantee, it fucking *revisits* nodes.
you truly don't know what dijkstra's is.
>>
>>103538543
same thing
>>
>>103538574
nta but your version is retarded brute foce that assumes that the chracter is starting in such way that no pi radian turn is required and thus guaranteeing that it won't run for an infinite time
You didn't even solve the problem.
>b- but mut star
ok, be happy about it, that's a seperate system and doesn't equate to solving the problem.
>>
>>103538594
>dijkstra fag coping and seething
DFS chads keep winning
>>
>>103538594
are these pi radian turns in the room with us now? Eric only says they can turn 90 degrees.
>>
>>103538594
>>103538605
>>103538606
Forgive me I didn't read through your code carefully
> cache[rr][cc] > cost - 1e3
So this is what makes sure that the program will eventually terminate huh.
Still slower than my bfs if the graph is large enough.
O(logv(V+E)) vs
S
O O O O O
O
.
.
.
O
Consider this graph there is an edge from every node in level 2 to the single node in level 3 and it has a really long tail. And all the edges are 1 smaller than last one, then it will revisit the entire long tail over and over and over again.
You could do this in muliple layers so the runtime is catastrophic, could be Omega(2^n) worst case if the weights are like that.
Face it, your solution is niggerlicious.
>>
File: carbon.png (784 KB, 953x4227)
784 KB
784 KB PNG
>>103536112
Bigboy/day 16 bigboy    time:   [169.31 ms 169.93 ms 170.62 ms]
day 16 time: [1.7307 ms 1.7336 ms 1.7368 ms]

I first find all connections between important tiles: crossroads, S and E. Then use dijkstra's algorithm to find all shortest paths to E. At the end, I do dfs starting from E and only visiting nodes that previously had the exact same costs as current cost from E and record tiles between them. That last part is kinda nice, because I don't have to allocate or clone anything.
>>
Are most of you employed or in school? Is it fair to say that most people who do these are in their 20s?
>>
>>103538789
I'm younger than that.
>>
>>103538789
this post glows
>>
>>103538757
the 1e3 check accounts for branches which reach the same cell from different directions
if i had 4 copies of the graph in cache then the speed would be comparable to dijkstra's
the niggerlicious slowdown is from the naive "if it's only off by 1000 then it's still worth investigating"
i chose to solve it this way because it's shorter
you may also know me as the guy who rotated the entire graph on day 15 0 or 4 times on each step so i only had to consider one case
>>
if this is monday's puzzle, I'll be filtered by friday
>>
>>103538853
I can see the appeal of dfs for part 2 because of the path recovery, however if you store parents from which you arrived at optimum cost you to some node, starting from the end position node it will form a tree and by traversing that with dfs you still get part 2
And for part one bfs is objectively better how is that shit shorter than heappush and heappop
>>
>>103538853
>you may also know me as the guy who also did some retarded shit on a previous day
>>
>>103538863
If you feel like you'll get filtered on Friday because of today's puzzle, you got filtered by today's puzzle. Don't wait, remove your name NOW!
>>
if this is monday's puzzle, I'll save christmas on time
>>
>>103538896
Sorry this is not entirely precise the parent node thing will form a dag not necessarily a tree but that doesnt change the fact that it can be traversed with dfs just dont blindly increase a counter but rather turn the flag on sum afterwards
>>
File: im-1734366480537.png (33 KB, 524x704)
33 KB
33 KB PNG
>pytoddler
washed and replaced my dumb implementation of part 2 with a smarter approach.
>>
>>103538979
Anon Python is one of the 6 certified White man's languages
Anyone telling you otherwise is just cope
>>
>>103539024
what are the other 5?
>>
File: 24_D16_C#.png (887 KB, 2372x4206)
887 KB
887 KB PNG
Spent way too long trying to figure out why my hashmap wasn't properly hashing. Even had to use AI to find out in the end. It's so over.
>>
man i’m happy with my part 2 solve. ended up just changing 1 line. score < visited(xy) to score < visited + 1000. that and len(set(pos)) was enough. unfilty’d today bois.
>>
>>103539121
HolyC, C, C++, x86 asm, Mathematica
>>
File: idiomatic_calendar.png (3.41 MB, 7916x4028)
3.41 MB
3.41 MB PNG
>>
File: file.png (8 KB, 690x677)
8 KB
8 KB PNG
Pretty sure I overcomplicated my solution, but I think it's pretty neat. I did two runs of Dijkstra's algorithm, one from S and one from E (and critically for the second one, I made (E, north, 0), (E, south, 0), etc. the initial frontier). This creates two maps, sSPD and eSPD, where sSPD contains the shortest path distances from (S, east) to any (P, dir) and eSPD has the shortest path distances from any (E, endDir) to (P, dir). For any particular point P, the length of shortest path that goes through P is the min over all directions D of sSPD[(P, D)] and eSPD[(P, -D)] (we have to negate D here because eSPD has paths in the opposite direction of what we want)
Probably could do some pruning during the second run of Dijkstra's algorithm to ignore points that won't possibly lie on the shortest path from S to E, but my brain's a little too cooked for that now
>>
File: r-castle2.jpg (82 KB, 1041x658)
82 KB
82 KB JPG
>>103539024
>tfw been shitting out python for nearly 15 years now
it's just so comfy though
>>
I solved it by doing Djikstra's and then
>backtrack through the least-cost path
>at every fork in the road, determine if the other fork is also a least-cost path
It was kind of retarded but happy to not be filtered without cheating
>>
File: carbon(2).png (990 KB, 894x5652)
990 KB
990 KB PNG
Bigboy times:

   backfill: 28.95ms
nodelist: 36.81ms
graph: 13.85s
part1: 13.97s
800196
2367
total: 14.13s


Graph creation is killing me. Turned each <intersection, direction> pair into a hashmap node, is there a more efficient way?
>>
>>103539230
C++ doesn't belong
>>
>>103539349
where the bigboi at
>>
>>103539377
>>103528248
>>
>>103539387
what in the hell i aint reading all that shit
>>
>>103539366
Yes it does and you're brown
>>
>>103539377
See >>103536112
https://files.catbox.moe/l64q3v.txt
1000x1000
Part 1: 800196
Gold: 2367
>>
>>103539418
Stop projecting vivek, only a streetshitter would defend what might be the worst-designed language of all time.
>>
>>103539454
newfag streetshitter, how dare you question a Danish Aryan AND The Divine Intellect
https://www.youtube.com/watch?v=25hLohVZdME
>>
>>103536564
Using Ddijkstra in Part 2 allows you to avoid tracking paths, which is expensive and slow. The idea is this:

>From the start, get the min cost to every other tile.
>From the end, get the min cost to every other tile.
>For every tile, if cost_from_start + cost_from_end == min_path_cost_from_part_1, add tile to set.
>Return length of set.

I'm getting 130ms in Python. You don't necessarily NEED to use Djikstra, but it's a very straightforward way to get the minimum cost to every other tile from some start tile (though you can also get this with DFS/BFS).
>>
>>103539490
Oh, just doing Djikstras from the ending node is so much simpler than what I did for part2
>>
>>103539490
oh shit that's brilliant
>>
>>103539490
wow this is hella slow
>>
>you'll need to determine which tiles are part of any best path through the maze
so? I'm getting ESL'd here. There's only one BEST solution. There are multiple good enough solutions, but there's only one BEST solution.
Unless multiple paths exist with the same score?
>>
>>103539594
>Unless multiple paths exist with the same score?
yes
>>
File: filtered.png (163 KB, 1653x960)
163 KB
163 KB PNG
Well, I'm filtered. Can't even get part 1. I've tried both recursion and Djikstra, I've written the entire program 4 times, and every time it works on the two examples but not the input.
It's been fun, see you all next year.
>>
>>103539600
thanks
>>
>>103539594
>Unless multiple paths exist with the same score?

If only there were ASCII examples showing graphs with multiple best routes
>>
>>103539609
Run someone else's code and see if it's something dumb like being 1000 off (aka one corner)
>>
>>103539594
maybe read the part where it describes what a best path is?
>>
>11:11:11 until the next puzzle drops
what does it mean? is this a secret hint for what tomorrow's puzzle will be, in the form of a little easter egg left by eric?
>>
I wonder, does this show up in any inputs?
##.##
##.##
.....
##.##
##.##

Couldn't be in mine because I'm fairly sure it wouldn't handle this case
>>
>>103539706
haha anon very funny keep it up
>>
>>103539488
Luckily he was able to leave his job and move onto non-shit languages
>>
So did you all find nodes or use the grid as is?
>>
Graph compression is kind of a waste of time here, right?
>>
>>103539757
making a graph is a waste of time, just operate on the grid directly
>>
>>103539757
That's what I assumed. I can see how it would help on Part 1, but for Part 2 (which is where I wanted to speed things up) it seems pointless since you have to uncompress anyway to get the distinct tiles. Maybe there's a big brain approach here I'm overlooking that lets you get the count of unique tiles from the compressed graph.
>>
>>103539757
I'm not sure how well it would work given that heading matters for scoring purposes
>>
File: carbon (12).png (273 KB, 1118x1353)
273 KB
273 KB PNG
>>103539786
Washed python. Quite pleased with this one, although it's completely different than my original solution.
>>
>>103539821
Sorry, didn't mean to respond to you >103539786
>>
>>103539349
I used a vector backed graph here >>103538776 and each node has 4 edges that might point to another node's index. A hashmap is used for the initial graph construction but that's it. It takes 135ms to construct the graph, but I create new nodes on the fly instead of your initial sweep. I still count all neighbors every step to detect crossroads but at least there are no hashmaps involved...
>>103539782
I store paths between 2 nodes, part 2 takes like 800µs for bigboy, it's a bit hard to measure. I think you could also just store the edge lengths, then:
part 2 = unique edges' lengths - 1 for each repeat node visit
>>
ok i give up i spent way too much time on this and i can't figure it out
what is the trick to solve part 2?
>>
>>103539909
>>103539490
or just Dijkstra again while recording the path so far, pruning every time you exceed the cost from your part 1 answer. Every time you get to the end with a cost equal to your part 1 answer, add that path to a set of tiles.
>>
>>103539909
Brute force
>>
File: amazing.gif (55 KB, 1200x600)
55 KB
55 KB GIF
part 2 gif. nbd. but I guess you could say I'm pretty a-maze-ing.
>>
>>103539720
I've got crossroads in my input, if that's what you're getting at. There's one in the first example as well, line 8 character 4.
>>
all i'm sayin is tomorrow better not be some 3d bullshit.
>>
>>103539909
just dfs, you can even use your p1 result if you want: >>103538070
>>
>>103536112
does this have features not present in the official input? my solution solves both parts in 60ms but OOMs on the bigboy
>>
File: reddit.jpg (82 KB, 1080x1061)
82 KB
82 KB JPG
>code keeps giving wrong answer
>spend an hour trying to find bug, no luck
>copy paste code into chatgpt
>immediately points out minor typo causing the issue
Why shouldn't I do this? Why waste time when i can get my bug fixed immediately?
>>
>>103538789
AoC didn't exist when I was in my 20s.
>>
>>103539909
My shitty broot solution was just to keep track of the path tsken as well as the cost in my djikstra.
>>
got filtered today on part 2. see ya next year bros.
>>
>>103540200
Do whatever you want, lil brainlet
>>
>>103540200
>immediately points out minor typo causing the issue
editors have been doing this for people forever
hell, even the python interpreter catches this shit
>>
>>103540200
Constantly relying on other systems to solve your problems will erode your own ability to solve them.
>>
>>103540282
let me guess, you didn't know how to handle rotations properly and just applied the score to the next node instead of the current one bricking your path reversal?
>>
>>103540282
Part 2 is easy to broot using the results from part 1.
>>
>>103540282
p2 is so short you can fit it in a 4chan post: >>103538070
no dijkstra bullshit, just broot: >>103540357
>>
>>103540190
It has
.#
#.
>>
>>103539757
A waste of programmer time for solving the input? Yes.
A waste of CPU time for optimizing execution speed?
No.
>>
>>103540443
new cope just dropped
define waste
>>
>>103540354
exactly
>>103540357
>>103540362
my PC crashed when I tried, kek
>>
Caught a cold and I can barely think... bros I don't want get filtered....
>>
File: 16304932219190.jpg (52 KB, 512x267)
52 KB
52 KB JPG
>>103540443
>>
File: xarbon.png (17 KB, 500x868)
17 KB
17 KB PNG
washed ass for day 16, still lazy to wash 15
bigboy:
$ ./main < l64q3v.txt 
+ ulimit -s unlimited
+ pypy main.py
+ tee /dev/fd/63
++ tail -n 1
++ xclip -sel clip
800196 2367

real 0m15,494s
user 0m15,345s
sys 0m0,146s
>>
Do you
>fap before the puzzle to have a clear mind when it starts
Or
>don't fap unless you get stuck on a specific edge case, to let the problem sauté for a while, until you come back to it with a fresh mind
>>
>>103540635
there's a reason why it's called an edge case anon
>>
>>103540481
to handle rotations properly you need to add another dimension to your score table, direction
>scores[direction][y][x]
and now one of the paths you can take on your djikstra is rotate (different direction, same y/x) on a node
>>
>>103540635
>Or
> >don't fap
Yes.
>>
File: code.png (520 KB, 1792x3308)
520 KB
520 KB PNG
Python

I adapted a pathsearch from previous years. I somehow got one of the 2000 and 1000 swapped on dirs_scores and it gave me the correct answer on part 1 for both examples but not the input. Quite MADDENING.

Also It is doubtful I will be able to do the next three days.
>>
>>103540653
thanks, this makes sense. I still consider myself filtered. I spent literal hours on this, feel tired, and don't want to play anymore.
>>
>>103540635
man I have RSI now after years of this shit, have to conserve my arms for typing
only when I'm actually horny
>>
>>103540413
that shouldn't cause any issues for me, but my solution is to find all the junctions and path over the graph of those instead. maybe it's just too many (bigboy has 149966)
>>
>>103540635
>edge case
heh
>>
>>103539720
No idea, but my solution most likely handles this.
>>
>>103539720
>>103540825
My input has this pattern.
>>
>>103540635
i do the puzzle first, then I spend the rest of the day fapping, once for each line of code
>>
File: tgf.png (869 KB, 2039x2117)
869 KB
869 KB PNG
Stop crying. It is quite unbecoming.
>>
File: day16_swift.png (1.28 MB, 1834x5138)
1.28 MB
1.28 MB PNG
Swift using BFS in both directions. Could be cleaner.
>>
File: 1714507751764855.png (8 KB, 379x764)
8 KB
8 KB PNG
truly an import solution sorta day today my uiua friends
code to come
>>
File: 1705830243686198.png (32 KB, 467x478)
32 KB
32 KB PNG
>>103541216
here it is
visualization code not included and left as an exercise to the reader
>>
File: 1704245775702956.png (63 KB, 400x400)
63 KB
63 KB PNG
why are all these nerds talking about their smarty-pants algorithms when all you need to do is ``from networkx import all_shortest_paths`` baka
>>
>>103541241
you did not beat aoc
>>
File: day16.png (41 KB, 908x325)
41 KB
41 KB PNG
BQN day 16
>>
>>103541241
i haven't used nx but i've seen it in solves over the years -- do you have to massage your data into an adjacency list or what particular data-structure in order for it to work?
>>
>>103541404
answering myself here but wouldn't you need to do a bfs over the gameboard and then add all the edges and costs in order to then use nx to solve it?
>>
>>103540996
Well I am now filtered. Yesterday was piss easy, but I cannot figure out D16 part 1. I've got Dijkstra implemented, but setting up my costs for each travel step is fucking me in the arse. It's been fun, but this is where I get filtered.
>>
>>103541428
if you need a hint and haven't figured it out yet you can calculate the next step's cost in a "stateless" manner
i.e. you don't have to keep the currently facing direction as global state to the dijkstra function
>>
>>103541428
hint: you don't need dijkstra's: >>103538070
>>
>>103541428
>>103541448
all this direction stuff made me think: is there a path where you cross a point twice? once on North-South axis, and the other time on West-East axis?
>>
File: aoc_2024_16_b.png (1.12 MB, 2022x6888)
1.12 MB
1.12 MB PNG
>>103541448
This is my (broken) solution. I'm pretty sure the problem sits with the recurse function and not Dijkstra.
>>
>>103541468
no, the shortest path would always turn at such a point
>>
>>103541468
no by definition because you would prefer turning in that point
>>
>>103541484
turnleft and turnright is useless, you just need to know the neighbours
dijkstra guarantees you wont turn back on your path
>>
>>103541503
But knowing whether I continue forward or turn determines whether I add weight 1 or 1001 to the edge.
>>
>>103541404
>>103541421
Not that anon and not the most efficient algorithm on part 2 but here's what mine looked like. Nodes are ((i,j), direction) tuples. Iterate over the grid adding every edge to the graph.
import networkx as nx
import numpy as np
import sys

grid = np.array([[*l] for l in open(sys.argv[1]).read().splitlines()])
dirs = [[0, 1], [1, 0], [0, -1], [-1, 0]]
G = nx.DiGraph()
for p, e in np.ndenumerate(grid):
if e == "S":
start = p
if e == "E":
end = p
if e == "#":
continue
for i, dir in enumerate(dirs):
G.add_edge((p, i), (p, (i + 1) % 4), weight=1000)
G.add_edge((p, i), (p, (i - 1) % 4), weight=1000)
if grid[p[0] + dir[0], p[1] + dir[1]] != "#":
G.add_edge((p, i), ((p[0] + dir[0], p[1] + dir[1]), i), weight=1)

print(
min((nx.shortest_path_length(G, (start, 0), (end, i), "weight")) for i in range(4))
)

seen = set()
for i in range(4):
seen.update(
node[0]
for path in nx.all_shortest_paths(G, (start, 0), (end, i), "weight")
for node in path
)
print(len(seen))
>>
>>103541509
like I said, you can do that statelessly
btw your recursion function is all sorts of fucked up
its better to just quit when you get to a bad path instead of only going to good paths, this is true for 99% of recursion algorithms
>>
File: 4way.png (9 KB, 969x897)
9 KB
9 KB PNG
>>103541468
It's entirely possible (at least in part 2)
>>
>works on examples
>doesn't work on input
at this point I'm not even surprised
>>
>>103541531
>btw your recursion function is all sorts of fucked up
Don't I know it, lol.
Ah well, it gives me something to do when I go on leave next week.
>>
>>103541544
That is two different paths crossing one point. Not one path crossing the same point twice.
>>
>>103541552
Don't do recursion.
Implement a stack. It is easier.
>>
>>103541547
Had that with both parts, something about today's problem
>>
>>103541509
Nodes in dijkstra can be more abstract than just irl coordinates
>>
>>103541453
If you have dijkstra set up it'll be much easier to add direction to state than use a completely different algorithm
>>
>>103541552
https://www.youtube.com/watch?v=ngCos392W4w
I really recommend watching this video to understand recursion
it's basically just proof by induction, you handle base cases first, you figure out how to get a step closer to a base case, and then you just assume that your function works and use the result of it to compute the total result
the video definitely explains it better, but recursion gets incredibly easy once you just handwave all the complexity away and assume it just works by default
>>103541570
recursion is generally easier than iterative once you know the process imo
>>
>>103541568
Obviously it's impossible in part 1, you won't revisit any tile
>>
File: file.png (4 KB, 603x539)
4 KB
4 KB PNG
>>103541568
If you have any loop like that, then it'll always be a strictly worse path than just making a turn that avoids the loop entirely
>>
>>103541598
>recursion is generally easier than iterative once you know the process imo

Recursion is just iteration where you're using the call stack as your stack. Sure it's slightly easier in that you have to write less code, but if you're at all confused about what's happening, better to spell it out. Plus you often end up with much faster code.
>>
sounds like this AoC features all the most fun and exciting topics: parsing, caching and graph algorithms
>>
>>103541653
it's basically work
>>
What edge case this is falling?
const auto [nodes, start, end] = parse(argv[1]);
auto score = std::unordered_map<vector<2, int64_t>, int64_t, hash>();
auto pqueue = std::priority_queue< std::tuple<vector<2, int64_t>, int64_t, int64_t>, std::vector<std::tuple<vector<2, int64_t>, int64_t, int64_t>>, cmp>();

for (const auto& n : nodes) score[n] = std::numeric_limits<int64_t>::max();
score[start] = 0;
pqueue.emplace(start, 0, 1);

while (!pqueue.empty()) {
const auto [n, s, d] = pqueue.top();
pqueue.pop();

if (n == end) {
std::println("{}", s);
break;
}

auto nn = n + directions[d];
if (nodes.contains(nn)) {
auto ns = s + 1;
if (ns < score[nn]) {
score[nn] = ns;
pqueue.emplace(nn, ns, d);
}
}

auto ns = s + 1001;
auto nd = (d + 1) % 4;
nn = n + directions[nd];
if (ns < score[nn]) {
score[nn] = ns;
pqueue.emplace(nn, ns, nd);
}

nd = (d - 1 + 4) % 4;
nn = n + directions[nd];
if (ns < score[nn]) {
score[nn] = ns;
pqueue.emplace(nn, ns, nd);
}
}
>>
>>103541639
>Recursion is just iteration where you're using the call stack as your stack.
that's true, but imo only in a literal sense
from my experience when people "get" recursion it's as simple as being able to solve one or two incredibly simple examples and then just handwaving away the rest of the solution because they know they're always progressing towards the base case
with iteration there definitely seems to be a bigger incentive to people trying to fit the entire problem (or at least the stack) in their heads, which is probably why recursion ends up going above people's heads
>>
edgecase bros
#######
#S#...###
#...#...#
#.#####.####
#...#.....E#
###.#.######
#...#
#####
>>
>>103541692
doesn't your priority queue want the priority to come first?
>>
File: 1570843334040.jpg (46 KB, 899x324)
46 KB
46 KB JPG
Now that we've had dijkstra this year, what can we expect in coming days?
>3D points and lots of calculating intersections or some shit
>line segments
>unfuck this assembly program
>DP (yes I know we kinda had it day 11, but that was too easy)
>rotating shit in grids
>RPG / simulation
>???
>>
>>103541801
>line segments
>unfuck this assembly program
>hard cycles shit with primes
Those for sure
>>
>>103541801
Folding origami 4D hypercube

Fucking do it, Eric. I dare you.
>>
>>103541801
Cellular automata
Didn't have one last year, so we're due
>>
File: carbon.png (316 KB, 2348x1676)
316 KB
316 KB PNG
>>103541404
Not that anon, but this was my lazy solution using networkx. I just created a directed graph where there was a separate node for each (x,y,direction), then added edges with the appropriate weight between each of the relevant nodes (1000 to turn on the spot, 1 to move forwards while facing the same direction).

The contracted_nodes part is just combining the two versions of the end node where you are facing north and east, since the problem doesn't care which direction you're facing once you reach the end. It would probably be more efficient to identify the end space during the parsing and handle it differently at that point, but I cba to deal with that. It's also ignoring the versions of the end space where you're reaching it facing south or west, but in this case since the end is always in the top-right corner those situations are impossible here.

After you've set up the graph, it's just a case of abusing the built-in methods to find the shortest path and getting the answers.
>>
>>103541832
We just had cycles with primes, although it wasn't very hard
>>
>>103540635
I edge on puzzles for hours.
>>
>>103540635
a mid problem shit or fap always helps me debug
>>
File: aoc_2024_16_a.png (839 KB, 2022x5126)
839 KB
839 KB PNG
>>103541484
Holy fuck, this actually works for Part A. I just handle the direction within Dijkstra's algorithm. Thanks for the advice, lads.
>>
>>103541801
Would love for him to thrown an intcode program in there as a callback to 2019, perhaps as the "unfuck this assembly" problem.
>>
redpill me on C#
>>
>>103541801
More
>grid problem
>grid problem
>grid problem
>grid problem
>grid problem
>grid problem
>>
>>103541987
more like C-Shart
>>
>>103541866
Did we?
Fuck I can't recall at all.
Maybe I got Parkinson's or something.
>>
>>103541801
lots and lots of leetcode-tier problems -- forever
>>
>>103541987
white mans language
>>
>>103542004
Day 14 can be brute forced by just checking all W*H states, but one way of optimizing it is by finding two points in time that minimize the X and Y coordinate variances (which requires far fewer iterations as the motion is periodic) and applying the Chinese remainder theorem to find the time that minimizes both variances at once
>>
>>103542031
it's the most indian thing that isn't java
>>
>>103542040
no thats js
>>
>>103542040
all programming languages should be ranked by how much of their relative popularity comes from india
>>
>>103542046
prove it
>>
File: file.png (41 KB, 751x509)
41 KB
41 KB PNG
>>103542056
>>103542057
oh nonono pytoddlers...
>>
not filtered but today was straight up NOT FUN
>>
>>103541801
Assembly would be nice. Anything visual too.
>>
>already have a graph of each state visited and the best possible score at the state
>just start at the goal, imagine the prior states and then add all ones in your graph to the set of visited states (repeat x failure)
>>
I HECKIN LOVE GRAPHS!!!!
>>
Is Part B just asking for every path that goes from S to E, without cycles?
>>
>>103542192
Every path that goes from S to E with the same min
>>
surely there must be an alternative to advent of code where you build something cool over a few weeks, rather than doing job interview problems
>>
>>103542192
len(set([node in best_paths]))
>>
File: 1699477087520166.jpg (97 KB, 550x512)
97 KB
97 KB JPG
>>103542214
>>
>>103542239
you don't like doing graphs?
>>
File: 1645533642916.jpg (42 KB, 800x450)
42 KB
42 KB JPG
>>103541989
worst thing about aoc
>>
>>103542239
You mean like home projects?
>>
>>103541801
tomorrow you have to dust off your intcode vm and extend it with doubles. the 4.5793472146389 instruction is division
>>
>>103542361
>intcode
>doubles
>>
>>103542239
codecrafters has this but its not an event
idk how good it is either I just know its shilled by some youtubers I like
>>
File: 2024-12-16_22-45.png (241 KB, 1830x1323)
241 KB
241 KB PNG
corejavabros we came really close to being filtered today.
one more day with this kind of part 2 and it might be it for this year...

>>103536112
getting wrong part 1, then part 2 balloons to multiple dozen gigs of RAM after a few minutes and presumably never finishes
thanks for providing a bigboi tho, it's truly a big one
>>
>>103542119
>just imagine a solution to the puzzle
>>
>>103542567
>then part 2 balloons to multiple dozen gigs of RAM
This is the same problem I'm running into, no idea how to solve it. But I get the correct part 1 answer in 600ms.
>>
>>103542567
>>103542604
Are you enumerating all paths? Because the number of paths is exponential, and you don't need to do that.
>>
>>103542612
Yes. Is it not enough to just cull paths if they exceed the min cost I find for part 1?
>>
>>103542618
The number of minimum cost paths is still exponential, so no.
>>
>>103541920
Dijkstra tutorials suck because they pretty much all confuse a node in the search with a physical node in a map. When irl the state often carries other info.
>>
>>103542069
Now we know why shills hate Rust
>>
>>103542361
dubs and this is happening
>>
File: maze.png (15 KB, 1000x1000)
15 KB
15 KB PNG
Fellow anons what is wrong with this obviously perfect solution? I get both examples correct for A and B, but this solution for part B, on my actual puzzle data is too looooow.
>>
>>103542604
What are you considering a node, each dot?
>>
>>103542696
Each junction. Solves the official input in 30ms so I'm surprised it doesn't work for the bigboy.
>>
>>103541653
There haven't been any days with difficult parsing yet this year.
>>
>>103542689
Triple check your score algorithm.
I got it wrong and some how gave me the right answer for both examples but not the input.
>>
>>103541653
>filterlet cope
seethe and return to vscode with catpuccin I see you faggot
>>
>>103542689
off by 1 error add 1
>>
>>103542142
I FUCKIN HATE GRAPHS
>>
File: Day16-2.png (4 KB, 191x131)
4 KB
4 KB PNG
>>103542689
Looks like there should be another valid path here.
>>
>>103542782
what the hell is catpuccin?
>>
>>103542824
Common (and overdone) onions-dev color scheme.
>>
>>103542801
Damn. I think you are right. How could it catch the others but miss that one? Investigating. Thanks!!
>>
>>103542689
Triple check the start/end states are handled properly, that was my edge case. Thought Eric was generous with two examples but a bunch of anons are saying the same thing, there are common input edge cases the examples don't touch.
>>
>>103542704
How exactly are you storing the graph+paths? I got similar times on the input and bigboy was 14s. Others got similar input times and ms bigboy times, and at a high level all our code sounds pretty similar.
>>
>>103538073

while let some cp r(a)p(e) d(ouble)p(enetration) h(ymem).pop()


No way that is a coincidence.
>>
>>103542604
>no idea how to solve it
ngl I just ran it to see if it would, saw that no, and that's it. doubt I could find a fast enough solution even if I tried.

>>103542612
>Are you enumerating all paths
to a point?
enumerating routes until one of:
1. I run into a node+orientation I visited before, and my current cost is higher than back then
2. current path cost exceeds best cost (silver result)
I'm sure there's much clever ways to do it, but by the looks of it >>103542623 is right and my priority queue grows faster than I pop off it, and the cost of interacting with it is what dominates time spent in the end
>>
>>103542941
schizo
>>
>>103542957
Consider each node individually. Is the minimum cost to end plus the minimum cost to start equal to the minimum cost from start to end? Then the node is part of a minimum cost path.
>>
>>103543000
yeah I tried this double-dijsktra-type approach at one point, and got the wrong value back
probably cause I didn't handle the matching of both sides + their respective possible directions
but also double-dijkstra for each node is slow as shit and I strongly doubt anyone solved bigboy with that
but maybe there's a way with 2 dijkstra passes and then just looking at cost maps? idfk to be honest
>>
>>103541241
based solution importer
>>
>>103543051
Dijkstra gives the minimum cost to all nodes, so you only need to run it twice and save the cost for each node.
>>
>>103542604
You solve exactly like part 1, except for each node you store a vector of [shortest nodes that reached this node]. Almost all vectors will have 1 element, some will have 2. At most they can have 3.

When you reach the end node, put it on a stack (only exit when you find a node with a higher value, just in case there are 2 routes that approach the end from different directions).

Then you backtrace, sure this occasionally branches but it's basically linear:

// node.0 is the coordinates, node.1 is the direction

// Count unique tiles on shortest paths.
let mut unique_tiles: usize = 1;
let mut been_on_stack: HashSet<Point> = HashSet::new();

while !stack.is_empty() {
let current_node: PointDir = stack.pop_front().unwrap();

// Cannot retrace further than start.
if current_node.0 == start.0 {
continue;
}
for prev_node in previous.get(&current_node).unwrap() {

// Rotation, doesn't affect path count.
if prev_node.0 == current_node.0 {
stack.push_front(*prev_node);
continue;
}

// Hope there are no paths >1000.
let path_len: usize = graph.get(prev_node)
.unwrap()
.iter()
.filter(|maybe_current| maybe_current.0 == current_node)
.next()
.unwrap().1 % 1000;
unique_tiles += path_len;

// Only backtrace from each node once,
// even if mutiple paths lead to it.
if been_on_stack.contains(&prev_node.0) {
unique_tiles -= 1;
} else {
stack.push_front(*prev_node);
been_on_stack.insert(prev_node.0);
}
}
}

// unique_tiles is now your part2 answer.


I have no idea where you're using gigabytes of RAM on part 2 specifically.
>>
>>103543051
I didn't have to worry about directions at all.

optimal_tiles = set()
for y in range(len(grid)):
for x in range(len(grid[0])):
if grid[y][x] != '#':
for dir1 in '^v<>':
for dir2 in '^v<>':
if forward_costs[x,y,dir1] + backward_costs[x,y,dir2] == min_cost:
optimal_tiles.add((x,y))
break


Just broot through every direction combination and take all combos that result in the min_cost path.
>>
>>103542879
My graph is an array of nodes, each node has an array of edges, each edge has an index into the node array and a list of points between the two nodes. I think the design is all reasonable except where I build paths. Each time I visit a new node I record the position permanently in a list as a child of some other position in the list, and this list of visited nodes is multiple millions of elements. I don't prune it because I want the indices to be stable, but this is partly why mine is fucked (the other is that the queue of places to visit is also >1M)
>>103543000
what the FUCK my mind is blown
>>
>>103542957
thats normal for a bfs, you have to use a different algorithm if the number of paths is that large
>>103542604
for the bigboy or for the real puzzle? if its the real puzzle you fucked up somewhere
>>
>>103538057
I was able to modify my Djikstra's to actually work though... The path mapping gets hairy but conveniently the input lets you implement it incorrectly and still get the right answer. There is also only one unique way to reach the End point with the lowest cost.
>>
>>103542801
Thanks again this fixed it. I was backtracking from the end and only following edges with exactly the cost I was expecting at that point. The flaw was marking vertices as 'already visited' instead of the edges as 'already followed'.
In this edge case you have to revisit the vertex while backtracking from a different direction.

Is 326ms anywhere near reasonable for this problem? This is taking a big bite out of my self-allotted budget of 1 second for the entire aoc2024.
>>
>>103543135
imo anything 3 seconds or less is good enough but im a pytoddler
>>
How do you handle the scoring with Dijkstra? I'm thinking of an example that has a crossroads. When you approach the tile, there's no guarantee if you'll turn or keep going straight, but if you just store it as a series of nodes there's no sense of "turning"
Using this as a sample >>103539720
>Approaching from the west, heading east
Would be no turn, only +1
>Approaching from the west, heading south
Turn, +1001
>Approaching from the north, heading south
No turn, +1

I don't get how you store this on a node by node basis because in this sample going from the middle node south can have a different score depending on where you came from, but that'd mean storing an extra node back worth of information. Do you just check the last two nodes instead of the last 1 node?
>>
>>103543107
Forgot to add,
previous
stores the shortest previous nodes, and
path_len
is just getting the distance between the current and previous node from the graph.
>>
>>103543157
instead of using nodes as (X,Y), consider (X,Y,face).
if approached from different direction, you are on a technically different node
>>
>>103543157
A node in Dijkstra doesn't have to be a (y, x) coordinate. It can be a (y, x, dir) triple.

So (4, 7, N) is adjacent to (4, 7, E) and (4, 7, W) with distances of 1000 each. N E S W can just be numbers 0 1 2 3.
>>
>>103543157
Don't move on turns.
Your state key is basically current x, y and your vector and your cost is well, the cost.
At each junction you just push a counter clockwise and clockwise rotation (+1000 cost) and one step forward (+1).
Your base case is wall (prune) or finding the E.

Use a hashmap for your distance map and a minheap for the frontier. Part2 is a bit hairy, but idk if you're at that point.
>>
>>103543157
>I don't get how you store this on a node by node basis because in this sample going from the middle node south can have a different score depending on where you came from

The beauty of Dijkstra's algo is that you don't need to store this.

With Dijkstra's algorithm, if we process nodes in strict order of current cost (guaranteed if using a heap), then the FIRST time we visit a node is GUARANTEED to be the cheapest possible path to that node.
>>
>>103543157
Yet another person filtered by >>103542674
>>
>>103539342
>ran poster and python user
BASED ** 2
>>
>>103543203
that doesnt help you with part 2 though, as you could visit it again later with the same cost
>>
>>103543205
He's right thoughbeit. People forget the "node" can be virtual as long as it carries the necessary state. I used Dijkstra's for the Wizard problem in 2015 as well and it literally just works.
>>
>>103543155
I'm doing C++ this year and going for highly optimized solutions. Hence the bugs :)
Did a small optimization in my cost calculation, and brought the time down to 46ms. Might still be some room for improvement, but now day 14 is a bigger problem with 133ms.
>>
>>103542239
game jams come to mind
>>
>>103543203
There could be a south->north path that's lower cost than a west->east path at that physical location, but has more turns and ends up more expensive than the west->east path. You'd never find the shortest path if you treat each location as a node. You have to be more abstract with what you consider a node to be.
>>
>>103543219
Did you do this?
>>103542035
>>
>>103543217
>People forget the "node" can be virtual as long as it carries the necessary state
people dont understand algorithms at all, they just mindlessly copypaste it
>>
>>103543214
For most advents you don't need the path mapping in Dijkstra, just the cost. for part2 you can tweak the pathing storage to work for part2. Worst case (which seems to never happen) you can pop more off the heap if they're same cost and at End if it was possible to reach End with the same cost from different states.
>>
>>103542602
imagine if you weren't awarded any starts today
>>
File: qman.jpg (58 KB, 525x503)
58 KB
58 KB JPG
>>103542983
Better safe that sorry.
Anyway I have being doing my own research and it seems that language is popular among certain population that is commonly associated with child abuse.
I will do what I can contacting my representative to bring some attention to this issue. Hopefully we can ban that language as part of the Project 2025.
>>
>>103543232
Obviously you need to consider turns and forward advances as separate nodes.

>>103543214
It helps if you use a bidirectional dijkstra for part two.
>>
>>103543254
>It helps if you use a bidirectional dijkstra for part two.
whats the point when you can do it with one
>>
File: 4way.png (9 KB, 880x839)
9 KB
9 KB PNG
>>103543203
>>
>>103543259
double dijks saves you the trouble of needing to track or save paths
>>
I don't get it, what's all this arguing about? it's just dijkstra but you append new shortest paths found instead of replacing the previous one, then you go backwards from the end node
>>
>>103543254
>Obviously you need to consider turns and forward advances as separate nodes

Clearly that's not obvious since the whole issue with >>103543157 stemmed from confusing physical locations with nodes.
>>
>>103543274
tracking paths saves you the trouble of pathfinding multiple times
>>
>>103543236
No I counted the number of adjacent robots in every frame, and the image has a much higher count than all the others. I just did the counting in a really dumb way by iterating over the entire grid. Just updated that to just look at the robots. It is now down to 38 ms.
* Day01 0.305ms
* Day02 0.737ms
* Day03 0.247ms
* Day04 0.945ms
* Day05 1.185ms
* Day06 2.104ms
* Day07 1.517ms
* Day08 0.063ms
* Day09 0.492ms
* Day10 1.943ms
* Day11 6.254ms
* Day12 0.718ms
* Day13 0.748ms
* Day14 38.576ms
* Day15 1.516ms
* Day16 48.505ms
>>
>>103543260
It doesn't happen in this problem on any input I've seen, but if it does, just keep a sentinel that's basically costmax = INT_MAX.

When you reach End, set costmax = cost and then keep popping the heap til your cost is no longer equal to or less than costmax.
It's an abuse, but it should guarantee you get all same (LOWEST) cost paths to E.
>>
>>103543274
>doing [complex thing] saves you the trouble of [simple thing]

If you do dijkstra and want to save your min path(s) just store the min prior node(s).
>>
>>103543280
You'd think, but at least when I tried both methods, my double dijk was about 10x as fast. Maybe my implementation was bad though.
>>
For path map, you just do -> hashmap(node, list node)
It's really not that complex. You can use a simple stack to visit all the paths to origin...
Idk why you niggas using double dijks or whatever the fuck. Obviously the list of old nodes must have the same cost reaching the node you mapped it to.

If your cost visiting node is less, clear the list before adding the current node you're on.... Again, real easy.
>>
>>103543282
Do that but instead of doing 10403 steps over two axes do 101 steps over 1 axis and 103 steps over the other.
>>
>>103543354
Bigboy time?
>>
>>
it's over
>>
starting to filter myself due to sheer unwillingness to do another AoC pathfinding puzzle
send help
>>
>>103543381
Idfk. If I had to optimize it, I'd just use a fixed 4 space array since the same cost can only be coming from different vectors, but I didn't bother because I don't care.
>>
>>103543396
Just copy code from previous puzzles. Less than half the lines in my solution were original.
>>
>>103543108
>>103543102
welp good point... tyty both

>>103543124
>you have to use a different algorithm if the number of paths is that large
is there any good method aside from the double-dijkstra one?
>>
Played catchup on the weekend's at work today. Saturday's was pretty easy, the Christmas tree part was a bit annoying since you have to either make assumptions or watch through thousands of outputs, I just assumed that the output from the first 10,000 that minimizes the number of robots with no adjacent robots would be the best, and it ended up working
Sunday's annoys me because I had a very clean and clever recursive solution but had to write a way to view the map each iteration to find a miniscule bug (I had a set of boxes, when a box is moved up, it is removed from the set and the box with the new position is added to the set. Problem is if you add a box that is already in the set then that box will be removed when it is supposed to stay)
Didn't start writing today's but it seems like simple uniform cost search should do the trick
>>
>>103543473
for an exhaustive search you can just dfs, the problem with bfs is only that it uses too much memory to expand every path at the same time
>>
>>103543386
yo am I still in this if I hand my assignment in late or as soon as I miss an assignment by 24 hours I'm officially filtered?
>>
>>103543371
Oh that sounds interesting. Going to think this over on the morrow.
>>
File: 1702956462947922.png (2.56 MB, 868x3302)
2.56 MB
2.56 MB PNG
Finally had time to wash my messy solution.

Benchmark 1: ../target/release/aoc-day16 /tmp/bigboy.txt
Time (mean ± σ): 1.129 s ± 0.009 s [User: 1.050 s, System: 0.072 s]
Range (min … max): 1.115 s … 1.140 s 10 runs
>>
nobody on /g/ knows what Djikstra's algorithm is huh
>>
>>103543808
I'm guessing "aoc_utils" is an external library? If so, that's probably cheating
>>
>>103543606
>yo am I still in this if I hand my assignment in late
yes
>>
>>103538057
Looks good
>>
>>103543852
>organizing and reusing your code is cheating
>>
>>103543852
it's my own local crate, I'm not going to redefine Point2D or rewrite the code to open the input file every day
>>
>>103544046
I think I wrote
>return i >= 0 and j >= 0 and i < arr.length and j < arr[0].length
at least 5 times now
>>
>>103543852
Formally or informally, everyone has their own utils library. Or do you write another grid-reading algorithm every day?
>>
>>103544100
I write grid = np.array([[*l] for l in open("input.txt").read().splitlines()]) from scratch every day
>>
>>103543606
The filter is dropout cope. If you solved the puzzles you're in.
>>
>>103543606
There is no cash prize. You're doing this for fun. You're an adult, you get to decide for yourself whether you're "still in it" and who else is "still in it" from your perspective.
>>
>>103544112
>np
cheater
>>
>>103543606
24 hours = filtered
>>
>>103543371
Oh shit this works. Set ans2 to xr and add width until it equals yr mod height. Where xr and yr are the indices of the steps with suspiciously clustered values. You only need to simulate 102 steps.
>>
my broot part 1 is still running guys give me a minute.
>>
>>103544176
Basketball rules, you dodge the filter if you ran your code before 24hr.
>>
>>103544175
>add width until it equals yr mod height
https://en.wikipedia.org/wiki/Chinese_remainder_theorem
>>
>>103544191
>not brooting your congruences

ishygddt
>>
Are there any youtubers who explain this stuff well? Not livestream/speedrunner shit but explaining the most efficient solution.
>>
File: day16_fast.png (319 KB, 943x2757)
319 KB
319 KB PNG
finally a fast solution. this was such a pain...
>>103536112
 time ./target/release/aoc_2024 < ./bigboys/l64q3v.txt
day16 result:(800196, 2367)
./target/release/aoc_2024 < ./bigboys/l64q3v.txt 0.11s user 0.01s system 89% cpu 0.130 total
>>
File: aoc_2024_16.png (106 KB, 1024x1218)
106 KB
106 KB PNG
Perl. I should try to store sets of paths of optimal lengths to each visited point instead of brute forcing p. 2, but it is good enough for today.
>>
>>103544280
sub 1 ms for regular input
>>
wait, people on /g/ are unironically using rust now?
>>
>>103544112
>import numpy
>>
>>103544280
Nice
>hash map and hash set for x,y,r tuples
What if you use an array instead?
>>
File: Screenshot AoC 16-1.jpg (500 KB, 1776x2147)
500 KB
500 KB JPG
> Wake up, open puzzle.
I'm not writing a maze solver again.
> Manually color in spreadsheet cells and prune passages for five hours.
> Got silver star, fuck part 2.
>>
>>103544504
>anime girl as the background
Either you're a coomer and that's your waifu or you're a tranny
>>
>>103544504
based
>>
>>103544504
that IDOL song gets stuck in my head whenever I see Ai Hoshino
>>
>>103544516
>doesn't know oshi no ko
anime website
>>
>>103544609
troon confirmed
>>
>>103544609
I know this is an anime website, but
A) not many people, even on 4chan, would go out of their way to set their spreadsheet software's background as an anime waifu, and
B) do you expect me to know every SOL anime? Only anime I watch are shounen like dragon ball and the occasional "2deep4me" shit like steinsgate
>>
>>103543606
>as soon as I miss an assignment by 24 hours I'm officially filtered?
Yes
>>
>>103544609
>2020
That was the last year I consumed any weebshit desu
>>
>>103544631
Oh and speaking of "2deep4me", I need to watch lain some time but I'm too lazy to get around to it
>>
File: welfin-2.png (583 KB, 921x620)
583 KB
583 KB PNG
>>103544653
watched hunter with my kids last week or two and just started trigun
I forgot how good that shit can be sometimes
>>
>>103544755
those are good animes not tranimes like posted above
>>
File: carbon(34).png (315 KB, 943x2719)
315 KB
315 KB PNG
>>103544466
actually sped it up a tiny bit. about 110 ms now
>>
Small boy:
Silver 3007
Gold 17
######
#....#
#..#.#
#S.#E#
#..#.#
#....#
######
>>
>>103544815
idgi
Is there some way of doing it that blows up here?
>>
>>103544815
Impossible boy:
Silver undefined
Gold undefined
#######
#S.#.E#
#######
>>
>>103544838
The official inputs are formatted to make it easier, so there are fewer "corner" cases, this one is not.
>>
>using networkx
you didn't beat aoc
>>
>>103544815
i dont understand how this could cause problems for anyone
>>
File: file.png (1 KB, 163x20)
1 KB
1 KB PNG
>>103544838
only if your code is retarded
>>
>>103543135
>Is 326ms anywhere near reasonable for this problem?
My solution takes 70 seconds and I'm not going to do anything to improve it
>>
>>103543135
My machine is 9 years old and it takes 20ms, but I am coding in C++, not Python.
>>
>>103544988
That is total time BTW, everything included.
>>
>>103544988
Is 10ms after commenting out the code that prints the maze to screen.
>>
>>103544875
I've written Dijkstra's algorithm a dozen times
I could again
I simply choose not to
>>
File: comparison.png (320 KB, 1461x1653)
320 KB
320 KB PNG
More people have been filtered this year than last year. Both screenshots from ~8:00PM Eastern on Dec. 16th of the respective year.
>>
>>103545076
probably due to the influx of "coders" who make apps with ai prompts
>>
>>103545076
Advent of Grids. I'd guess a lot of people got bored.
>>
>>103545076
damn, what happen? I remember last year being harder
>>
How come none of the search problems ever require a heuristic, I feel that'd be more fun
>>
>>103545087
>I remember last year being harder
Maybe you just got better at coding. You should ask for a raise.
>>
>>103545083
Just get better libraries, one that turns those grids into a proper directed graph. You only need to provide a lambda to calculate edge costs and call one of many functions available that do the job for you. EZ AF.
Of course you can reinvent the wheel if you are into that.
>>
>>103545083
I only noticed now that excluding day 2, every single even-numbered day has been a grid problem. Wild
>>
>>103545141
Don't forget day 15.
>>
File: lisp.png (15 KB, 636x136)
15 KB
15 KB PNG
>>103544875
Lisp, simple as that.
>>
File: loli-sunglasses.png (813 KB, 899x899)
813 KB
813 KB PNG
cycle detection today
>>
>>103545122
I already get 200K making node.js webshit
>>
You have never used Dijkstra's algorithm to solve a real problem and you'll likely never will.
>>
>>103545185
biittch you ameri-jeets have it good. thats like a million leaf clown bucks
>>
>>103545188
just used it to calculate the cost of getting my dick into your mom's pussy ($0)
>>
>>103545208
jokes on you retard. with no cost thats just regular BFS
>>
>>103545188
How many "real problems" are you solving by posting on 4chan buddy
>>
>>103545126
its lame still, when i see a grid i skip the day
>>
yeah I don't think I'll be back in time for today, good luck anons
>>
>>103545031
>today was simply too easy, that's why I needed someone else's code to solve it
>>
>>103545250
NTA, but I decided pretty much my entire career path based on 4chan posts and it turned out pretty good and I also found true love on here
>>
completely filtered on silver of a boring and trivial problem that I've solved a dozen times already in prior puzzles, and for which I have 99% applicable code from last year, and while passing the examples but not the input.
Thanks Eric.
>>
>>103545076
>biggest filters were days 2, 4, 5, 6, 12, 16
hmm
>>
>>103545338
The stars predict an easy day for us.

Beware multiples of 3.
>>
>>103545179
Aho–Corasick algorithm today.
Btw, it's hilarious that this is actually Aho algorithm, and he only added his assistant Corasick there because she sucked his dick.
>>103545250
>How many "real problems" are you solving by posting on 4chan buddy
You're joking, but shitposting on 4chan really improved my writing skills for IELTS. They have this bullshit assignment about comparing pee to poo, and you just need to shitpost many words without ever doubting whether what you write is true or not.
>>
File: theontarioman.jpg (249 KB, 1826x1108)
249 KB
249 KB JPG
Aho algorithm? I'm intrigued
>>
>>103545355
who is he going to enforce that? retards will just search for every single pattern with python "in" or find or something
>>
has anyone seen the krita drawing anon?
Been missing for 3 days now.
it was the best drawings
>>
>>103545408
The filter is ruthless....
>>
>>103545387
Part 2 can be "Oops, the first string is actually just a seed, and now you need to find all matches for these 1000 words in 1 000 000 000 characters of the generated input".
>>
>>103545422
noo. every morning I woke up I was looking forward to the new drawing
>>
>>103545408
Hi I didn't get filtered lol, I just had something super time sensitive come up a couple days ago and had to focus all my energy on that. Should be free for the rest of December though. Probably gonna post all my catch-up drawings tomorrow
>>
>>103545428
based, I hope eric does that, 90% of /g/ would be filtered
and anyone looking up the algorithm or import solution is filtered
>>
>>103545448
>anyone looking up the algorithm
how did you learn about it then dingus?
>>
>>103545442

nice!
>>
File: aoc2023.png (134 KB, 1158x591)
134 KB
134 KB PNG
>>103545076
2023 was comfy.
>>
>>103545451
It's basically just an automaton (graph) built from all the patterns and putting the big text as an input.
You can figure this out yourself, you don't need to know what Aho-Corasick is.
>>
>>103545451
i invent my own algorithms
>>
>>103545448
>you need to know the algorithm off the top of your head because... you just do ok?!
Fuck off.
>>
>>103545509
Learn to read illiterate retard, I didn't say you need to know Aho-Corasick.
I said anyone who looks up the algortihm is filtered.
>>
FIVE MINUTES
>>
really hungry and tired
hope today is easy so I can eat and go to bed
>>
File: showtime.jpg (46 KB, 640x480)
46 KB
46 KB JPG
https://www.youtube.com/watch?v=hjGZLnja1o8
>>
>>103545533
cancer music
>>
>>103545533
kino music
>>
File: mokou-showtime.jpg (130 KB, 440x518)
130 KB
130 KB JPG
>>
THREE. MINUTES.
>>
>showtime
>thread is dead
grim.
>>
>>103545547
everyone went home because it's too hard
>>
>>103545533
SHOWTIME
>>
>>103545546
>>103545547
everybody's filtered, sorry
>>
File: showtime-frog.png (468 KB, 1858x1829)
468 KB
468 KB PNG
>>103545533
we rollin
>>
game of life today
>>
lcm today
>>
THREE DEE
H
R
E
E

D
E
E
>>
File: dabuchi.jpg (398 KB, 1532x2048)
398 KB
398 KB JPG
DABUCHI time!!
>>
regex problem today
source: I am eric
>>
>>103545551
thread becomes a ghost town as we approach christmas
>>
>>103545569
I will do it without regex
>>
CRT today
>>
WE'RE GETTING DP'D BROS
>>
HRT today
>>
what IS a monad anyways?
>>
FUCK
>>
FUCK
>>
FUCK
>>
FUCK
>>
FUCK
>>
FUCK
>>
advent of parsing
>>
>wall of text
>tiny input
oh no...
>>
>assembly
>>
>It's a rev eng episode
pen and paper chads?
>>
advent of reading comprehension
>>
This one is cool, but I would hate to do it in a hurry. Sounds like a comfy problem to do with a glass of beer after work. See you later.
>>
but i don't want to be an emudev
>>
File: 1733431358775192.png (93 KB, 320x240)
93 KB
93 KB PNG
>>
i dont understand a single fucking thing he wrote
>>
>part2
FUCK
>>
Brootchads... our time to shine.
>>
>part 2
see you guys next year
>>
>part 2
brute force bros...?
>>
>works for all examples but not puzzle input
fuck my ass
>>
>works on examples not input
fugg.
>>
>MY ANSWER WAS RIGHT BUT I LITERALLY NEEDED TO INPUT THE COMMAS

FUUUUCK YOU ERIC YOU NIGGER
>>
>>103545737
BROOT IT
>>
oh no this is the reverse engineering day isn't it
FUCK
>>
File: cry-cirno.jpg (496 KB, 1536x2048)
496 KB
496 KB JPG
>read part 1
>ez pz, no problem!
>read part 2
>>
I'm gonna be up for a while it seems
>>
>part 2
im a fraud... see you guys next year
>>
File: file.png (766 KB, 1108x2058)
766 KB
766 KB PNG
I'm brootin so hard...
>>
why does OUT do a mod 8 on it's combo op? all ops must be 3 bit and thus already the equivalent of mod8
>>
>The answer is somewhere between 50000000000000 and 100000000000000
FUCK
>>
Are commas part of the answer or not? I have no idea where my shit went wrong, the example is working
>>
>>103545873
its a combo op, which means 4-6 is a register value
>>
>>103545895
uhhh brootchads?
>>
>it's another program the proper part b while the you brute force it day.
>>
>example works
>input doesn't
>>
>part 2
FUCK
>>
>example works
>real input returns 0,0,0,0,0,0,0,0,0
>>
inb4 my laptop is still brooting by the time i wake up
>>
>>103545909
THEY ARE, FUCK YOU ERIC
>>
>>103545976
read nigga read
>>
>>103545976
>Once it halts, what do you get if you use commas to join the values it output into a single string?
anon...
>>
So for part 2 im noticing that the program increases in length every so often after each number in it goes through some cycle.
>>
>wrong answer
>rewrites my code
>gets the same answer back
???????
>>
jnz means jump to 3?
>>
File: assadjak.jpg (136 KB, 1887x1742)
136 KB
136 KB JPG
bros... i don't think brooting will work.
>>
>realize that by jumping to an odd number it can read a secondary set of instructions
shit that complicates things
>>
>>103546056
>Not just brooting harder
>>
>>103545895
hahaha
this is a joke, right?
>>
>>103546059
Check your input anon. There's only one 3, and it points to a constant.
>>
>>103545895
brootsisters...
>>
File: 1707089644047366.png (792 KB, 2560x5662)
792 KB
792 KB PNG
here's my brootable saars. it will finish, I'm sure of it
>>
>>103546056
only one way to know.
>>
brooting isnt going to work

with some trial and error i determined my answer is between 35184372088832 and 281480000000000

since the output gradually grows as the initial A register increases
>>
File: bqn.png (135 KB, 886x916)
135 KB
135 KB PNG
day 16 p1 in BQN
>>
>>103546118
so could you do a binary search?
>>
AIEEE I AM SOOO CLOOSE BUT THERE IS SOME SORT OF WEIRD EDGE CASE I DONT GET FUCK FUCK FUCK
>>
>works on sample
>doesn't work on input
I need YOUR input, because this shit cannot be debugged at all
>>
>>103546124
Theoretically yes, but you'd need to decode the output to determine whether to look above or below a given initial A register

Haven't figured that out yet since the output values dont increase or decrease linearly
>>
Finally did it. I experimented with larger steps until output was closer to the desired.
      -------Part 1--------   -------Part 2--------
Day Time Rank Score Time Rank Score
17 00:22:18 1275 0 00:59:56 219 0
>>
so the output needs to output a copy of itself, correct?
my program has a length of 16. interestingly, I printed how many instructions each starting value gives, and I noticed that from 32767 to 65536 it gives a 16 length result. however, the answer isn't within that group, but I suspect there's a cycle and it has to do with these ranges since it's powers of 2. it seems like for each number, the resulting length of its output set is log2(A+1)? I can't see where the cycle comes in, must be a lot larger than I realize. going to try a few million steps at a time and see
>>
Divide by zero error. It's over.
>>
digit 1 starts at 0
digit 2 starts at 8
digit 3 starts at 64
digit 4 starts at 512
digit 5 starts at 4096
digit 6 starts at 32768
digit 7 starts at 262144
digit 8 starts at 2097152
digit 9 starts at 16777216

hmm
>>
Trying to figure out how you can work backwards given the expected output. It's super complicated because output is COMBO % 8, and because there's jumps involved. Almost feels like a pen and paper thing, though that's probably incorrect.
>>
>>103546134
I KNOW MY PROBLEM I WASN"T CONSIDERING WHAT THE (7,5) INSTRUCTION DOES
AIIIIE I COULD HAVE DONE SO WELL
>>
>>103546124
I found the lower and higher bound of A and thought about this, but idk how I would even determine which half of the space to eliminate.
>>
File: carbon (2).png (747 KB, 2230x4696)
747 KB
747 KB PNG
>>103546144
Solution is very hacky. I ran it mutliple times adjusting starting register A and step.
>>
>>103546168
i wrote it down with pen and paper and got a formula but then was too dumb to solve it
>>
File: A17.png (1.36 MB, 2048x6116)
1.36 MB
1.36 MB PNG
Unwashed Kotlin.
>>
      -------Part 1--------   -------Part 2--------
Day Time Rank Score Time Rank Score
17 00:09:33 294 0 01:16:22 441 0

Did a binary search by hand, lmao.
>>
>works on all sample input
>real input rejected.
F U eric
>>
>length of programs only goes up over time
>my program is only 16 long
so how exactly is it supposed to be a massive number? does it loop? I shouldn't even need to run 100,000 iterations to get it if it's that short, or do I misunderstand?
>>
File: confusedcat.png (433 KB, 474x442)
433 KB
433 KB PNG
is 32 bit xor fine?? or do i need 64 bit?
>>
>>103546289
>so how exactly is it supposed to be a massive number?
>he didn't write his program in human-readable format to understand what it really does
>>
>>103546289
Check your program and see how it reduces the A register. It's a huge number.
>>
>>103546301
no what I mean is, the program is supposed to output a copy of itself, right? so if the smallboy is 0,1,5,4,3,0 then the result should be 0,1,5,4,3,0 right? but if you add a high enough A register, it's going to produce a result that is something like 0,1,5,4,3,0,0,1,5,4,3,0,0,1,5,4,3,0 which is much longer than it should be. so how can it be a massive number, if it's going to produce a program that is 50-60 long?
>>
File: carbon.png (615 KB, 1250x3680)
615 KB
615 KB PNG
      --------Part 1--------   --------Part 2--------
Day Time Rank Score Time Rank Score
17 00:34:12 2444 0 01:16:03 430 0

Had a lot of bugs in part 1, mostly due to not skipping the wall of text. The solution to part 2 is suspiciously simple but it works instantly, so I'll take it.
>>
thats it im just gonna leave the bruteforce going and do some other shit
it will probably find an answer eventually
>>
>>103546322
>he never heard about the exponential function
>>
File: UNWASHED ASS.png (325 KB, 824x2718)
325 KB
325 KB PNG
>>103546271
This is the worst ASS that's ever been left UNWASHED.
>>
>absolutely sure my code should work
>wrong answer
>try someone else's code
>wrong answer (same as mine)

AAAAAAAAAAAAAA
>>
>>103546370
WHAT THE FUCK I HAD TO INCLUDE THE COMMAS FUCK ME

NIGGER
>>
File: 24_D17_C#.png (774 KB, 2372x4094)
774 KB
774 KB PNG
Good Morning Sirs! Nice of Eric to make such an easy challenge today. Still waiting on my Part 2 but that shouldn't take too long
>>
>>103545976
>>103545976
>THEY ARE, FUCK YOU ERIC
>>103545909
>Are commas part of the answer or not? I have no idea where my shit went wrong, the example is working
AHHH HHHH D: < FUUCUK THANKN YOU FUCKK YOU ERIC!
>>
I bet there are going to be some infinite loop values of A. That should be fun.
>>
can someone post part 2 my mom says i have to go to brush my teeth and go to bed :-(
>>
>>103546332
so the solution was to just discover the solution three bits at a time
>>
lol best day so far
      --------Part 1--------   --------Part 2--------
Day Time Rank Score Time Rank Score
17 00:24:14 1467 0 01:34:04 826 0

this was for you bruteforcers, dont give up

just reduced my steps size and added more output matching starting from the end as i decrease step size.
    step := 1 << 2
step = 1
low := int(163827235291136) - ((1 << 22) * 2)
low = int(164239550054400) - ((1 << 21) * 2)
low = int(164273909792768) - ((1 << 20) * 2)
low = int(164278204235776) - ((1 << 18) * 2)
low = int(164278472540160) - ((1 << 17) * 2)
low = int(164278496460800) - ((1 << 16) * 2)
low = int(164278496488960) - ((1 << 10) * 2)
low = int(164278496489088) - ((1 << 4) * 2)
.... snipped

fmt.Println(output, low)
if Equal(program, output) {
fmt.Println("MATCH", low)
}
low = low + step
if output[lll-1] == 0 && output[lll-2] == 3 && output[lll-3] == 3 && output[lll-4] == 0 &&
output[0] == 2 &&
output[1] == 4 &&
output[2] == 1 &&
output[3] == 1 &&
output[4] == 7 &&
output[5] == 5 &&
output[6] == 1 &&
output[7] == 5 &&
output[8] == 4 &&
output[9] == 2 &&
output[10] == 5 &&
output[11] == 5 {

break
}

>>
>>103546421
Just run the brooting algorithm and go to bed.
My answer is 1XXXXXXXXXXXXXX, so this shouldn't take long.
>>
File: file.png (310 KB, 602x420)
310 KB
310 KB PNG
>>103546388
>Still waiting on my Part 2 but that shouldn't take too long
Anon, I...
>>
File: worry.png (193 KB, 472x313)
193 KB
193 KB PNG
i bet there's some hacky shit you need to do specific to the puzzle input, similar to 2023 day 20.

idk what though. yup. this is a panic.
>>
>>103546433
I tried some binary search thing trying to close my low/high values.
But I wasn't sure how to reduce/increase my lo/hi
>>
>get p1 correct
>put 117440 into my program
>get 0, 0, 0, 4, 6, 3, 5, 2, 5, 2, 1, 4, 6, 7, 3, 1, 0 (not the smallboy's program)
huh?
>>
>>103546388
To compute in one second you need a ~20THz computer, and that's assuming you complete the entire program in one cycle
>>
>>103546442
The A register gets reduced by a certain value every time. Just iteratively approach that value by going down a power.
>>
>>103546444
the example changed. its not the same ex as part1.
>>
File: file.png (325 KB, 716x1002)
325 KB
325 KB PNG
>part 2
>>
guys I hope you produce idiomatic code today for your computer.

>Combo operand 7 is reserved and will not appear in valid programs.

we might use combo 7 in a future day
>>
>>103546460
>intcode is back
What a time to be alive.
>>
>>103546448
> by going down a power.

ah neat. that didn't cross my mind. will try that and see if I can get the answer again
>>
Can you not just work backwards? i.e. you know the last digit it outputs has to be the last digit of your input, and work from there? is this stupid
>>
>>103546426
from the right end. from the wrong end, you run into problems for some reason
>>
>>103546511
I tried this but the problem is that one of the operations is non-reversible.
>>
>>103546511
you wouldn't be able to know when you're dealing with a jump
>>
File: 1728640485194413.png (2.75 MB, 2569x2970)
2.75 MB
2.75 MB PNG
As usual, the intended solution is to inspect your program and see what it does. Then do a backtracking solver or something and you're done.
However, by the time I got halfway through that the leaderboard was already full so I decided to just write a nice and (somewhat) general Z3 solution instead.
>>
>>103546534
All of the inputs end in 3, 0.
>>
>>103546511
Yes you can do that. With all possibilities.
>>
I DID IT I DID IT
>>
>>103546555
Good work, anon. Now POST UNWASHED ASS
>>
I was able to find the last 7 output digits, but then it said that number (~281 trillion) was too low, and if I increase the number further to try to find the last 8th digit, i end up losing the previous matching digits
>>
>>103546580
The next digit may be lower than your first guess. Make sure you start at offset 0 for the next power.
>>
File: carbon(61).png (559 KB, 1302x2992)
559 KB
559 KB PNG
      --------Part 1--------   --------Part 2--------
Day Time Rank Score Time Rank Score
17 00:41:30 3065 0 01:52:21 1267 0
>>
File: .png (1011 KB, 1018x1312)
1011 KB
1011 KB PNG
positively miffed
>>
>>103546426
Since register A get divided by 8 by loop, I just reversed that and check the other 7 possible As. I think the first xor is for changing the value a bit by adding +/- 1 to B.
>>
>>103546555
>>103546562

I left in a bunch of debug print garbage.
I nearly "manually" found the answer digit by digit, as i figured out the rough relationship between A and the next digit very quickly. But I couldn't quite figure out how to deal with the "third instruction" of the intcode program, where the entire value of A matters for finding the next digit.
I wish I started programming my solution immediately after figuring out the relationship between register A and the input digits, rather than continuing to fuck around with the "theory" of exactly what bit manipulations were happening. I could have improved my time by like 20 minutes.
>>
>>103546633
Yeah, basically went through the exact same process and approximated it by hand to get my star.
>>
File: file.png (17 KB, 647x248)
17 KB
17 KB PNG
Reverse engineered my input program and came up with a sort of closed-form solution for part 1

Part 2 should be a lot easier now since i can find a try a value for the last program item, multiply it by 8 and try again for the next item to the left

on and on until it finds a value that works for all 16
>>
>>103546642
I semi-brooted by trying 0-7 for the next mod8 digit and pruning out the ones that don't match the program.

I would be interested in seeing the "smart" solution where you can predict exactly how the output changes with A.
>>
>>103546661
To add onto this, there's techincally only 8 possible 'seed' values of A to try, since A being less than 8 will terminate the program on the next cycle
>>
File: xarbon.png (31 KB, 692x1572)
31 KB
31 KB PNG
unwashed ass
Yet another terrible day for me, I fucking hate intcode
Bring back Advent of Math!
      -------Part 1--------   -------Part 2--------
Day Time Rank Score Time Rank Score
17 00:23:37 1406 0 02:10:26 1633 0
>>
day 17 p1 in bqn
code's not particularly interesting for a problem like this, but BQN at least has terse tests and doesn't get in the way
>>
File: 1734420054579.jpg (2.55 MB, 4000x3000)
2.55 MB
2.55 MB JPG
Advent of pen-and-paper bros, report in

(What i was trying to do on the bottom half didn't work, ignore it)
>>
File: bqn.png (161 KB, 989x1098)
161 KB
161 KB PNG
>>103546739
>>
how many digits is your part 2? im up to 152,318,285,876,145 with my BROOT and wanna know if im getting close
>>
Just woke up and from what I'm reading in the thread it's not looking good...
>>
>>103546750
10^14
>>
>>103546613
very neat solution
>>
>>103546514
I got four then two numbers working from the left (first output), then the rest is taking forever, so you're probably right
>>
>>103546750
You are, impressive speed.
>>
>>103546766
its optimized broot, im not checking literally every index and also it can exit early on obvious failures
i also skipped everything that wasnt big enough to get enough digits
>>
> I wrote it, but xor in js breaks on large number
FUCK
>>
>Found the exact value of A where I get 11 matching digits
>Can't find the 12th digit, eventually A gets too big and I lose the other 11 digits
fug
>>
>>103546750
mine needs 48 bits of representation, it's 15 digits long
>>
>>103546780
oh, fuck.
that explains why I can do part 1 but not part 2
>>
File: bruhcode.png (17 KB, 844x82)
17 KB
17 KB PNG
REMINDER
save your code we might use it in the future again.
>>
>>103546797
i will quit
>>
File: frieren-hoodie.jpg (130 KB, 1920x1080)
130 KB
130 KB JPG
>>103546797
intcode returns
>>
>>103546780
>>103546789
Lmao there is no way this is real. How can js be THIS bad.
>>
>>103546797
But I can't write
op < 3 ? op : reg[op]
if there's a third case
>>
>>103546805
floating point shit is the least bad that JS gets. Any language with a single numeric type's in a similar boat.
>>
>>103546805
JS doesn't have integer primitives, anon
Ints > 2^53 are opt-in
>>
File: 20241216_98a5b5ee5e6.jpg (2.63 MB, 4032x3024)
2.63 MB
2.63 MB JPG
>>103546743
Red 10 standing by.
>>
>>103546816
Ok i will give you guys a hint as you clearly need it. The answer is less than 2^53
>>
>>103546820
Lmaooo I kneel. Are you doing part 1 or 2?
>>
>>103546783
Notice that the computer is basically base 8, if you're trying to find the number by hand or whatever don't use base 10
>>
File: file.png (41 KB, 637x689)
41 KB
41 KB PNG
>>103546661
Holy shit I can't believe it worked

Basically entirely close-form solution that recursively bubbles its way up from the 'final' A value used in the program to the first, based on possible inputs to the floor divide that happens after each chunk of the program

0.001 seconds in normal python
>>
>>103546805
>>103546789
>>103546780
That's it, I am learning rust.
I managed to solve it using BigInt, but I hate js now, fuck it.
>>
>>103546842
very cool
>>
>>103546842
>>103546661
very nice
>>
>>103546837
That's still part 1. First filling in all the dead ends, now bigger and bigger paths that lead to the same point in higher scores or are just unnecessary detours.
I'm starting to see some denser villages, connected by longer roads.
>>
>>103546842
is that closed form solution specific to your input? You will need a different one for the examples?
>>
okay I have narrowed it down to this:
>first digit of output cycles every 1024
>nth digit of output for starting value A can be acquired by
(A/(8^n)) % 1024

now to figure out how to reverse it.. I'm almost there
>>
>>103546881
It is yes, but as far as I could tell the only part you'd need to modify is in 'calc_out' on that one long line

I'm not sure what other people's inputs look like but i imagine you'd just be changing some of those constant values around
>>
so what's the trick? I observed the output and saw that increasing register A led to increasing output so I attempted to solve by bit shifting left to right until the outputs matched, however they never do. does the value begin to oscillate or something?
>>
>>103546885
acquired by looking at that position, within the original cycle*
>>
i just had a realization, the solution probably has something to do with the specific bits in each position of the number
oh well im too tired now maybe tomorrow
>>
I can reverse everything but op 7
How the fuck am I supposed to reverse A and B being used to make C....
FUCK
>>
>>103546900
there are multiple valid values for A to recreate your program.
part2 wants the LOWEST value.
You might be cycling around them?
>>
VISIONS OF I DID IT
>>
>>103546108
My broot is still running. It's been 3 1/2 hours.
Today may be my filter lads.
>>
>>103546898
cool
>>
File: file.png (6 KB, 233x164)
6 KB
6 KB PNG
>>103546900
In my program, the execution could be broken down into 16 'blocks', one for each value being output. Each block looks like pic related according to my input, which might be slightly different for yours.

Each time one of these blocks happens, it outputs a value based on some computations and then floor divides A by 8, with A being otherwise unmodified. So basically, its just calculate -> A // 8 -> calculate -> A // 8 -> etc etc until A reaches 0.
>>
>>103546927
Do you know what number it's at?
>>
>>103546927
stay strong brootbros our time will come
>>
>>103546805
JS has only one number type, integers < 2^32 work as expected, large integers are actually floats and it breaks xor.
>>
File: tmp.png (21 KB, 1106x92)
21 KB
21 KB PNG
remove this shekelberg-dicksucker goodgoy wagecuck from the leaderboard NOW
To him: if you're here and read this hang yourself
<insert streetshitter codemonkey you'll never be a real programmer copypasta here>
>>
>>103546955
lol 2h for part1 and 3min for part2.
sus
>>
>>103546885
I tried to do that, didn't get very far though.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  try searching for A from the end, not from the start                                                                                                                                                                                                                                                                                                                                                                                                                          
>>
> Have a solution for Register A that returns an exact copy of the program
> Answer to large
Hmmm, how do I go down from here though? when do I stop?
>>
>>103546979
do what you just did to find the large value, but start small and increase your guesses to find the lowest value.
>>
>>103546955
Makes me wonder how many of the remaining unfiltered are cheaters (including reading the thread before solving) . I'm thinking 80% of us are legit, but maybe I'm being too optimistic.
>>
>>103546979
>> Have a solution for Register A that returns an exact copy of the program
Your solution should incrementally produce a set of values, and then you get the smallest one.
>>
>instruction set emulator
FINALLY something I've actually been working on at my workplace
>>
I feel like a genius for figuring out the pattern, although I'm sure others did faster.

Multiplying A by 8 causes your program to output the same digits as before, but with a new digit on the left. And adding to A by up to 7 adjusts the digit on the left without affecting the others. So by incrementing to get things correct, then multiplying by 8, you can start working on the new digit and repeat. Of course, you may have to backtrack in some cases, but this is a lightning fast approach.
>>
>>103547007
>Of course, you may have to backtrack in some cases,
If it wasn't for this, i would have been like top 200 or something. I spent way too long trying to "solve" it to avoid backtracking. When I should have just brooted.
>>
>>103547007
you can start with the last instruction retard then you don't need to backtrack
>>
File: hqdefault.jpg (21 KB, 480x360)
21 KB
21 KB JPG
broot bros I scanned up to INT_MAX and did not find the result. time to bump those bits to 64
>>
>>103546932
No. I didn't print because I didn't want to slow down. Now I don't want to ctrl C because I waited too long lmao.
>>
>>103547032
You only get 8 chances to increment A to get the first digit correct. You can do this 8 times and the first digit still may not match, forcing you to backtrack.

It's pretty negligible though.
>>
>>103547032
You do. Or at least you did for my input
>source: manually got to digit 10 or so before no bits were valid for digit 11 and I had to actually write a program to solve it
>>
>>103547046
What i do for my long broots is i have it print every million or something. That way i can estimate how long it's taking.
>>
>>103547056
>>103547050
I didn't have to backtrack
>>
>>103547032
>>103547007
am I wrong? Mine has a lot of backtracking even if starting with the 8^15 term, then 8^14 term, then 8^13 term etc.
>>
>>103547044
Mine was:
105'981'155'XXX'XXX
>>
>>103547044
Mine is > 2^48, so good luck
>>
>>103546916
>How the fuck am I supposed to reverse A and B being used to make C....
Op 7 doesn't use B at all
>>
>>103546927
Just keep waiting. You'll definitely get the answer before the heat death of the universe.
>>
>>103547094
>>103547115
I optimized it such as I can scan to INT_MAX in 50 seconds.
Gonna try further and rewrite the input as C program, should speed it up by a lot.
Never give up.
>>
>>103546990
>>103547004
> manually find each answer then reduce the modulus 8 to find the lowest answer
> Here's your gold star!
https://www.youtube.com/watch?v=vu2NK5REvWM
>>
File: 223031115_363196.jpg (37 KB, 1280x720)
37 KB
37 KB JPG
>>103546008
>me give answer, incorrect
>wtf.jpg look for 5 minutes at the code like a retarded
>find i give the answer with a coma at last place
>>
>>103546780
Use a typed array of one element:
{
const a = new BigUint64Array([ 12105981156665749n ]);
Math.floor(a / 8) * 8 + (a % 8 ^ 5);
}
>>
>>103547157
This also works:
{
const a = new BigUint64Array([ 12105981156665749n ]);
Math.floor(a / 8) * 8 + ((a & 7) ^ 5);
}
>>
File: file.png (174 KB, 659x432)
174 KB
174 KB PNG
>>
>>103546927
You need to skip values. Print the numbers in octal base and start skipping 9 bits, make sure to set the lowest bits to the bit pattern that satisfy your puzzle (print those A values that output the first valid values). I went up to 30 bits, so that makes the brooting up to a billion times faster.

for (N i = 1; ; ++i) {
// ---------------------> bit pattern in octal
const N oa = (i << (10*3)) | 05110264632ull;
N a = oa, b, c;
out.clear();
while (a) {
b = a & 7;
b = b xor 5;
c = a >> b;
b = b xor 6;
a = a >> 3;
b = b xor c;
out += char('0' + (b & 7));
}
if ((i & 0xFFFFFF) == 0) std::cout << "....." << i << std::endl;
if (!target.starts_with(out)) continue;

std::cout << out << " <- 0";
out.clear();
for (N n = oa; n;) {
out = char('0' + (n & 7)) + out;
n >>= 3;
}
std::cout << out << " decimal: " << oa << std::endl;
}

>>
>>103547207
>so that makes the brooting up to a billion times faster.
hmm feels like cheating
>>
File: gorilla rage.png (138 KB, 500x502)
138 KB
138 KB PNG
>I looked at the input for hours
>I tried searching for any pattern I could
>I printed out every step, every output, poured over everything trying to find the answer
>I had simplified the interpreter into only the instructions that mattered and translated it into my program so that I could read exactly what it was doing in a readable language
>I studied the XORs and that one division operator, thinking maybe there's a way to simplify it more, maybe you can combine XORs in a way I don't understand
>but that one division operator with register C, it's just too random, there's no way to predict how the output will turn out with that instruction there
>I knew exactly how the program worked from each crook and cranny and the general shape of the output from a given input but I just couldn't find that one secret ingredient to finally crack it open like an egg and reverse engineer it completely

>revisit my "recursive search by checking if the end of the output is equal to the end of the instructions" idea
>print out what the output is when they're getting close to matching
>mfw there's negative numbers in there
>mfw I was using JavaScript's XOR operator
>mfw I realize the logic operators assume signed 32 bits and 1 | 2147483648 results in -2147483647
>mfw I replaced both values with bigints and my solution worked immediately
>mfw I solved the problem hours ago
>>
>>103547224
wonder if any jsbabs will whinge at eric about it
>>
>>103546780
fugggg, updated it to use bigint and now works
>>
File: carbon (13).png (236 KB, 822x1414)
236 KB
236 KB PNG
Python washed. I'm really happy!
>>
>>103547263
thanks chatgpt
>>
>>103547271
Haha, I do have it help with formatting after I've gotten the stars. The logic is all me though!
>>
File: file.png (369 KB, 609x609)
369 KB
369 KB PNG
>>
I am never using JS for AOC ever again after this year. Will probably switch to Python
>>
I didn't solve it
from z3 import *

program = [2, 4, 1, 1, 7, 5, 0, 3, 1, 4, 4, 4, 5, 5, 3, 0]


def f(a):
b, c = BitVecVal(0, 64), BitVecVal(0, 64)
result = Array("r", BitVecSort(4), BitVecSort(3))
for i in range(len(program)):
b = a & 7
b = b ^ 1
c = a >> b
a = a >> 3
b = b ^ 4
b = b ^ c
result = Store(result, i, Extract(2, 0, b & 7))
return result


a = BitVec("a", 64)
o = Optimize()
for i in range(len(program)):
o.add(Select(f(a), i) == program[i])
o.minimize(a)
o.check()
print(o.model()[a])
>>
File: IMG_3951.jpg (98 KB, 976x850)
98 KB
98 KB JPG
>>103547224
sorry anon. hate it when that kind of thing happens.
>>
>>103547314
dumb frogposter
>>
>>103547314
Kill yourself
>>
File: d17.png (794 KB, 1506x5548)
794 KB
794 KB PNG
Yep, not filtered.
7,2,5,1,7,5,0,3,1,7,4,1,5,5,3,0 190615597431688
d2
7,3,5,1,7,5,0,3,1,7,4,1,5,5,3,0 190615597431752
d2
7,4,1,2,7,5,0,3,1,7,4,1,5,5,3,0 190615597431816
a
5,4,1,2,7,5,0,3,1,7,4,1,5,5,3,0 190615597431817
a
5,4,1,2,7,5,0,3,1,7,4,1,5,5,3,0 190615597431818
a
3,4,1,2,7,5,0,3,1,7,4,1,5,5,3,0 190615597431819
a
1,4,1,2,7,5,0,3,1,7,4,1,5,5,3,0 190615597431820
a
0,4,1,2,7,5,0,3,1,7,4,1,5,5,3,0 190615597431821
a
3,4,1,2,7,5,0,3,1,7,4,1,5,5,3,0 190615597431822
a
2,4,1,2,7,5,0,3,1,7,4,1,5,5,3,0 190615597431823
190615597431823
Runtime:> 71.408s
>>
reddit niggas really say "right shifted by three bits" instead of "divided by 8" huh
>>
>>103547339
Anon did you take math first class elementary school?
Do you know what division is?
>>
>>103547347
no
>>
File: file.png (370 KB, 1198x2950)
370 KB
370 KB PNG
>>103546842
I think I basically did the same thing except without a closed form solution. takes 0.002 s.
>>
File: animegirlstocksgoup.png (462 KB, 720x544)
462 KB
462 KB PNG
> Both parts of this puzzle are complete! They provide two gold stars: **
just managed to solve it manually. don't (You) me.
>>
>>103547339
You mean programmers?
>>
>>103547367
lemme guess you also say "orthogonal"
>>
Part 2 is just too hard for me. I'm filtered.
>>
>>103547372
Part 2 doesn't have a generic solution.
>>
>>103547371
Yes
>>
File: bruhcode1.png (17 KB, 855x87)
17 KB
17 KB PNG
reminder. save your computer for later
>>
ah yes, input 2 which has only one jump at the end and at step (i+1) you only depend on the a from step (i)
>>
>>103547371
and "orthonormal" yeah
>>
>>103547289
Based Z3gger.
The right tool for the right job.
>>
>>103547378
Okay? It's still too hard for me.
>>
File: count-dracula-eight.gif (1.66 MB, 400x224)
1.66 MB
1.66 MB GIF
>>
File: file.png (5 KB, 1139x52)
5 KB
5 KB PNG
is oofmatoes an LLM cheater?
>>
>>103547382
eric just couldn't think of a fun thing to do for 7, don't get your hopes up
>>
>>103546098
>>103546539
>>103546633
>>103546745
>>103547289
>>103547334
>>103547356
That will be $150,000 each.
>>
File: day17.png (440 KB, 1788x3192)
440 KB
440 KB PNG
$ mix run -e 'AOC.main()' -- 2024 17 b input/real
3,6,7,0,5,7,3,1,4
164278496489149

Ran in 0.429ms


Might wash later, the simulation loop is really ugly.
>>
>>103547378
I'm somewhat confident there's a pseudo math generic solution to this. Currently trying to work it out, I'm close
>>
>>103547427
elves are gonna invent memory protection and SMT
>>
>>103547477
>and SMT
they're gonna summon demons and cause the apocalypse?
>>
>>103547461
Eric's input has a math solution, but a general input doesn't have a solution that is not bruteforce.
>>
>>103547461
Is there? I think the computer is Turing complete, since the registers are specified to be of infinite length and bits can be used to track state and control the pointer.
>>
how the fuck do I solve it if changing just the 3 leftmost bits of A changes all the output so after a few recursive steps it finds no solution
>>
File: img-2024-12-17-10-41-15.png (1.39 MB, 5654x4362)
1.39 MB
1.39 MB PNG
idiomatic Rust solution
>>
>>103547518
>changing just the 3 leftmost bits of A changes all the output
Dude, what?
The program is literally
START
PRINT(FUN(A))
A = A / 8
IF (A > 0) GOTO START
>>
>>103547365
>>
>>103547411
oh nonono...
>>
>>103547288
same, im tired of these python niggas in the top of the leaderboards. im gonna be a pythonchud next year
>>
>>103547537
I'm talking about part 2
>>
File: day9silver.png (13 KB, 732x569)
13 KB
13 KB PNG
Let's fucking go.
>>
>>103547567
>day 9
>>
>>103547566
How about you change the three rightmost bits?
>>
>>103547571
>implying filtered
>>
>>103547579
how about you change my diaper faggot
>>
>>103547567
BASEDboy!
LFG!
>>
File: day9silver.webm (235 KB, 721x554)
235 KB
235 KB WEBM
It is fucking fast, too. And doesn't modify the filesystem table in memory, so I can start gold without rebuilding it.
>>
>>103547138
Op 7:
C = A / (2 ^ combo(operand))
In my input , it's 7, 5
Combo(5) is B
>>
>your answer is too low
>plug answer into part 1 to double check that it produces the original program
>it does

I am going to go insane
>>
>>103547614
hot hot
>>
File: filtered.mp4 (1.7 MB, 720x720)
1.7 MB
1.7 MB MP4
>>103547611
>diaperfag is filtered
Based Eric.
>>
>>103547621
Did you check if you actually get the right computer output in part 2? I had the same issue, because I put the upper limit too low and it just returned that.
>>
>>103547621
>produces the original program
>>
so where's the bigboy?
int64lets need not apply
>>
How the fuck do digits downstream change

I got something like A = A / 8 at the end of my prog
So I've been trying to slowly reconstruct the output by increasing A by 1 and as expected it changes the first output while the rest remain the same
Then I do A = A * 8 and try the next output

But at like 6 deep it changes shit downstream
HOW THE FUCK
>>
>>103547653
overflow or something
>>
>>103547664
Should it even be possible to get negative numbers out?
If so that means I've been bashing my head against my languages bitwise xor this whole time
>>
New AoC theme music
https://www.youtube.com/watch?v=HgzGwKwLmgM
>>
>>103547629
ai be wildin fr
>>
>>103547684
non-cancer music
>>
>>103547278
Haha. You're filtered.
>>
>>103547653
Js?
>>
>>103547711
Can't believe I didn't realise it sooner....
Killing myself promptly
>>
>divide by 2^n
right shift n times
>mod by 8
bitwise and 7
>>
>>103547684
Gay.
>>
>>103547754
ok
>>
there's a pattern and I'm gonna crack it
>>
I bet a full bruteforce would take under an hour on GPU
>>
File: image.png (637 KB, 1077x815)
637 KB
637 KB PNG
my humble BQN solution for day 17.

only does silver. for gold i have some hardcoded stuff that works only on my input. haven't found a good way to generalize it cleanly.
>>
>>103547513
It's not Turing complete.
Every instruction generates an output with either the same or a smaller number of bits than its largest input. Thus, only a finite number of states are available.
In particular, you can solve the halting problem just by calculating an upper bound on the number of available states and running the program for that long.
>>
>finally try to solve p2 intelligently
>code gets the answer I got for round one and one of the answers I got for round two
>no possible solutions by round 3
I'm getting there!
>>
Need a good meme image for new thread
>>
>>103547951
I've spent the last two hours looking up pics about the number 8, power series and what not and I can't find anything.
Just go with >>103547281
>>
File: Ernie8Salesman.jpg (13 KB, 460x327)
13 KB
13 KB JPG
>>103547976
>pics about the number 8
>>
>>103547754
>divide by 2^n
>right shift n times
Interdasting, that means I don't need to generate a power of two each time. Thanks anon
>>
File: the number 8.jpg (20 KB, 273x200)
20 KB
20 KB JPG
>>103547951
>>
File: today_i_will_broot.png (76 KB, 665x278)
76 KB
76 KB PNG
>>103547951
>>
File: manualp2.png (338 KB, 700x495)
338 KB
338 KB PNG
>>103547951
me manually building up my solution for p2
>pic related
>>
Is there something obvious i'm missing here? The answer i get back is close to the original instruction set, but there are always a few numbers it can't find a solution for on each iteration. I'm going fucking insane.
>>
make some smallboys that change the program fundamentally but are still valid inputs by following all of eric's rules and having existing silver and gold answers
>>
very nice problem today
one of those problems where you keep making observations about the input and it gets simpler and simpler until the whole thing unravels and the solution is trivial
good puzzle for once, Eric
i have a smile on my face
>>
>>103548081
smallboy:
Register A: 2024
Register B: 0
Register C: 0

Program: 0,3,5,4,3,0


part1
5,7,3,0


part2
117440
>>
File: file.png (432 KB, 1464x2230)
432 KB
432 KB PNG
>>103546909
bros i made it
im not filtered
      -------Part 1--------   -------Part 2--------
Day Time Rank Score Time Rank Score
17 00:21:53 1245 0 06:16:45 5138 0

printing out the values as binary did help a lot
>>
>>103547411
OVERNIGHT BROOTTTTTT
>>
>>103547411
evidently lol
>>
>>103548091
Fuck you, today was extremely bad.
Nothing interesting about it, completely boring.
>>
>>103548190
What was your time?
>>
what's part 2? I can't do part 1 yet and want to think of a solution for part 2 as well while I wait
>>
>>103548190
hello oofmatoes
>>
I got distracted

New bread
>>103548198
>>103548198
>>103548198
>>
auto solve2(T)(T computer)
{
auto target = computer.program;
auto targetRetro = target.retro.array;

long start = (8^^(target.length-1));
long end = (8^^(target.length));

long current = start;
long step = (end - start)/(256);
long lastMatchlength;

while (current < end)
{
computer.reset();
computer.registerA = current;
int[] output = computer.run();

if (output == target)
return current;

// How many of the numbers at the end of the output match the back of program array
auto matches = commonPrefix(output.retro, targetRetro).length;
if (matches > lastMatchlength)
{
// Getting Closer to target
current -= step; // Lets Step Back incase we missed it
step >>= 3;
step = max(step, 1);
lastMatchlength = matches;
continue;
}
current += step;
}

return 0L;
}

Its Nasty, Brooty but it works.
>>
>>103548203
quine
>>
>>103548203
Given the same program and a different output, find the initial register state that results in the new output.
>>
>>103548203
What is the lowest positive initial value for register A that causes the program to output a copy of itself?
>>
>>103548199
2 hours, I wasted more than an hour from my life before looking at my specific input.
I don't get it what do you find "interesting" about it?
>>
>>103547411
can a nigga not skip a question
>>
>>103547653
so just to confirm im a dumb js fag and this should never actually happen if my program executes properly
>>
>>103548251
>>103548217



[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.