[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] [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: 1765315434583222.png (299 KB, 521x687)
299 KB
299 KB PNG
finally getting interesting 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:
224303-2c132471
anonymous-only leaderboard:
383378-dd1e2041

Previous thread: >>107490190
>>
File: eric.jpg (22 KB, 460x460)
22 KB
22 KB JPG
>>107498650
APOLOGIZE.
>>
File: kinds.png (2.87 MB, 1536x1024)
2.87 MB
2.87 MB PNG
There are three types of people who do advent of code

Type 1: The Engineer
For these people, the goal is to write a program that solves the problem for every possible case efficiently and elegantly. The Engineer cares about things like memory safety, time complexity, and "washed" code.

Type 2: The Hacker
For The Hacker, the goal is to get the right answers for their input. They might use tactics like manual or script-assisted inspection of their input file, brute forcing, or even AI.

Type 3: The Artist
The Artist's priority is solving the problem in a unique, amusing or aesthetically pleasing way. They might use esoteric programming languages, impractically long one-liners or obscure hardware.

Which type are you? Let me know in the comments below.
>>
>>107498745
The only way I am apologizing for only 12 puzzles is if the last 3 are so hard that im filtered. This will not happen.
>>
>>107498764
Hacker at midnight, then artist the following day if the problem pleases me. Its Eric's job to force be to be the Engineer, and he has dropped the ball hard the past few years.
>>
>>107498764
>Which type are you? Let me know in the comments below.
This jeet thinks he's farming on X.
>>
>>107498745
I will only apologize if there is a big reveal on the 13th day that yes, we are indeed getting puzzles all the way to Christmas
>>
>>107498764
I start out as the Artist, then transition into the Engineer as the problems get harder, then finally am forced to become the Hacker a day or two before I get filtered.
>>
>>107498764
god I hope the gasline to your house blows up
>>
File: bqn.png (71 KB, 1059x508)
71 KB
71 KB PNG
>>107498358
really? but part2 was only a 12-line problem
>>
>>107498886
Rude
>>
File: 84937949.png (4 KB, 375x539)
4 KB
4 KB PNG
post yfw the puzzles starts with
>using the intcode computer you created back in 2019...
>>
>>107498764
>Hacker
>They might use... AI
no that's the fourth type of AoC person: the cheater. includes vibe coders and people who get frustrated and just copy-paste someone else's solution
>>
File: 1735754505074644.png (146 KB, 560x396)
146 KB
146 KB PNG
>>107498764
>>
>>107498896
idk, part of it was i liked the lineup on the /a/ stream so if anything took me longer than 30 minutes i was pretty over it

this year i'm unemployed and the /a/ stream lineup is dogshit, so plenty of time to beat my head against the wall
>>
>>107498936
>and just copy-paste someone else's solution
I refuse to belive this.
>>
>>107498963
Someone admitted to typing out someone else's solution in the last thread. Just imagine what people aren't admitting to
>>
where's today's slop comic? enjoyed the one yesterday, idk if they made more before that, i usually only show up to the threads 10 minutes before puzz drop
>>
>>107498963
if you think people are too "honorable" for this, i have a bridge to sell you
>>
>>107498987
>>107497012
>>
>>107498963
it's no coincidence that once one really good solution gets posted where it can be copy/pasted a bunch of people magically get unfiltered. sometimes they even post their solution which is a clear modification/"obfuscation" of someone elses
>>
>>107498963
Believe it!
>>
>>107499022
I don't read solutions before I finish mine, but I do read through the thread for ideas when I get really stuck. Good enough for me.
>>
>>107499047
that's natural. only autistic savants would say you're filtered if that's truly all you do
>>
>>107499022
I don't open aocg until I get both the stars. As simple as that. Don't want to ruin whatever little fun this year has been.
>>
>>107499069
i just log off a minute before, maximise fun
>>
File: day9go.png (337 KB, 2204x1360)
337 KB
337 KB PNG
Baby's eighth Go program. This one was rough, brothers.
It stack overflows on bigboy, and no, I'm not fixing it.
>>
>>107498979
>typing out someone else's solution
I had ChatGPT transcribe it and goth both stars lol
>>
>>107499022
This is why I post my solutions.
They're so bad no one is going to copy them and it's obvious I didn't copy anyone.
>>
>>107499090
I didn't read this line at first, and wasted a huge amount of time trying to find the biggest rectangle possible.
>The rectangle you choose still must have red tiles in opposite corners, but any other tiles it includes must now be red or green. This significantly limits your options.
I think I got it working, but it took a whole second on Eric's input, and ofc the answer was wrong.
>>
>>107498764
kys
AoC is dead enough, we don’t need you faggy pajeets raping the corpse, though I know you saarrs can’t resist raping
>>
>>107499128
>get both stars
>change code logic to subtly make it wrong
>upload wrong solution

is this the real meta? I'd put it into play but (((they))) banned me from the aoc subreddit
>>
File: IMG_0606.jpg (29 KB, 474x474)
29 KB
29 KB JPG
>>107498764
>>107499022
You heard of Advent Coding but have you tried Advent Children
>>
>>107499090
>240 line solution in a high level, garbage collected language

Time to switch to python or c++
>>
>>107499196
It's only so much because I solved it probably the stupidest way possible.
>>
>>107499173
Actually if people really are copying solutions verbatim you should slip in some code to remove their home directory. Simple b64 obfuscation would probably be enough.
>>
>>107499234
>pajeets taking measure against pajeets
this board is so dead
>>
>>107499282
lmfao

>>107499234
>accidentally runs the program without removing the malware
>>
>>107499282
The cheating jeet recoils in anger... he has been found out, and know for certain they plot against him. To aid his escape, he accusses his accusers of the crimes he himself is guilty of; "bloody pajeets!" he curses as he slips away into the musty streets of Mumbai.
>>
>>107498896
what am i seeing?
>>
>>107499346
>cheating jeet recoils in anger
immediate classic, let out a sensible chuckle
>>
Can anyone explain to me why the idiomaticfag calls his code "idiomatic"? Are the conventions and best practices of rust to write as much as possible as one-liners?
>>
>>107499416
rustfmt breaks it up anyway so it's not a one liner, ig it's become a synonym for elegant though
>>
By eliminating tests on rectangles smaller than the largest found so far and ones that have points inside them, I have cut my solution time from 13 minutes to 10 seconds.
>>
>>107499433
almost in time to get filtered by today's puzzle, welcome
>>
I NEED TO SHIT
>>
>>107499416
It's called ironic shitposting. Non-westerners and autistics tend to struggle with it.
>>
>>107499416
not him, but no, it is to not use unsafe, use iterators (instead of for loops), let type inference do its work, use Option where it makes sense and transformations on it like .map, etc. I think one liners are just to make the code look concise, otherwise rustfmt breaks a line on each method chain when working with iterators.

>>107499453
I think anon does it unironically
>>
File: file.png (79 KB, 1200x1200)
79 KB
79 KB PNG
The Wall.
>>
File: file.png (70 KB, 1200x1200)
70 KB
70 KB PNG
In theaters December 9th.
>>
>>107499047
Same, I avoid these threads until I solve it and if I can’t I ask for a hint without looking at any posts. Part of the reward of solving it is getting to read the thread and see (usually better) solutions by others, like a self-enforced Project Euler setup.
>>
>>107499433
Damn that is such an obvious optimization I feel dumb now for not adding it.
>>
>>107498998
based, thank you
>>
>>107499433
>>107499489
Just sort the rectangles from largest to smallest and stop at the the first valid rectangle
>>
>>107499480
now do one with her tits out
>>
>>107499472
>>107499480
you're what's keeping me going, anon. thank you for your service.
>>
>>107499433
yep, i had that and my shitty python ran pretty quick. also saw people floodfilling the interior and exterior of the shape which really isn't necessary, one is sufficient
>>
>>107499196
202 lines here: >>107497852
this go also has stuff like _ = vx that's just there to satisfy the compiler while was working on the rest of the program. Zig does this shit too, but goes further and refuses to compile if you go on to use the variable, so published Zig never has this stuff
it also be compressed by combining assignments, not really a big deal
>>107499090
use log for output instead of fmt and you get some cheap timestamps + log.Fatal(), instead of print and return
for i := range px {} gives you indexes
>>107499480
lotta nice details here
>>
>>107499483
the most dangerous period is deep into a 3h brute and you're confident it'll work, so you casually check the thread
>>
>>107499472
>>107499480
I'd buy opening nighttickets!
>>
>>107499548
>log
Thanks, I will use this next time.
>for i := range px {}
Yeah, but sometimes I have an inner nested loop that starts at i+1, and then they don't match.
>>
I am here to see the carnage. I hope filter-anon wasn't filtered.
>>
>>107499584
he posted earlier saying he wouldn't be here for puzzle drop tonight but that he was looking forward to making the graph for yesterday's puzzle
>>
>>107499511
From part one you mean. Damn, that it obvious, too.
>>
>>107499463
The rest I get, but is making the code look concise idiomatic in rust? If it is possible to write something much more complicated than aoc solutions in couple of one-liners, which they still are, even if you insert newlines, is it actually idiomatic rust? Let's say you chain 100 methods, 1000, 10000?
>>
>>107499358
BQN
Merge is a function (capital letter) defined on that one line
x and r are its left and right parameters
the function starts with a conditional: is the length of x (actually r - probably only bound that so that the r could be used deeper in a nested context with its own twitter-x) less than or equal to the count of zero bits in w (x)? if so it does that first thing; if not it returns the arguments in an array
The ? and ; in the last sentence have the same meaning in BQN
>>
>>107499595
What the fuck do you think, anon? No.
>>
>>107499595
how is that relevant here
>>
>>107499626
How is it not?
>>
>>107499416
from google:
>Idiomatic Rust code refers to code written in a way that aligns with the conventions, best practices, and common patterns of the Rust programming language and its community. It prioritizes clarity, safety, and performance by leveraging Rust's unique features.

so basically it's the rust equivalent of calling your python code "pythonic"
>>
File: 1757328121678500.png (330 KB, 534x330)
330 KB
330 KB PNG
>>107499508
I like the little filtered sticker
>>
File: day9stretch.png (2.39 MB, 8760x996)
2.39 MB
2.39 MB PNG
Not sure why people are calling day 9 some big """""filter""""". It is literally 1 list comprehension in python
>>
>>107499595
between a master at work, and an amateur at work, which do you appreciate more? Do you like enjoy pro games more or less than games where the winner is decided by whichever team was last to try and throw the game?
You could take nearly any programming language and write it to look like an educational program in Pascal. There are a bunch of earlier posts that are just "d in the style of this earlier code". Deliberately unsafe Rust that uses pointers is fun to see, too.

Idiomatic Rust anon is showing off the Rust stdlib. It's actually really nice, not full of embarrassments like C++ or D.
>>
>>107499649
>pythonic
yeah it's the word that people used before Python came up with a stupid and self-indulgent word for it
>>
>>107499690
>acting like you aren't Idiomatic Rust-fag
>>
>>107499656
Is opening the same file 7 (seven) times in a single list comprehension idiomatic python?
>>
>>107499699
I wrote all the D posts and stopped liking Rust after I deployed a server in it and finally had to hack on libraries and not just use them.
400-line warp errors were a trip as well.
>>
>>107499706
time/space tradeoff
>>
>>107499706
I was trying to get rid of those. Most of the file reads are just to get the number of lines of the input so I can build the list of pairs, assignments arent allowed in the iterable part of list comprehensions for some reason. I could hardcode it but thats cheating.
>>
>>107499472
>>107499480
I was worried you wouldn't show up in time anon
thank you
>>
>>107499728
amazing
how many seconds does it take to solve p2
>>
>>107499762
it's only one line of Python, type it out yourself
>>
>>107499656
Not sure why people are calling Advent of Code some big """""filter""""". It is literally 1 copy+paste to Chat GPT
>>
>20 minutes to go

HOLD THE LINE BROS
>>
>>107499728
you can try __import__("itertools").combinations(open(0), 2)
share the code and I will try to suggest improvements
>>
remember when aoc was fun? now the puzzles are either a) boring and easy b) boring and frustrating
>>
>>107499785
member INTCODE
>>
>>107499511
this didnt help me with this particular bigboy, still 10 minutes
however now it takes 1 minute to sort and 9 min with main algorithm. in any case im stupid for not thinking of this
>>
>>107499773
We need an Advent of AI where AI use is encouraged but the problems are extremely elaborate and require 1000+ lines of vibecode to solve.
>>
>>107499799
that might just be better aoc lol. if it will be difficult for LLMs then it will be more fun for humans too
>>
>>107497092
i think he's ngmi :(
>>
I finally got it
- sort rectangles by size
- check if any edges are inside the rectangle
That's it
This 5 minute timeout is killing me. I am a retard but at least I didn't hit the wall.
>>
>>107499808
works for the input but not for edge cases. anywho, glad one more joins for another day
>>
File: white.jpg (456 KB, 2560x1683)
456 KB
456 KB JPG
>>107499792
now that was a good year
*sip*
>>
File: WALL_INCOMING.jpg (157 KB, 462x260)
157 KB
157 KB JPG
TONIGHT'S THE NIGHT

day 10 will make day 9 look like a fucking joke
>>
>>107499821
Give me an edge case it fails on if you can, I think it's pretty solid.
>>
>>107499792
>that day eric wrote breakout for the intcode computer
>you could either make a UI and beat it for the answer or code some ai to beat it and get the answer
nothing will top that year and i pity the people who never did it
>>
>>107499762
>>107499781
here is the line
print(max(map(lambda p:(abs(p[1][1]-p[0][1])+1)*(abs(p[1][0]-p[0][0])+1),[((coords := [list(map(int,line.split(","))) for line in open("input.txt").read().splitlines()])[i],coords[j]) for i in range(len(open("input.txt").read().splitlines())) for j in range(i+1,len(open("input.txt").read().splitlines()))])), max(map(lambda p: (abs(p[1][1]-p[0][1])+1)*(abs(p[1][0]-p[0][0])+1) if not(any([(max((xrange := [min((p[0])[0],(p[1])[0])+1,max(p[0][0],p[1][0])-1])[0],(sxrange := [min(s[0][0],s[1][0]),max(s[0][0],s[1][0])])[0]) <= min(xrange[1],sxrange[1])) and (max((yrange := [min(p[0][1],p[1][1])+1,max(p[0][1],p[1][1])-1])[0],(syrange := [min(s[0][1],s[1][1]),max(s[0][1],s[1][1])])[0]) <= min(yrange[1],syrange[1])) for s in [[coords[i-1],coords[i]] for i in range(1,len(open("input.txt").read().splitlines()))] + [[coords[-1],coords[0]]]])) else 0,[((coords := [list(map(int,line.split(","))) for line in open("input.txt").read().splitlines()])[i],coords[j]) for i in range(len(open("input.txt").read().splitlines())) for j in range(i+1,len(open("input.txt").read().splitlines()))])))
[\code]

Its just my solution >>107489511
squished into one line
>>
File: 1761459001546683.png (6 KB, 400x400)
6 KB
6 KB PNG
>>107499838
>>
>>107499838
1,1
10,1
10,10
6,10
6,4
5,4
6,10
1,10
the correct answer is 100 but you'll exclude that
>>
>>107499838
couldn't the input have been some huge concave object like a C where your corners would be the only parts on the boundary?
>>
>>107499832
rolling for dynamic programming
>>
>>107499844
I think the AI was literally "move pad to ball", an absolutely fun puzzle nevertheless.
>>
>>107499856
>5,4
>6,10
you are indian
>>
>>107499870
>Fatal error: exception Failure("diagonal")
my code caught that though
5,4
5,10
>>
>>107499838
1,1
8,1
8,3
3,3
3,4
8,4
8,6
1,6

should be 48 48
>>
>>107499869
i think mine was a little more complicated to account for wall bounces but that may not have been necessary. but still cool anyway and i assume way more work for eric than these puzzles
>>
>>107499848
thanks, i get similar times on my machine
>>
File: showtime.jpg (46 KB, 640x480)
46 KB
46 KB JPG
www.youtube.com/watch?v=hjGZLnja1o8
>>
>>107499897
cancer music
>>
File: mokou-showtime.jpg (130 KB, 440x518)
130 KB
130 KB JPG
>>
>christmas tree: plugged in
>second monitor: showing /a/ stream
>bladder and balls: empty
yep, it's aoc time
>>
>>107499844
Yeah the Intcode problems were definitely unique not only because they spanned multiple days but because of puzzles like arkanoid or the jumping robot where it was more like you had to program a CPU to beat a game instead of solving a problem in the input
>>
> 5 minoots

HOLD
HOLD
>>
Going for some classic ambient music today.
https://www.youtube.com/watch?v=-9pgIVcB3rk
>>
5 hours of sleep send help this is not healthy
>>
File: dance.gif (402 KB, 544x384)
402 KB
402 KB GIF
https://files.catbox.moe/tuevnx.mp4
>Code is Ticking Like a Clock Tonighttt
>>
>>107499904
I always mean to check in on the /a/ stream but i forget about it every year. you just reminded me of it now.
>>
>>107499904
What is the /a/ stream? Sounds comfy
>>
>>107499906
a glimpse at what AOC should have been
and it was ruined by reddit whiners crying its unfair
>>
>>107499910
I CAN'T HOLD IT IN, I HAVE TO SHIT
>>
>>107499904
>Depleting your zinc reserves... ngmi.
>>
>>107499927
never watched it before, how long does it run?
>>
>>107499792
intcode was fun but 2018 was honestly just as good
>>
>>107499927
>>107499928

lineup is ass this year, don't bother
>>
>>107499916
i wanna listen to https://www.youtube.com/watch?v=lJ71NUL9Cp4 but i think i'll fall asleep
>>
>>107499930
what did redditors think unfair?
>>
math trick incoming
>>
>>107499947
Elves and goblins fighting was good
>>
>>107499951
when shitters got filtered on one day they couldnt do future days because it used the same intcode solution
>>
>>107499953
please no CRT
>>
FUCK
>>
I am not going to get filtered!
>>
the great filter
>>
FUCK YEAH
>>
oh no
>>
>>107499956
bigger thing i think was people produced shitty code for their first intcode solution and then ragequit when they realized they had to pay for their sins later. too lazy to clean it up during the day i guess
>>
>>107499849
>>107499861
Ah, good point

>>107499856
>>107499870

>>107499879
Another good point, I excluded this case mentally after ruling out brute force
>>
[.##.]
l-lewd
also
FUCK
>>
oh fuck its this day. This always takes me 3 hours. No I will NOT be importing solution btw.
>>
>>107499966
FUCK I am am definitely filtered.
>>
oh shit
>>
>there's no such thing as "0.5 presses"
ERIIIIIIC
>>
>>107499986
[.##.]
[...#.]
[.###.#]

naked yoga, in my Christian contest?
>>
I give up
>>
Shit. Don't even know how to start part 1.
Oh, right. I can just broot it
>>
>>107500022
good fucking luck
>>107500015
i'm out too, i'm not worthy
>>
>(0,3,4) means that
> first, fourth, and fifth indicator lights
Dijkstra was wrong
>>
what the fuck am i reading
>>
Circuits, wires, joltages...
We are so back EE bros
>>
oh, I hate these puzzles
only thing worse are the slider puzzles
>>
File: rmsy7hvucpvf1.png (50 KB, 492x767)
50 KB
50 KB PNG
>see wall of text
>brain switches off
>>
File: 1764839348278368.jpg (89 KB, 1280x720)
89 KB
89 KB JPG
>there's no such thing as "0.5 presses"
>>
I'm still trying to parse the input
>>
is this brootable?
>>
>>107500094
part 1 easily, not part 2
>>
yet another dynamic programming problem
>>
>>107500094
nope
>>
>>107500084
just split the line by spaces and check the first char of each substring? for once eric didn't put spaces after his commas
>>
>>107500041
I might need the whole day for this one EEbro.....
>>
File: 1748040235180126.jpg (7 KB, 242x209)
7 KB
7 KB JPG
>>
>part 1 is taking time to broot
oh I am so fucked
>>
>>107500100
i dont believe you, my part 2 broot WILL finish
>>
File: pepepraying.gif (173 KB, 220x208)
173 KB
173 KB GIF
full court gauss jordan shot, all net no rim
>>
parsed!
while(data[i] != ' ') {
if(data[i] == '#')
machines[machines_count].lights_target |= 1 << machines[machines_count].lights_count;
if(data[i] == '.' || data[i] == '#')
++machines[machines_count].lights_count;
++i;
}

while(data[i] != '{') {
if(data[i] == ')') {
++machines[machines_count].buttons_count;
}

if(data[i] >= '0' && data[i] <= '9')
machines[machines_count].buttons[machines[machines_count].buttons_count] |= 1 << (data[i] - '0');

++i;
}
>>
>>107500305
LOL!
>>
I have absolutely 0 idea how you're supposed to calculate button presses. I can't even come up with a brute force method
>>
>>107500322
it's a graph
>>
File: file.png (2 KB, 228x62)
2 KB
2 KB PNG
>>107500243
300 seconds in, 2 are completed, just 7-8 more hours to go
>>
>>107500355
i will personally pay for your electricity costs incurred by this broot if you let it run the whole time
>>
>>107500376
looks like some of the later lines have way more options though so its probably going to be slower for those
>>
>>107500322
I figured it's a tree - each node is a light configuration, branching off are the buttons to press next, which lead to other light configurations etc. You do a breadth-first-search to find the light configuration you're looking for and then add up the depths of the trees for part 1.
The problem is I have to go to work in 20 minutes and I can only implement this idea in the afternoon.
>>
p2 solution
p2 = 0

from z3 import *
for l in lines:
goal, *buttons, joltages = l.split()
goal = goal[1:-1]
goal = [1 if g == '#' else 0 for g in goal]
buttons = [ints(b) for b in buttons]
joltages = ints(joltages)

s = Optimize()
final_values = [0 for i in range(len(joltages))]
button_presses = [Int(i) for i in range(len(buttons))]
for i, b in enumerate(buttons):
for j in b:
final_values[j] += button_presses[i]
s.add(button_presses[i] >= 0)

for i, joltage in enumerate(joltages):
s.add(final_values[i] == joltage)

total = 0
for b in button_presses:
total += b

s.minimize(total)
s.check()

m = s.model()
v = m.eval(total)
v = v.as_long()
p2 += v
print(p2)
>>
>>107500322
actually I came up with a way. just realized that any more than 1 button press is redundant. a button set is either used or it's not so you can iterate through a combo of all buttons used and brute it that way
int64_t sum = 0;

for(int i = 0; i < machines_count; ++i) {
int64_t fewest = INT64_MAX;
for(int combo = 0; combo < ~(~(uint16_t)0 << machines[i].buttons_count); ++combo) {
uint16_t lights = 0;
int presses = 0;
for(int b = 0; b < machines[i].buttons_count; ++b) {
if(combo & (1 << b)) {
lights ^= machines[i].buttons[b];
++presses;
}
}

if(lights == machines[i].lights_target)
if(presses < fewest)
fewest = presses;
}
sum += fewest;
}

return sum;
>>
>>107500429
>import solution
>>
>>107500474
10th day in a row, he's really done it this time
>>
for part 2, do you need to satisfy both the indicator lights and the joltage requirements, or JUST the joltage requirements?
>>
>>107500510
>What is the fewest button presses required to correctly configure the joltage level counters on all of the machines?
>>
>>107500510
>(Ignore the indicator light diagrams.)
>>
>port gauss jordan to your lang day
>>
is this fucking CRT again?
>>
1 hour update: I have coded a generator that makes the combinations i need.

Not importing itertools btw fuck you
>>
wait, I want to import z3, is that cheating?
>>
>>107500606
>not enumerating over bitmasks (int)
>>
File: 10a.png (430 KB, 2852x2696)
430 KB
430 KB PNG
>where is part 2
I used from scipy import solution
>>
IDENTIFYING DYNAMIC PROGRAMMING
>>
>>107500162
part 1 is easy, besides the tedious parsing and array manipulation (in my implementation)
think in binary + xor,
A XOR B=C -> C XOR B=A
makes no sense to xor (press) b twice
>>
>>107500632
it's not though?

>>107500641
yes, suppose you have k button configurations then if you iterate from [0, 1<<k) then you will have all the combinations of length k. then just xor all the switches whose bit pos is 1. then compare against the requirement
obviously you need to make masks of the buttons too so (1,4) turns to 0b10010
>>
>>107500305
Parsed!
let inp: seq[tuple[lights: seq[bool], buttons: seq[seq[int]], jolts: seq[int]]] = commandlineparams()[0].lines.toseq.mapit(splitwhitespace it).mapit (it[0][1 .. ^2].mapit it == '#', it[1 .. ^2].mapit it[1 .. ^2].split(',').mapit parseint it, it[^1][1 .. ^2].split(',').mapit parseint it)
>>
i think i figured out how to do part2, but now i have to go to work
FUCK
>>
>>107500322
curr = [0,0,0]
button_pressed = [2]
curr[2] = not curr[2]
>>
is gauss jordan really the way though? considering integer solution set, and minimizing the sum of answer vector
>>
File: output.jpg (499 KB, 1600x2000)
499 KB
499 KB JPG
>Part 1: 206.49 µs
>Part 2: 67.15 ms

magick carbon\(1\).png -resize x2000! output.jpg
>>
>>107500649
exactly, simply xor all the combinations (ordering does not matter) going from length 1 to k, and the first one is the winner.

second part im gonna do later, but I think it can follow a similar approach but here I would only try actual feasible combinations
>>
File: 1759651497774381.png (647 KB, 1024x538)
647 KB
647 KB PNG
>>107500658
p1 broot
>>
oh wait isn't this just a linear alg solve? time to numpy bb
>>
>>107500677
for part 1, yes; for part 2, also yes but you have use some heuristic to limit your search space
>>
>>107500699
It's exactly how to solve it, both parts too. P1 is binary, P2 is integer.
>>
>problem is literally NP hard
I kneel Eric
```Day -Part 1- -Part 2-
10 00:16:28 01:07:52```
>>
>>107500716
Go back to discord
>>
miss me with that math shit, I'll take the silver star and call it
>>
>>107500698
Fuck the broot isn't working for part 2. I threw it at my strongest soldier, let's see if it gets any results within a reasonable amount of time, but I doubt it. Any hints?
>>
isn't gauss jordan just brute force??
>>
>>107500812
broot it after gauss jordan it'll work
>>
ok, I solved it with import z3, but I'm not satisfied. I feel like a fraud
>>
>>107500843
the fuck's a gauss jordan, some kind of shoes?
[spoiler]ok I'll goolag it...[/spoiler]
>>
I keep getting 15 for the first part 2 example machine and i cannot figure out why
>>
File: 1753317917618993.png (2 KB, 403x25)
2 KB
2 KB PNG
I'm not liking my bruteforce odds...
>>
So this broot is gonna take forever, what's the smart way of doing this? was part 1 supposed to be a hint at a better way of doing part 2?
>>
>>107500849
same, I used scipy but writing out Gaussian Elimination feels like an exercise in pointlessness
>>
>part1 (x, xs, _) = minimum $ map length $ filter ((== x) . foldl' xor 0) $ filterM (const [True, False]) xs
>from scipy.optimize import linprog as part2
yawn
>>
>>107500936
claude wrote it out for me, and it's like 100 lines of python.. it works but what's the point if I couldn't have written it myself? i'm just importing from claude at that point
>>
>"I imported solution"
>"I had AI write it"
can you niggers stop yawning and tell me how this shit even works
>>
>>107500962
p1 or p2?
>>
>>107500968
p2
>>
>>107500962
Do you write your own sorting function every time?
Linear programming optimization is just something you should always rely on a library for, there's no reason to reinvent the wheel.
>>
>>107500970
if you want a hint, we're modeling it as a flfgrz bs yvarne rdhngvbaf (rot13)
>>
Is there some way of doing this where you reduce the target jolts by the smallest number?

like if the target is [50, 51,52], just cut that down to [0,1,2], find out how many cycles it takes to get there, and then find out how many cycles it takes to get to [1,1,1], multiply that by the number you reduced, and add those two counts together? or is that still going to take a gorillion years?
>>
>basket ball remainder theorem

I knew it was going to be some gay math shit today...
>>
>>107500985
i'm not sure you're even guaranteed that you can do a [1,1,1]
>>
coping filturds
>>
>>107500978
Unlike sorting, this is not the kind of algorithm that's universally applicable enough to be in a standard library. I'm not switching to a different language just so I can import solution a thing I don't understand.

>>107500981
Yeah, I get that part, but it doesn't really help - every explanation of it uses matrices to explain shit that should be simple in the most obtuse way possible.
Thanks, anyway.
>>
Has anyone done part 2 from first principles and without using any special libraries, or should I basically just call it here?
>>
>>107501027
Apparently not, they're all impoooooorting niggers
>>
>>107500990
hmm good point. it gives a wrong answer for the test but it's not necessarily the fastest route i guess so it didn't work
>>
>>107500843
>>107500936
wouldn't gaussian elimination introduce negative numbers?
is there a way to avoid that?
>>
>>107501021
x0 = how many times you press the 0th button
x1 = how many times you press the 1st button
if your first zoltage is 47, then you do...
47 = x0 + x2 + x5 (or whatever ones increase the 0th value)
>>
IDENTIFYING GREED
>>
Wow two more days to go wow
>>
>>107501027
i have the concept of an idea...
>>
>>107501034
Okay, but how do I know when to stop pressing the 0th button? Assuming 47 is the lowest joltage, I can just press it 47 times, but I don't know if I will then have a button to increase a different joltage by the amount I need, *without* affecting the 0th...
Or are you just brooting it like this? I don't think that'd be much faster than what I'm doing as is.
>>
>>107501075
well, you set up 6 of those different equations (or however many), and you have to solve them at the same time. if you bump x0 up too high to solve the first equation, you will probably mess up the other equations. I don't know how to solve these in code easily so I'm importing (and being filtered >>107500994)
>>
I don't feel like jumping on my computer did Gemini 3, opus, deepseek, or gpt solve it one shot?
>>
I don't even know how to do this efficiently for real
How is z3 so fast, what is it actually doing
>>
>>107501027
>>107500696
here you go
>>
File: 1518783031984.png (1.64 MB, 1028x1460)
1.64 MB
1.64 MB PNG
I dont think we can broot part 2 mr frodo
>>
>>107501108
opus landed it in two attempts, gemini couldn't l, gpt ran out of "data analysis" and deepseek didn't get it either

captcha: goyim (g0yvm)
>>
>getting 44 instead of 33 on test
>getting tired
oh no no no
>>
>>107500950
>I didn't solder the logic gates used in my processor, what's the point?
There's a difference between using a crane to build a house and just paying someone else to do it for you

>>107500962
Each button is a vector (list) [0, 1, .... 1, 1, 0, 0, 1], pressing it adds that value to your current joltage vector (starts at [0, ..., 0]) and you need to get to your goal [5, 23, 0 ... 3]. So pressing a button b, 10 times is like +10b. What you want is for all your buttons ( vectors a, b, c) some numbers (x, y, z) such that ax + by + cz = joltage (goal). The notation for this is a matrix (a list of all your vectors) [a, b, c] multiplied by some vector [x, y, z] (this is equal to ax + by + cz ). The result of multiplying this matrix A by your solution vector (list) x is A*x. You need to find the x with the smallest sum(x) (sum of all numbers in your list x), so that A*x = b. For integers only, there isn't a fast way to do this, your options are pruning (reducing the number of possible x, by adding more limitations) or approximating it.

>>107501032
No matter how you do your elimination you reach RREF - there only exists one version of this for every matrix, it's unique (the columns are even if the order isn't and you swapped things). But your RREF should have infinite solutions, your goal is to find one that only has positive values REGARDLESS of what the RREF values are.
>>
File: 61f9ciagv5L._SL1256_.jpg (69 KB, 827x1256)
69 KB
69 KB JPG
>>107501112
Forming polygons (polytopes in higher dimensions) with real values which bound the feasible region, and then a bunch of algorithms to snap the values into lattice points. It's really quick to find solutions with real values, the harder part is when you're constraining to integers.

Pic rel is a very good introduction. Or the Bertsekas book if you want more math.
>>
>>107501086
I see. The thing is if I set up this equation for all the possible permutations the problem space explodes, I need some heurestic to reduce it by, the best I got right now is that I can disregard any solutions with less presses than the highest joltage.

Maybe I can do something silly by starting with an array of [47, 0, 0, 0, ...] (assuming 47 is the highest joltage) and then moving parts of that to other buttons somehow...
>>
eric you shitter why didnt we get this during the weekend
>>
>>107501187
anon ... there won't be another weekend this year
>>
>>107501187
he's never given any consideration for that, i remember a few years ago the biggest difficulty spikes always seemed to be sunday night while the previous fri/sat nights were easy
>>
>>107501142
>>107501165
This problem is so fucking boring. It completely killed the thread too. Guess I'll check in here and there to see if ps2 anon manages to solve it and then I'll see you guys next year.
>>
>>107501142
>there isn't a fast way to do this, your options are pruning (reducing the number of possible x, by adding more limitations) or approximating it.
This is the part I'm having trouble with, the rest is just a roundabout way of explaining what eric wrote on the page. Thanks for explaining, though.
>>
What is the general approach to part 2? Maybe finding some kind of criteria for a greedy algorithm to reduce the highest joltage index/indices or something? "Minimum moves" makes me think either greedy or DP, and I'm hoping it's the former.
>>
I did a quick Z3 solution and won't have time to do a proper one before work.
The counters that have the least buttons pointing to them should be solved for first, often you can completely eliminate multiple buttons because their values are effectively fixed.
>>
>>107501192
the previous weekend lol
>>
>>107501238
Or I guess maybe a recursive approach with (heavy) pruning?
>>
>>107501238
Branch and bound.
>>
>>107501238
I tried dp and it just fucking takes forever. I'm going to give greedy a shot but it might just be a linalg day.
>>
>>107501133
Damn a whole two attempts
>>
>works on test
>cant even clear first line of input
oh...
>>
>>107501266
yeah.....
>>
File: carbon.png (285 KB, 1024x1685)
285 KB
285 KB PNG
<-- unwashed ass
Day   -Part 1-   -Part 2-
10 00:40:35 02:15:09

Haven't read the thread, this is some linear algebra/system of equations bullshit, right?
I'm a mathlet, but I have a vague idea about how to wrangle Z3, at least. Takes 8 seconds.
>>
>>107501184
you can limit possible checks by setting an upper bound on the number of clicks. if the highest joltage is 25, and there's a free var that increments it by 1, you don't have to check the solution for that equation set for anything beyond 25 clicks
>>
>>107500696
just tell me if this is gauss jordan with extra steps or not? yes or no?
>>
>>107501320
yes
>>
File: file.png (34 KB, 786x454)
34 KB
34 KB PNG
>import solution
>>
>>107501238
it's a math day, either you know linear algebra and are using a language that can just
import solution
or you're filtered
>>
>>107501232
You can binary search the solution space because we know it has a lower bound. All you want is a function:

f(RREF, x) -> true or false an integer solution to RREF exists with sum x

The actual f function is what you'll be brute forcing, you can prune this by taking your free variables and trying to plug that back in. or take your most used variables and try to create a stronger constraint with less stuff to broot force

it's not great, and it's why this problem is technically NP-hard, the "import" way is more or less using ILP which is just this on crack
>>
File: file.png (89 KB, 518x588)
89 KB
89 KB PNG
I've been avoiding Python so far because it's like a drug and I'm supposed to be better than that, but I succumbed today.
I am a weak man.
>>
I'm brootin'. (with prunin')
>>
>>107500061
Maybe Eric knew that everyone was going to break out the SAT solver for this one, and that was his hint to remind you to set your multiplier values to integers and not real numbers.
>>
I'm so sorry bros, I have not participated at all this year
I joined the leaderboard and was about to start but didn't even finish day 1 silver before getting distracted
it's so over
last year I was writing Elixir and gave up at like day 6 or some shit because I refused to brute force a solution
>>
>>107501375
lol newfag
>>
>add pruning
>test fails
FUCK
>>
File: 1719770772133124.jpg (73 KB, 956x956)
73 KB
73 KB JPG
>used AI to import solution
i don't even care, fuck eric and fuck math
>>
>>107501398
What?
>You have to push each button an integer number of times; there's no such thing as "0.5 presses" (nor can you push a button a negative number of times).
If you use a SAT solver, you have to remember to use integers, and set a constraint that each integer >= 0, otherwise the SAT solver will find decimal and/or negative numbers when you tell it to optimize for the lowest total value of multipliers.
>>
> Super inneficient at writing parsing code because I have to re-learn Haskell parser combinators
> Write a nice solution for P1 using bitsets
> Part 2 requires me to drop my bitsets and go for something else

SHIT
>>
>>107501492
yeah i was proud of my part 1 solution using XOR since i never fuck with bitwise stuff. didn't help with part 2 tho, rip
>>
>>107499480
the red and the green :)
>>
File: 1743090647504566.jpg (92 KB, 460x443)
92 KB
92 KB JPG
>>107501325
thanks anon but I might have to just embrace the filter. will keep trying until the next day
>>
>>107501538
there are so few of us left anon, we must persevere
>>
Well, I guess that is it. I get the LinAlg concept behind the problem, but I don't know how to make a computer do it or even how to import solution and make it do it.
>>
air jordans for all
>>
unc lost it, he gives csp problems now
>>
>>107501580
it's a constraint satisfaction problem where the constraints will be in the form of let there be some variables. first switches gets pressed v0 times, second v1 times, etc + condition that all variables are non-negative integers + condition that sum of variables is minimized. there are solvers for such problems.
>>
>>107501538
>>107501580
Honestly, just figure out how to use python z3 for the problem. It's interesting and not too hard. Personally, I don't count it as a filterable transgression.
>>
File: broooot.png (20 KB, 547x311)
20 KB
20 KB PNG
the basic bitch broot is now running while I take a 2 hour shower and think of ways to be less broot about it
>>
>>107501580
here you go, buddy, all yours

from z3 import Optimize, Int, Sum, sat

with open("input.txt","r") as f:
lines = f.readlines()

machines = []
for line in lines:
line = line[:-1].split("] ")
lights = line[0][1:]
line = line[1].split(" {")
btns = []
pbs = line[0].split(" ")
for b in pbs:
b = b[1:-1].split(",")
entry = [int(n) for n in b]
btns.append(entry)
jolts = [int(n) for n in line[1][:-1].split(",")]
machines.append([lights,btns,jolts])

def import_solution(buttons,targets):
# Brought to you by AI
solver = Optimize()

presses = [Int(f'x{i}') for i in range(len(buttons))]

for p in presses:
solver.add(p >= 0)

for j, target in enumerate(targets):
solver.add(Sum([presses[i] * buttons[i][j] for i in range(len(buttons))]) == target)

total_presses = Sum(presses)
solver.minimize(total_presses)

if solver.check() == sat:
model = solver.model()
solution = [model[p].as_long() for p in presses]
return sum(solution)

tot = 0
for machine in machines:
b = machine[1]
j = list(machine[2])
buttons = []
temp = [0 for _ in range(len(j))]
for i in b:
btn = temp[:]
for n in i:
btn[n] = 1
buttons.append(btn)
to_add = import_solution(buttons,j)
#print(to_add)
tot += to_add
print(tot)

>>
>>107501608
Adding to this, look at the z3py guide by, I shit you not, ericpony on github
>>
>>107501627
>>107501580

gotta
pip install z3-solver
first
>>
fuck these boring ass import solution "puzzles"
>>
aight Im leaving my broot on for 16 hours while i sleep and work.
>>
>have stupid recursive broot of part one running for over an hour
>decided to try pressing all the buttons on all the states each loop (with pruning of previous states)
>finishes in 1 second
Damn it, i should have known.
Guess I'll do the same for part 2.
>>
>>107501685
>>have stupid recursive broot of part one running for over an hour
lmao you have to be joking
>>
>>107499832
PROPHETIC
>>
>>107501685
>Guess I'll do the same for part 2.
I guess this isn't going to work to part 2...
>>
>>107501701
doesnt count, its a simple z3 solver one
>>
File: Day10_2025.png (429 KB, 1220x2352)
429 KB
429 KB PNG
Importing the solution is pythonic and idiomatic
>>
>>107501693
>Silver:> 505
>Runtime:> 3731.809s
It gave the correct result at least.
>>
>>107500429
>>107501292
>>107501627
>>107501639
>>107501744
What the hell is this z3 thing? Where did it come from? Why does everyone suddenly know about it and use it?
Back in my day we used scipy for this.
>>
>>107501759
used in previous years
>>
>>107501780
What do you mean "used in previous years"?
Was it mentioned in a puzzle?
Or did did one random anon happen to post a solution using it in a thread one time and all the codelets who don't even know what numpy is started mindlessly copying him?
>>
I imported the solution
I "imported" someone else's solution that imported the solution to see how to import the solution
No I am not filtered
>>
>>107501759
You can use the SciPy MILP solver for this (which is just a wrapper around HiGHS), but for small problems like this Z3 is fast enough and more versatile.
For example, it could easily solve last year's rock throwing problem, which had quadratic constraints.
>>
>>107501759
It's not some secret. It's permissively licensed and created by Microsoft Research. It's been around for a decade or so.
>>
>broot solved 3/167 lines in the past 15 minutes

As good as solved. See you tomorrow with my star.
>>
>>107501759
https://en.wikipedia.org/wiki/Z3_Theorem_Prover

It's come up a few times now where it's much easier to feed Z3 a set of constraints and make it do the hard stuff, especially if you suck at math (like me).

I've used it for part 2 of each of these:
https://adventofcode.com/2018/day/23
https://adventofcode.com/2023/day/24
https://adventofcode.com/2024/day/13
https://adventofcode.com/2025/day/10 (today)
>>
x_4 + x_5 = 3
x_1 + x_5 = 5
x_2 + x_3 + x_4 = 4
x_0 + x_1 + x_3 = 7

if I weren't a mathlet maybe noticing that I can compress the first line of the example into this system of equations would be useful in any way
>>
>>107501759
well for one, z3 is available for more languages than just python, and it's basically made for shit like this. scipy has so much shit in it i have to google to find out if it can do what i'm interested in
>>
>>107501838
is today's one a trivial math problem though? I don't think finding a heuristic method for gauss-jordan is that easy (don't spoil)
>>
>>107501838
As always, when you look into who creates these types of libraries, it's either a French or Danish guy. In this case, Denmark.
https://www.microsoft.com/en-us/research/people/nbjorner/
>>
does it exactly equal or are you forced to go over? I am finding no solutions for exactly equal?
>>
>3 hours later
>only done 2/167
fuck
>>
>>107501856
it is, that's all I'll say
>>
>go to bed (5 hours until work)
>brain suddenly provides me with solution
nooooo. Ill do it tomorrow.
>>
File: 1747257488021443.png (1.93 MB, 1493x933)
1.93 MB
1.93 MB PNG
>wasted entire morning on this shit when I could have been doing comfy gamedev
FUCK YOU ERIC
>>
>>107501953
What engine is that?
>>
>>107501956
my own (I have autism). you'd think I'd be better at lin algebra problems
>>
>>107498825
*new years
>>
>anons spending hours to complete it
>one shot by AI again
Kek.
>>
>bruteforce doesn't work for part 2
wow this is a tough one
i guess it will be the same for the iterative version
at least we know that there won't be any problem after d12, considering steep the difficulty has been these last days
going back to gamedev too
>>
>maybe there's always only one button the increments a certain place
>first input has it
>second input does not
Damn it. There's got to be a trick that's not that difficult.
>>
>>107502028
how steep*
>>
>Because none of the machines are running, the joltage requirements are irrelevant and can be safely ignored.
Just tell me what part 2 is about already...
>>
>>107502030
it's not "hard", it's an import solution problem if you realize it's a csp problem, just check a random library or ask a llm to write you the constraints if you can't bother to read the docs
>>
File: file.png (273 KB, 395x366)
273 KB
273 KB PNG
hey I know this one
>>
File: 10.png (823 KB, 2960x4744)
823 KB
823 KB PNG
idiomatic "Rust" solution
>>
>>107501075
order doesnt matter
>>
>>107502134
Surely Rustroons have wrapped Z3?
>>
>go to the reddit thread
>check the repos of the big brains
>no project, it's all competitive programming/leetcode/aoc solutions
kek pathetic
>>
>>107502134
>idiomatic
rustic
>>
>>107502134
>shelling out to python
oooohhh no no no no no noooo
>>
>>107502134
filtered
>>
File: ocaml10a.png (529 KB, 1458x4342)
529 KB
529 KB PNG
here's part 1 for OCaml
I was very happy when I finished this several hours ago
I have only just thoroughly concluded that that this was indeed a DP problem.
Lot of time wasted on thinking that part 2 was adding a goal instead of replacing part 1's goal.
>>
>>107502257
I have all stars though :^)

>>107502262
where is your code?
>>
>>107502196
Yes https://docs.rs/z3/latest/z3/
>>
File: 1749569619542473.png (641 KB, 1468x2490)
641 KB
641 KB PNG
I will try my luck with bfs on part 2 - if I manage to implement that in Haskell - but here is part 1.
>>
I learned something today.
But what I learned... I'm not entirely sure.
>>
>>107500061
Okay, TJ "Eric" Yoshi
>>
>>107502367
anon, there is no bfs, sadly. I considered it but there are far too many states.

>>107502422
a classic lesson in aoc
>>
>>107502431
>a classic lesson in aoc
True.
Now back to trying to get day 9 part 2 to a workable state for PS2.
>>
>>107501616

real    142m24.873s
user 141m10.641s
sys 0m5.851s


>ctrl+c
>see runtime
>0 lines of input part 2 completed so far
it was worth a try

getting worried I have to do soulless number theory remainders and divisors fuck
I have some more broot optimizations in mind I will try first though
>>
>>107502477
Good luck Mr. Brootchad
>>
>>107502200
I have skills but no ideas
Someone has to give me a problem to solve
>>
>>107502462
Damn it. My solution works on example but not input.
>>
>>107501821
I see it's not a secret, but I've just never happened to heard about it until today.
I checked Reddit and they're all using Z3 too. Bizarre.
Feels like it suddenly popped into existence, even though it's clearly quite old already.
Maybe because I haven't really looked into the state of the art python ecosystems since learning machine learning 5 years ago
>2018/day/23
fuck
>>
>>107502499
A good linux DE
>>
File: filtered.png (68 KB, 1440x614)
68 KB
68 KB PNG
>>
I FINALLY DID IT

NOW FOR PART 2
>>
>>107502670
are you serious? part 1 was trivial.
>>
>>107502676
It is not for most devs...
>>
there might be a "linear algebra"-way without going down the "Integer Programming Solver" Route.
Using the smith normal form decomposition one can find all solutions over Z. the input seems to always have solution dimension of up to 3. the resulting MILP program (in max 3 variables) should be bruteforce-able.
finding non-"heuristic" bounds on the reduced variable set might be hard.
then again, a smart MILP-solver might be doing something like similar behind the scenes anyway, so this might not even be faster...
>>
alright jordan anons I might need a hint after all. help me please. idk what heuristics to use. I have tried column wise min/max, full pivot for min in the remaining submatrix with both row and column swap, only picking an element as pivot if it divides the rhs and if the quotient is non-negative, etc. no where close
>>
>>107502834
if you are talking about "doing integer gauss elimination" then the term is "smith-normal-form". then you still need to find the optimal solution (with up to 3 non-pivots)
>>
I realized that my new day 9 part 2 solution doesn't pick up the big bar in the middle of the shape if none of the points that make it up are in the candidate rectangle.
>>
>>107502730
it should be for everyone who has made it so far.
>>
>>107502846
some anons gave me hope >>107501922 >>107501325 >>107501142

ig the heuristics anons are talking about is trivial for them but not for me :<
if I don't report back then consider me filtered. so long bros
>>
>example input works
>real input
>your answer is too low
FUCK YOU ERIC YOU FUCKING FAGGOT
>>
>part 2 example takes few minutes
brootbrothers I don't think we're gonna make it
>>
>>107501744
bruh you don't need dijkstra for part 1. Simple BFS will work.
>>
>>107503027
>BFS
anon...
>>
>>107501538
Anon, it can be done using Excel. With the right library is just parsing, formatting the data, and calling the solver.
>>
>>107503031
>>107503027
I brooted that part, like in testing all combinations, is a few seconds at most.
>>
no idea how to solve this without z3
>>
So what I did is reverse the light and turn it into bits and then turn the buttons into bit masks and then get every combination of the bit masks and XORing them until we get a combination that matches the light and then get the minimum number of bit masks and then sum. This works for the example but for the real input it gives a "low" answer. No idea what I'm missing here.
>>
well i got as far as converting my buttons into numbers and converting the target into a number
then it's just finding a*x + b*y + c*z + ...
so how the fuck are you supposed to do that without `import solution'?
>>
I looked up lectures about ILP and they were using z3 too
>>
>>107503186
nvm u8 was just too small...
>>
>>107503130
Same.
At least I realized Z3 was the way to go, and got my star with it before looking at the thread.
I'd be feeling pretty filtered right now if I only thought of it after getting a hint.
>>
>>107502802
turns out finding bounds on the variables is actually a thing and called "Fourier-Motzkin-Elimination"...
>>
>>107503204
In some of the cases, only one button increments a certain position.
So that solves one portion of the equation, and, if that button increments other positions, it limits the search space.
But after that, or when that's not the case... i don't know. You could take the longest button and multiply it by the lowest target it matches, then try fit other buttons into the remainder, decrementing the initial button when you can't fit any other buttons in and don't have the solution, but I don't know.
>>
File: file.png (25 KB, 809x122)
25 KB
25 KB PNG
>Gauss-Jordan to get the potential solutions
>BROOOOOOOOT over the set of potential solutions
>it just werks
>>
File: carbon.png (327 KB, 1024x1965)
327 KB
327 KB PNG
>>107503058
It occurred to me that you can just sort your search order by how many buttons are turned on, and then you can optimize that further by turning the code that generates your search order into a function and memoizing it.
Cuts my part 1 time in half (334 -> 162ms CPython)

Washed version of >>107501292
>>
>>107503402
use bitmasking. no need for extra space
>>
>>107502834
No heuristics. Just brute force.
After reducing to normal form, you'll have a few free variables and the rest can be calculated from them.
You'll notice that the difference between the number of buttons and the number of counters is never greater than 4.
>>
>>107503513
yep, I realized that after reading >>107501142 . I am mathlet

running. let's see if I managed to impl it correctly or not. still very slow. I am not doing binary search, just for a given sum finding the min sum that can yield an integral solution.
>>
>>107503130
>>107503317
>>107503402
every year there's a puzzle solvable by z3 and to this day I have no idea what it does.
shamelessly filtered
>>
>>107503130
Here is one.
>For each button, check if it can be a part of the solution
>If yes, check if it is the solution
>If no, save the state of the indicator lights/joltages after pressing it.
Do the above for each state of the indicator lights/joltages you have saved (start from all zeros).
Works for silver, no reason it shouldnt work for gold (except number of presses to keep track of maybe, you can propably do some memoization trick).
>>
this year sucks ass
>>
>>107503641
NTA but that's what running for me in background and i'm not even 1/20 of the way for the first line of input after 5 mins
>>
>>107503641
got silver with basic bfs
for gold I did everything I could think of, let the program run for a haf hour and got only 29 out of 167
I'm officially filtered
>>
File: file.png (81 KB, 411x334)
81 KB
81 KB PNG
>>107503641
>no reason it shouldnt work for gold
>>
>>107503680
Why do all the retards use BFS?
Don't you realize it has the same speed as brute force search but is 10x more complicated?
Just go through the bitmasks in a for loop, xor all the active shit, check if equal to target, if so record the popcount.
Or if bitmasks are too advanced for you, just generate all subset lists.
>>
File: unknown.png (44 KB, 1106x248)
44 KB
44 KB PNG
>>107503576
bros it's not over yet TwT

>>107501142
>>107503513
love you anons so much <3. a small step towards not being a mathlet

now I am ready to see your jordan solutions. share pls
>>
>>107503362
finally someone who fucking gets what do after gauss man I was tired to see everyone eat shit and die
>>
>>107503732
it must have been lonely at the top, king. are you the only one with jordans? other than this anon >>107503362
>>
>>107503746
there's like 4-5 of us I think? some landed a heuristic others brooted over the entire available space post jordan so it took slightly longer, but yeah
>>
>>107503674
>>107503680
>>107503698
Kek looks like I'll ditch my silver solution.
>>
>>107503777
trips of kings

what's the heuristic one? and what's the brute one? mind sharing your code?
I set the threshold to be 320 (arbitrary judging from a few) and then for each case just found the min presses. idk how to improve it other than just checking for all values for each position and exhausting the remaining sum.
>>
>>107503806
it works for part 1, my answer was 3 digits long
it's part 2 which fucks it in the ass
>>
>>107503844
True, I meant that my code is not reusable except the parsing.
>t. retard that thought he had basically solved the day
>>
File: file.png (595 KB, 1532x4620)
595 KB
595 KB PNG
>>107503820
Not that guy but here's mine.
Yes it takes several minutes to run. No I won't improve it.
>>
new thread

>>107503906
>>107503906
>>107503906

new thread
>>
File: carbon.png (324 KB, 1024x1965)
324 KB
324 KB PNG
>>107503483
Yeah you're right, I didn't want to because it was annoying to write.
Saves like another 30ms on part 1.
>>
File: image.png (276 KB, 739x887)
276 KB
276 KB PNG
I have no idea how any of this math stuff works, so I used z3. I want to formally apologize to Eric for doubting him.



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