[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: wallchin.png (2.29 MB, 1600x900)
2.29 MB
2.29 MB PNG
the real wall 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: >>107481125
>>
File: solve_naive.png (532 KB, 5708x2412)
532 KB
532 KB PNG
idiomatic Rust solution
>>
>5 key doesn't work half the time
>this is now aocg 1 instead of 15

ffs
>>
>>107490214
well this is the first proper day of aoc this year
>>
>>107490197
idiomatic rust anon, see >>107490049
I don't think just checking for one edge at a time will work for this

>>107490258
indeed
>>
>>107490322
someone should post one of those line graphs that show how many on the /g/eaderboard got filtered, we surely dropped down to 80?
>>
>>107490333
only 38 anons have solved p2 today
minus a few who took >24h on any previous day
threads are going to be quiet...
>>
bigboy?
>>
>>107490349
bloodbath
>>
>>107490322
>>107490333
check 'em dubs and trips

>>107490349
>threads are going to be quiet
aoc is going to be fun

>>107490350
I hope the bigboy anon did not get filtered. I am thinking of ideas of how to make one
>>
>>107490394
i have an optimization trick in mind but cannot land the execution, hope some anons can help me.

my approach is basically to pick a candidate rectangle and then check every edge of the green/red polygon to see if it cuts it or not. now for most points the lines will be far enough from the rectangle to be irrelevant, but what kind of heuristic could I use to not check them? does this even make sense?
>>
File: aoc2025-09.png (291 KB, 592x2482)
291 KB
291 KB PNG
Finally, some good fucking food
I compressed the grid and flood-filled it, guessing the middle coordinate as starting point. Of course Eric put a big dent in there to fuck me over.
Still slow as hell, it takes 220 seconds to run. I might look into optimizing this.
Mostly unwashed code
>>
File: Day 9.webm (1.51 MB, 1000x1000)
1.51 MB
1.51 MB WEBM
Visualization of my solution
>>
>>107490430
say you have a two points represented as top left / bottom right of your rectangle
if you check each row and scan right, then you're looking for two things:
1. the number of rightward vertical segments from topleft.x is odd (this means your left edge is within the polygon)
2. there is no vertical line such that topleft.x < line.x < bottomright.x where there is no adjacent vertical line (line.x + 1 or line.x - 1)
>>
>>107490430
why are you avoiding checking for lines? there are like 500 lines. I don't think it will be very easy unless you compress the coords

>>107490452
why not start flood fill from edge points?
>>
>>107490458
seems like it's checking all rects n e way, what's the thing in the start that's going across the screen
>>
>>107490471
no I mean that's just describing my current solution back to me. i was thinking out loud on that optimization thing nvm
>>
>>107490474
I am marking all the boundary cells first, then I do bfs from a cell outside the boundary to mark all the cells outside boundary.
Remaining cells will be inside the boundary.
Then I iterate over n*(n-1) possible rectangles and get the rectangle with max that's completely inside.
>>
>>107490458
cool :O
>>
File: carbon(8).png (1.85 MB, 1586x8974)
1.85 MB
1.85 MB PNG
Extremely comfy day since I know some computational geometry.
Mathlet status?
>>
>>107490487
for each row, store a set of indices where a vertical line crosses that row
that way you're not looking at unrelated edges
instead of a set (for check 1) you can use a sorted list and binary search
>>
>>107490472
Yeah I could have done that.
In the end I scanned the line y=1 (in the compressed grid) for positions that intersected a line, and determined my floodfill start position that way.
I'm also realizing I only need to check the rectangle edges, not the insides, so it could be a lot faster.
>>
File: AoC-09.png (301 KB, 1127x1991)
301 KB
301 KB PNG
Very much a "What the fuck am I writing" kind of day.
>>
File: carbon9.png (575 KB, 1294x3186)
575 KB
575 KB PNG
I have no fucking idea. I did it in two ways, both give me the same fucking answer, which is too low.
First idea was to check if any line between two consecutive tiles crosses my square (and if it doesn't, it is valid).
Second idea was to compress coordinates, make a grid and just check if there are any outside tiles inside my square.
What is wrong here?
https://pastebin.com/AGRB8hV3
>>
>>107490474
Looks like Anon's flood filling starting from the top-left to find what's outside the shape.
I did a single ray cast starting from (-1,-1) and going towards the point furthest from (-1,-1) until I hit a point on the outside edge, then just followed the wall from there to make a tight loop to find the outer edge.
This anon >>107489431 from the last thread had the best idea I've seen described.

Could also make a set of all points in a 3x3 grid around every border point, subtract the border set from that set, then do a flood fill from any arbitrary point to to separate inner and outer halves; then the outer border is just the longer of the two sets. Shit, should've thought of that earlier.
>>
>>107490594
enumerating all the points attached to the edges is not that efficient though. although, cool trick.
>>
i dont understand with raycasting how you handle something like this:
.....#.
>..###.
...#...
>>
>>107490566
Oh, I just fucked up my area function.
>>
>>107490620
I was stuck too. but for edges that completely coincide with the ray you have to check if that edge causes an inflection point or not. if it does then you count that as ray cross it.

inflection point means if the edges before and after it are along the different direction

consider |_| < in this case both the adjacent edges are along the same dir so it does not count as cross the bottom edge
>>
File: carbon99.png (576 KB, 1294x3186)
576 KB
576 KB PNG
>>107490644
>>107490566
> I spent a two hours because my area function was fucked
> second solution gave me the same answer because I copied that function to it
FUCK
>>
>>107490394
>I hope the bigboy anon did not get filtered
Not yet but my solution is too slow. Sorry fellas, maybe tomorrow
>>
>>107490646
that makes sense but sounds like it would be painful to check in my spaghetti code
>>
>>107490667
i came up with the idea for a bigboy but this bitch is so big my code can't handle it lol. what's your general procedure for creating these, if you don't mind sharing
>>
>>107490566
Finally a good day though, not too hard, but got me thinking a bit.
>>
>>107490693
my idea would be to create a small one in a 1000*1000 grid (most edges will be of length 1 or 2) and then just blow it by coordinate decompression lol
>>
File: disgasteng.png (512 KB, 2048x1698)
512 KB
512 KB PNG
PostgreSQL PostGIS solution

I got the list of possible rectangles from my shitass Python solution, but it could be done with a cross join in pure SQL.
>>
>>107490693
>ndle it lol. what's your general procedure for creating these
rand(), shuf, etc. no one cares about quality as long as it's big and fits the description
>>
File: aoc2025-09a.png (265 KB, 567x2261)
265 KB
265 KB PNG
>>107490452
Ok, now it runs in 4 seconds
>>
>thinking i can get from casting four rays down to casting one ray
>realize that in a literal edge case i could get a false inside result
>realize i can still cut down to two rays because two rays will definitely hit the polygon and if either of the other two don't intersect anywhere the point is outside
I think I'll be able to get this working on PS2, I'll need more time, though. Technically I was already filtered by Day 2.
>>
>>107490733
anon you only need 1 ray
>>
I tried doing part1 in O(n), by finding points closest to the corner. It doesnt work. Any way to salvage the idea or should I just brooot?
>>
>>107490779
each point is on the corner by definition, did did you mean points closer to that cave in the middle?
>>
>>107490779
just brute. that's probably intended
>>
>>107490799
I mean points that are closest to the corners of the grid ((0,0) for example). This assumes that bigger eucledian distance -> bigger rectangle, which is wrong
>>
>>107490806
Propably will, if only to start part 2.
>>
File: 4132.png (18 KB, 552x77)
18 KB
18 KB PNG
>2h on debugging trying to figure out what's wrong with overlap code
>turns out the corners are correct and i calculated area wrong (which didn't show up on part 1)

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
>>
>>107490779
n is just 1000, so it doesn't really matter.
>>
>>107490852
>>107490665
Bruh
>>
>>107490498
>then I do bfs from a cell outside the boundary to mark all the cells outside boundary.
Why not dfs...
>>
TAKE YER BIGBOYS TAKEE YER BIG BOYSS:

bigboy day 9: https://files.catbox.moe/jw23yd.txt

>Part 1: 275972310
>Part 2: 29280786

caveat: first time doing this and I could only solve it with a modified version of my own solution, so there's no "verification" of the solution, so to speak. like the solutions could just be wrong lol but they're most probably right
>>
>>107490852
>abs(x1-x2+1)
ahahahahahahahahaha dude
>>
>>107490931 (me)
used solution thrice in a sentence lifetime achievement award
>>
>>107490747
I suppose casting towards the nearest "boundary" would be would be enough, yeah.
>>
File: carbon(2).png (2.92 MB, 1834x4468)
2.92 MB
2.92 MB PNG
good challenge today.
I was planning on building a quadtree of valid squares and using that to speed up the solution but after just using the "is this a valid rect" function I was going to use on the tree on the sample input I realized that it'd probably be fast enough (or faster?) to just skip the tree and validate rects directly. Spent a while debugging my winding numbers, I had an issue with double counting lines that shared a start/end
>>
>>107490966
"nearest" boundary is just an heuristic optimization though? I just shoot a ray to the right and then iterate over all the edges to count how many were crossed
>>
>>107490931
It crosses itself?
>>
File: ray.png (6 KB, 230x154)
6 KB
6 KB PNG
>>107490988
How do you deal with this?
>>
>>107490990
afaik the only rule is each point is on the same X or y as the next one
>>
>>107491020
things that don't intersect vertically aren't relevant to increasing or decreasing the winding number
>>
>>107491020
>>107490646
>>
>>107491025
What is considered "inside" then?
>>
>>107491020
see >>107490646 (me)
in this case it's an U shape so it does not count as crossing that edge
>>
>>107491025
having it self intersect introduces ambiguity about what "interior" means, doesn't really fit the puzzle.
>>
>>107490931
>negative numbers
bruh
>>
>>107491043
and if you don't do this then even if you shoot 4 rays it will not be correct because all 4 rays might coincide with an edge completely

additionally, you should also check if the point is on an edge. if so then it is inside
>>
File: file.png (19 KB, 771x735)
19 KB
19 KB PNG
>>107490931
I don't know what's supposed to be the interior and exterior here, but my code is treating everything inside the exterior wall as inside.
P1 is correct, P2 is like 40% done and the best it's found so far is
>207548208
>>
File: solve.png (1.68 MB, 5708x9302)
1.68 MB
1.68 MB PNG
>>107490931
61s
I also get 207548208 for part 2.
>>
hmm maybe fractal structures might be better for bigboy instead of a spiral? the other approach is probably just blowing up the coordinates
>>
>>107491031
Couldn't I then just completely ignore the horizontal lines and go if it intersects two vertical lines (directly on a y value), see if the points other than the intersected y point are both in the same direction? (both less than or greater than) and ignore
>>
>>107491224
what if more than 2 such points are there? essentially, how will you know which edge points are connected to form a horizontal edge? intuitively, it makes sense to not make a distinction b/w vertical and horizontal edges and treat all the same
>>
Well I have a solution but whether it finishes before the heat death of the universe is another matter.
What a stupid ramp up in difficulty this year. From almost trivial to almost impossible.

While writing this I thought about a wait to detect the corners of one of the inlet points but fuck it I will wait until my brute force finishes.
>>
>>107491288
>What a stupid ramp up in difficulty this year.
lol, filtered.
>>
File: file.png (130 KB, 2465x183)
130 KB
130 KB PNG
bruteforce CHADS keep winning
>>
>>107490931
pypy3 09B.py < input.txt
275972310 207548208
38.569275000000005 seconds

I think your solution might be incorrect.
>>
File: 9.png (209 KB, 1025x1247)
209 KB
209 KB PNG
awk
takes 10s but works
>>
>>107490920
You could do either BFS or DFS. Both of them work equally well here (afaik). I did BFS because it looks cooler in the vid.
>>
>>107491321
always good to see awk. but I might have a bad news for you
paste answers for
1,1
8,1
8,3
3,3
3,4
8,4
8,6
1,6
>>
File: file.png (29 KB, 2253x1680)
29 KB
29 KB PNG
My solution is mega stupid (it's like O(n^4)?) but it works okay enough for this. Gotta find a smarter way of doing it
>Initial try was to do a line-side test for each side of the polygon. Treating each line as a directed edge, we test if the AABB is always on the same side of the line. If it's not, then it's outside the figure
>This works on inputs without a U shape like the test input, but fails on the real input because it's effectively a giant U
>I adapted the solution to do a second check for each line. Suppose we're testing a line that goes to the right. If there's a line that goes to the left that's above the test line and below the AABB, then we should ignore the test line, because it isn't relevant to whether the given AABB is in bounds
On the main input it takes a second or two to run, scared to run it on the bigboy because I know it sucks. But I only barely didn't get filtered
>>
>>107491339
48 8
>>
File: 1743090647504566.jpg (92 KB, 460x443)
92 KB
92 KB JPG
>>107491349
am sorry, anon. should be 48 48
>>
>>107491360
tell that to eric
>>
fuck geometry puzzles
t. mathlet pythonigger
>captcha PYGTAY

>>107491341
>pic
there can't be inner squares because input is a closed loop
>>
>>107490931
is this a valid input? otherwise I am not modifying my program to support negative coords

>>107491422
if it works it works
>>
bros... im getting filtered...
>>
>>107491465
The inner square is meant to be the rectangle we're checking the polygon, I just fucked up the diagram and forgot it should touch two corners of the polygon. The same logic I described still applies though
>>
>>107491478
yes in the sense my program ran on it unmodified, although my parse number util already handles it so I didn't have to care
no in the sense that people are saying self intersecting structures (a spiral here) are not fairplay since there's no out or in side
>>
>>107491481
the best solution is a ray trace broot. start going down that path you'll get it
>>
>>107491321
Never thought to use "ag" and "au" as shorthand for "silver" and "gold," that's cute
>>
>>107491512
alright. mine would pass but I still don't want to modify it for negative numbers. I can just shift all by an offset tho

>>107490931
275972310
207548208
3.1s

hmm, incorrect for p2

>>107491520
not the best

alright, it's decided then. I will give you anons the bigboy of your life
>>
File: file.png (13 KB, 1259x101)
13 KB
13 KB PNG
rustbros...
>>
>>107491288
Got the answer via the corner detection and now I am sure the brute force will work for sure and end on time too.
will post both solutions once the brute force one finishes.
>>
File: filtered.png (82 KB, 1474x645)
82 KB
82 KB PNG
>>
part 1 is trivial.
part 2? yeah I remember something similar from a few years ago. I've got a few ideas.
>>
>>107491639 (me)
>I will give you anons the bigboy of your life
I don't think I want to :<
too much work and most of anons' solutions will fail because the expected time complexity will be O(n^2)
>>
File: ot62yB6.png (626 KB, 1440x963)
626 KB
626 KB PNG
>>107490503
Mathlet here. You know I'm something of a geometrist myself.
from shapely.geometry import Polygon
polygon = Polygon(points)
for p1, p2 in combinations(points,2):
(x1,y1), (x2,y2) = p1, p2
p3, p4 = (x2, y1), (x1, y2)
rect = Polygon([p1, p3, p2, p4])
if polygon.contains(rect):
gold = max(gold, area(p1,p2))
>>
>>107491867
now do the bigboy
>>
File: carbon.png (734 KB, 799x4157)
734 KB
734 KB PNG
>>107490931
Today was interesting, got me back to rust to optimize this.
Star one: 275972310
Star two: 207548208
day 09                  time:   [7.5693 ms 7.5999 ms 7.6337 ms]
bigboy time: 7.7s

Thank you whoever mentioned coord compression, I tried to use a sum table on its own at first but couldn't allocate that much.
First, I mark the polygon border and floodfill outside. Then set all border+unmarked tiles to 1 and create a sum table. If a rectangle sum is equal to its area, we found one fully inside the polygon.
Creating all rectangles is like half the runtime, finding the largest valid takes around 1.5s. Bigboy made me use a binary heap, it doesn't make any difference for regular input.

Is there a nice way of inserting a value into iterator without copying? I did
                    .chain([i32::MAX].into_iter())
[/code[
but clippy's complaining and I don't want to add .copied() if I don't have to.
>>
File: file.png (427 KB, 1834x2458)
427 KB
427 KB PNG
rust day 9

solution running slow? no problem just add a threads, it's only 4 characters god I love rust
>>
>>107490503
hello fellow zigger anon. comfy solution as always :)
how does the winding algo compare against the ray casting algo?

>>107491919
getting the same answers with the same approach
>>
File: file.png (3 KB, 198x218)
3 KB
3 KB PNG
Anons, be honest
can your solution handle this?
>>
File: code.png (619 KB, 1958x3548)
619 KB
619 KB PNG
>>107491720
Python

This version reduces the search space by detecting special x and y coords that happens to appear four times within the tiles coords. Only one x coord and one y coord appear four times within the tiles thus they must be part of the answer given the shape formed by all tiles.

It is slow as fuck but works and is faster than the version that search all rectangles for the answer which is taking hours but I am confident will end on time.
>>
File: 1755227708874736.png (25 KB, 1080x136)
25 KB
25 KB PNG
I don't think I could've solved this without that anon explaining coordinate compression. I am not even sure if I implemented it right but got my stars. My head hurts. I don't even know what I don't know to solve this thing. My code is a mess but this type definition should give a hint about it
>>
>>107491993
Isn't this basically what the actual input is like for everyone? A large area with a slot jutting into it?
>>
what if I partitioned the polygon into individual rectangles?
then I could sort them by area, and pick the larges one that has two opposite corners from the original set
>>
>>107492050
in the input there is a gap in the slot, so if you check for edge or corner inside a candidate rect it works
in that pic there is no gap, the answer is in black
>>
>>107491919
chain calls into_iter for you, so you can just write chain([i32::MAX])
>>
>>107491960
>how does winding compare to raycasting
Well, in theory I like the winding numbers approach since it always "just works" even for nonsimple polygons and is easy to remember.
In practice it's doing a lot of duplicated work and is far from perfect for this puzzle.
I tried the bigboy but even just reading and appending the rectangles takes 20 seconds, and I stopped it since I'm not optimizing my solutions this year :^)
Coordinate compression feels like a hack but I'm probably misunderstanding how people work around the approximation.
>>107491867
Nice. I'm thinking next year I'll only do
import solution
s.
>>
File: 1764913099967144.jpg (107 KB, 636x800)
107 KB
107 KB JPG
>>107491993
yes
>>
>>107492027
link to explanation please
>>
>>107492099
The input is also constructed so that coordinate compression doesn't destroy the gap, which in general is very possible.
>>
File: Day-9.png (1.85 MB, 1594x8856)
1.85 MB
1.85 MB PNG
>>107492150
see mine

>>107492189
you too

see >>107489767 and >>107489811 for explanation
>>
>>107491815
how many problems are there across AoC history with more silver star only holders than gold star holders?
>>
>>107491993
No
>>
>>107491919
>7.7s
Very nice. Could you please post your code to pastebin?
I want to see whether it's my solution or my PC that's shit.
>>
>>107491993
poast input that does this
>>
File: 1745878479353169.png (17 KB, 398x126)
17 KB
17 KB PNG
>>107491993
Easily. It is a mess but it works. I was scared it when I had to wait several minutes at this point though. Me, console and "Just"
>>
>>107491847
if I don't see the bigboy here in five minutes motherfucker I'm going to request again
>>
>>107492212
Oh you just remove all "white" columns/rows. That makes sense. So it's a nonlinear transform of the axis, that explains why I thought something else. Still if the input is very unfortunate it could barely have an effect at all, no?
>>107491993
>>107492202
I think the assumption is that Eric gives us all the extremal points of the polygon nicely ordered so this case isn't a viable input.
>>
>>107492202
breh it's so over. coord compression is not the golden goose I thought
but I can just insert fake points between every point that is not subsequent. so if my xs = [3, 5, 6, 9, 12] then it would compress to [1(3), 2, 3(5), 4(6), 5, 6(9), 7, 8(12)]. 2, 5, 7 are fillers. no filler b/w 3(5), 4(6) because 5 and 6 are subsequent
>>
>>107491993
if your solution does not recognize the lip as a rectangle obstruction you were filtered
>but if you read the story then you'd know that drawing a line between floor tiles doesn't create a barrier between them
don't care
if the input has extra steps just to create a lip then there's an obstruction and if you don't take that into account you were filtered
>>
>>107491919
what's your ans for this? anyone else doing coord compression try this too
0,0
8,0
8,3
3,3
3,5
8,5
8,8
0,8
>>
File: 9c.png (252 KB, 1065x1104)
252 KB
252 KB PNG
>>107491321
rewrote in c now it's 40ms
>>
i can't believe how many self proclaimed programmers use sqrt in their "efficient" solutions
if eric had been crueler and made precision matter half of them would be wrong too
>>
>>107490190
>/aocg/ - Advent of Code General #1
>#1
>>
explain coordinate compression to me in a way that doesn't make it sound like a solution for poora who cannot afford long long
>>
>>107492318
>I think the assumption is that Eric gives us all the extremal points of the polygon nicely ordered so this case isn't a viable input.
Reading this made me realize another way to detect the special coord is to calculate the manhattan distance of the points as you construct the perimeter and save those coords with a huge discrepancy from the norm (say x3 the previous distance). Pretty sure you end up detecting the points that make up the rectangle for the solution.
>>
>>107492375
addressed in spbp
>>
>>107492375
this is what happens if you don't tip your janny
>>
There are only five real stars left this year. Day 12 Gold will be collecting the other 23 stars.
Only five more stars and then we will have to wait a whole 'nother year for another twelve puzzles.
Can this year still be saved, with only five stars left?
>>
>>107492383
poors*
>>
>>107492272
2,2
9,2
9,9
2,9
2,7
1,7
1,6
5,6
5,5
1,5
1,4
2,4
If I didn't make any mistakes
>>
>>107492375
it's the #1 after 4chan 2 was launched yesterday
>>
>>107492355
>what is the largest area of any rectangle you can make using only red and green tiles?
all the rectangles inside the area are green or red
>>
>>107492318
can you describe the edge case? the one I found is >>107492356 where the compression removes the horizontal gap. but I fixed it with >>107492330

>Oh you just remove all "white" columns/rows
not completely remove it but reduce its length

>>107492425
64 64

>>107492383
we are all poor of time in this universe, anon
>>
>>107490503
can you share the source file?
>>
Contender for my worst broot in all of AoC. Unwashed aside from removing unused lines
from itertools import combinations
data = open("Day 09 input.txt", "r").read().strip().split("\n")
from time import clock
print clock()

nums = []
for i in data:
nums.append(map(int, i.split(",")))

leftmost = nums[0]
near = set()
border = set()
last = nums[-1]
for num in nums:
if num[0] < leftmost[0]: leftmost = num
for x in range(min(last[0], num[0]), max(last[0], num[0])+1, 1):
for y in range(min(last[1], num[1]), max(last[1], num[1])+1, 1):
for x2 in (-1,0,1):
for y2 in (-1,0,1):
near.add((x+x2,y+y2))
border.add((x,y))
last = num


perim = set()
queue = [(leftmost[0]-1, leftmost[1])]
while len(queue):
pos = queue.pop()
if pos in perim: continue
if pos in border: continue
if not pos in near: continue
x,y = pos
perim.add((x,y))
for x2 in (-1,0,1):
for y2 in (-1,0,1):
pos = (x+x2,y+y2)
queue.append(pos)

dirs = [[1,0],[0,1],[-1,0],[0,-1]]
largest = 0
check = 0
for a, b in combinations(nums, 2):
check += 1
if check%1000 == 0: print check
size = (abs(a[0]-b[0])+1) * (abs(a[1]-b[1])+1)
if size > largest:
edges = [min(a[0], b[0]), max(a[0], b[0]), min(a[1], b[1]), max(a[1], b[1])] #left X, right X, top Y, bottom Y
fail = False
for x in xrange(edges[0], edges[1]+1, 1):
if (x,edges[2]) in perim or (x,edges[3]) in perim:
fail = True
break
if fail: continue
for y in xrange(edges[2], edges[3]+1, 1):
if (edges[0],y) in perim or (edges[1],y) in perim:
fail = True
break
if not fail:
largest = size

print largest

>was worried about this case >>107488702
>start writing a flood fill around perimeter to check for instances of that
>wait, I can just use this against the rectangles as an easy check
>pypy go brrrr
Runs in ~160 seconds with pypy on my computer. A little ashamed coordinate compression didn't even cross my mind since I've used it in previous years.
>>
>>107492447
>BUT THE STORY SAYS
filtered and you probably defend files with zero bytes taking up space
>>
>>107492383
you're right, the answer to all parts of all days is actually 0 because you need to ignore the text
>>
>>107492223
only today
it's because eric threw a hard problem at casuals instead of slowly weeding them out
>>
>>107492590
>throwing a hissy fit because someone hated on your gay ass method
alright sorry
>>
The polygon/fence problem every year always pisses me off because I spend 3 hours every time accounting for different convex/concave geometries and then the input doesnt have any interesting edge cases. As far as im concerned you are all filtered if you arent casting from the outside to ensure your rectangle isnt in a cavity
>>
>>107492626
>casting from the outside
anon just draw a straight line from any point and count how many times you intersect the border
odd: inside polygon
even: outside polygon
>>
>>107492648
Yeah thats better im retarded. Gets rid of some 99999999s in my code lol
>>
>>107492359
whats wrong with sqrt'ing? a lot of t rust girls are sqrters
>>
File: code.png (326 KB, 1572x1698)
326 KB
326 KB PNG
Day   -Part 1-   -Part 2-
9 00:10:20 10:40:26

i made it bros... not filtered yet
>>
>>107492695
>10 minutes, 10 hours
>4 minutes, 4 hours
Day   -Part 1-   -Part 2-
9 00:04:44 04:14:30

spooky
>>
File: compress.png (10 KB, 989x629)
10 KB
10 KB PNG
>>107492478
Not an edge case just a case where it doesn't help much (picrel) if I understand right.
For something like >>107492356 my thought would be to do one preprocessing pass along the polygon to remove any "useless" intermediate segments.
>>107492520
https://files.catbox.moe/q2mi6a.zig at the bottom
>>
>>107492425
I get 64, 25
>>
>>107492796
wrong
>>
>>107492751
the thing is after compression your grid is guaranteed to become n x n (or 2n x 2n if you pad as I mentioned). the worst case will be when each point has a distinct x coord from every other and distinct y from every other point. this will mean the coordinate space will compress to width n. if points have a common x then width smaller than n will suffice

contrast that with the raw input where the grid can be arbitrarily large. but the no. of points are small (~500) but it should work for larger input too.

why manually find and remove useless intermediate segments when coord compression just works.

thanks for the code <3
>>
>>107491993
I get 64, 64
>>
>>107492695
maybe i am still filtered after all i just copied some rectangle overlapping formula and it worked but now i think about it more it doesnt make sense (even though it works)
idgi
..........
...C###...
.A##..###.
.#......#.
.#......#.
.#......#.
.#......#.
.###..##B.
...###D...
..........

it seems like rectangle from A to B would overlap rectangle from C to D so it would be considered non viable
so how does it work...
>>
>>107492863
what why would AB be non viable if it overlaps CD?
>>
>>107492891
within the bounds of the question it wouldnt be but within the algorithm i used it looks like it would be
which is why i am confused why it works
>>
>>107492686
you only care about the number for sorting
sqrt doesn't change the sorting (mathematically, and practically for our inputs)
>>
>To save Christmas, the Elves need you to finish decorating the North Pole by December 12th.
>9 days in, haven't done any decorating yet
>gaps above each calendar day for more puzzles
eric you madman
>>
>>107492863
>me when I cheat by reading other people's solutions and implementing them without understanding them
You make me sick.
>>
>>107492898
so next time when you waste space on aocg (atleast when it's still boomp able) atleast put your code and the puzzle text in sonnet 4.5 /gen
>>
>>107492936
its not someone elses solution, i was looking for algorithms on intersecting rectangles
who hasnt tried random shit out of desperation after spending many hours on puzzles?
>>
>>107492134
Thanks, didn't know that.
>>107492266
https://pastebin.com/S2NUq3NZ
It's singlethreaded and I'm running this on an old computer so I don't think it's your pc.
Grid2d is a grid supported on a 1d vec. You're probably gonna have to fix Coords and compressed Coords cause I made them a bit messy. At least that made it work on bigboy's negative inputs without any changes. I put in a main function for you but I run it differently so I'm not sure it's going to work out of the box.
>>107492356
I'm getting 81, 81. I initially inserted empty values around every coordinate but it didn't change anything for regular and bigboy inputs (except for runtime). I get 81, 36 if I do that for this input.
>>
>>107492957
me, desu
>>
File: rival.png (8 KB, 452x52)
8 KB
8 KB PNG
mathletsBTFO GET AWAY FROM ME
you were supposed to have been filtered today
>>
>>107492863
nevermind figured it out i had forgotten after trying too much random shit that im iterating the line segments not every point vs every other point
>>
>>107492863
>>107492898
you're filtered for copy+pasting a solution without knowing how it works
I don't know what you copied but I did something similar, except instead of C and D being any two points along the input, they can only be a line created by the input (so red tile C and the red tile after C)
if a line created by the input overlaps with the middle of a rectangle then the rectangle is invalid
..........
...####...
.A##..###.
.#......#.
.####C..#.
.....#..#.
.....#..#.
.####D..#.
.#......#.
.###..##B.
...####...
..........

(A,B) is invalid because it intersects with rectangle (C,D)
>>
>>107492989
line* CD
>>
File: hoes mad.jpg (69 KB, 750x562)
69 KB
69 KB JPG
>>
File: code.png (427 KB, 1838x3028)
427 KB
427 KB PNG
>>107492003
Behold the master of brute forcing.
This version took 3h15h03s.

Fuck efficiency. It is winter. Every CPU cycle is money saved on heating.
>>
>>107493031
although yes same thing if we're going by that copied solution
>>
>>107492989
>>107492986
>>
TICK TOCK CODELETS
>>
>only 12 hours to next puzzle

HOLD THE LINE
>>
looking forward to an NP-complete combinatorial optimization puzzle tomorrow
>>
>>107493097
i have a TSP O(n) solution that I'll only release to the world if eric (swt) integrates it into a puzzle
>>
>>107493059
I am always in awe of long successful brutes
to let it run so long is a supreme act of confidence
>>
using someone elses code isnt cheating if you type it yourself
>>
>>107493168
holy cope
>>
>>107493168
the man who can't be fucked to come up with the code won't bother typing it himself
>>
does using this count as cheating? https://www.geeksforgeeks.org/dsa/find-two-rectangles-overlap/
>>
>>107493214
>www.geeksforgeeks.org
Good evening, sir.
>>
>>107493223
first result when i bing "rectangle overlap algorithm"
>>
>>107493214
>jeetsforjeets
>>
>>107493214
I always use this one https://www.love2d.org/wiki/BoundingBox.lua
I can derive it myself but I never feel like it.
>>
File: 1703547102605.jpg (604 KB, 960x1280)
604 KB
604 KB JPG
Can I just get a small hint? I have found counterexamples to all of my solution ideas so far. Right now I am considering checking that the 4 corners of any proposed rectangle by raycasting out from them and if we cross a border we have gone out of the shape and thus is not a valid rectangle. I haven't exactly determined how I would detect a boundary crossing though. I feel like there is probably some simpler trick I can do that involves checking the corners against some criteria for each point in the list, but I haven't figured out the trick if there is one. If asking for a hint filters me, so be it, I still want to solve it without being told the answer explicitly.
>>
>>107493326
looks the same either way
>>
>>107493340
sounds like you are on the right track, a hint is you dont need to use raycasting
>>
>>107493238
How do you use the fact rectangles overlap? There are both cases which a rectangle can overlap and be just fine for the original and the opposite
>>
>>107493214
Finding the common area between two rectangles, or finding the common interval between two intervals is trivial though. You just take the maxes of the supposedly minimum points and vice versa.
>>
>>107490197
First, even for Rust this looks garbage.
Second, it's wrong. See this example where the biggest rectangle spans all but the first line:

..#X##X#..
#X#.XX.#X#
X...XX...X
X...XX...X
X...##...X
X........X
#XXXXXXXX#
>>
File: me.jpg (149 KB, 720x900)
149 KB
149 KB JPG
>broot solution is still running after 30 min
time to get a drink
>>
>>107493383
I know it's "wrong", it works for the input though.
Here is the "correct" solution btw: >>107491133
>>
>>107493363
its actually checking if your target rectangle overlaps one of the edges of the polygon (i.e. the "rectangle" you are comparing it to is just one line segment edge of the polygon)
>>
>>107493340
stop reading when you've got it
>take two points and build a candidate rectangle
>check if it's center is inside the polygon (raycast in one direction and count how many times it crosses (odd is in, even is out))
>for each line of the green polygon (k and k+1 (wrap at end)) check if it cuts the rectangle
>for vert, check if it lies between the y span of the rectangle, and if it's length covers the x span (this is to, more or less, see if the polygon line is on the edge it covers the full edge)
>for hor, vice versa
>>
>>107493388
abon (above anon) had his complete in 10 hours so you might be here for a while
>>
>needing to import a fucking AABB
grim
>>
>>107493441
my 10 hour wasnt broot it was retardation
>>
>>107493471
having to broot IS retardation if we're being honest, but today was a bloodbath so any port in a storm I suppose
>>
>>107493214
>is it cheating if I look something up and learn things
yes, if you did not derive all of your code from first principles alone you were filtered
>>
>>107493388
Im bruteforcing O(n^3) and it'sless than a second
>>
>>107493406
Thanks anon
>>
Friendly reminder to all Python brothers to use pypy
>>
>>107493536
shant
>>
>>107493489
I think mine is something like O(n^2 * max(n)^2)
>>
>>107493536
Usually it barely matters desu.
Half the time it's 20% faster, veryoccasionally it's a 100x faster, and the rest it's slightly slower.
>>
File: d09.png (207 KB, 728x1522)
207 KB
207 KB PNG
This got me the gold, but I am unsure if it works for all inputs. I just checked if there are any edges between two tiles.
>>
File: carbon.png (629 KB, 1970x3472)
629 KB
629 KB PNG
rectangles just make more sense if they're x, y, width, height, not this x1, y1, x2, y2 shit
>>
>>107491133
61s is too long for the approach you are using? I am getting 3.1s for the bigboy with >>107492212
what could be the reason? also, nice and concise impl, as always
>>
in 11 hours
>train A starts at 8 AM in western north pole heading east travelling 100 km/h
>train B starts at 10 AM in eastern north pole heading west travelling 200 km/h
>when will the two trains meet?
>>
File: 9.png (2.93 MB, 5708x9562)
2.93 MB
2.93 MB PNG
>>107492968
Thanks for the code. My old laptop is indeed very shitty, your code takes ~23s for the bigboy.
That's still more than 2x faster the my solution (>>107491133), turns out I made my grid way bigger than necessary which made the flood fill take 40s.
After fixing my code it now takes ~20s for the bigboy.
Are you sure that the heap actually helps you?

>>107493653
>>
>>107493617
try the edge case inputs posted above

>>107491133
try for
1,1
9,1
9,4
4,4
4,6
9,6
9,9
1,9

mine gives 81 36
check >>107492330 for the issue and the fix. lmk if you find other edge cases
>>
>compress grid to input x,y values only
>scanline to mark interior cells
>prefix sum for rectangle areas
>checking a corner pair is an O(4) lookup (does the prefix sum match the expected area)

My code may be ugly as shit but by God it's fast
>>
>>107493485
second principles. you're allowed to look up the dijkstra implementation on cp.com
>>
>>107493706
wdym scanlines? ray casting algo?

>O(4)
kek

btw share times for the bigboy
>>
>>107493706
you also check for >>107493687
>>
Obscure math trick puzzle tomorrow
>>
>>107493681
can you using the hashmap as a hashset to not insert duplicates in xs? rn you are sorting the all the points based on their x and then running dedup. just store some zero value in hashmap for each x and dedup using that instead. although, sorting an ~25k len array shouldn't amount to much

additionally, you can just pad the grid array with a fake top row and fake left column. this should avoid bound checks and a bunch of .map_or-s in an O(n^2) hot loop

also, instead of marking inside cells in grid mark outside cells. so instead of matching the area you can just check if the sum of subrect == 0

a Vec instead of a VecDeque works too for flood fill as bfs order doesn't matter here

can't see anything else

>>107493780
anything but whatever the first 7 days have been
>>
>>107493780
add this list of numbers tomorrow (part 2 is multiply them)
>>
File: carbon.png (10 KB, 942x88)
10 KB
10 KB PNG
>>107493780
I'm prepared
>>
>>107493675
wtf does east/west mean near the north pole
wouldn't they just drive in circles?
please clarify
>>
>>107493780
20 million dollar bounty for eric, all he has to do is come up with a problem that I can't crack with `import solution` (pro tip: he can not)
>>
>>107494013
>1 man vs the wealth of literally countless programmers building libraries over deacades
yeah i dont think he ever had a chance
>>
>>107494013
any problem not rooted in a single algorithm
can you solve the intcode puzzles (I didn't do that year)? what about cube folding? numpad robot? not enough minerals? falling cave tetris like thingy?
>>
File: bloodbath.png (139 KB, 738x987)
139 KB
139 KB PNG
here's my broot
$ time python3 solution.py < input
silver: 4790063600, gold: 1516172795

real 0m59.256s
user 0m59.244s
sys 0m0.012s
>>
File: gomi-gomi-dog.gif (149 KB, 488x498)
149 KB
149 KB GIF
>>107493388
>broot solution is still running after 1:30 hrs
lads, I'm beginning to worry
>>
>>107494089
Relax, you still have ~10 hours.
>>
>>107494089
20,000 people are watching their broots as we speak
>>
>>107494055
here's a tip eric next time you're white knighting yourself, ease into it instead of going whole hog off rip
>>
>>107494113
what if nobody has been filtered yet and they're just waiting for their day 2,3,4etc broots to finish? our broot brothers will join us, I believe in that
>>
>>107490503
I tried bruteforce by validating the perimeter of each red pair but my answer was too small. Also this fails on adjacent lines, but i don't think that happens.
>>
>>107494167
>24h is filtered, i'm afraid

>>107494089
now is the time to start shitting your pants
>>
>>107493681
Maybe you ran out of ram, it does take a lot longer if it starts swapping. Sorting took like 6 extra seconds, could also be low memory issue.
>>
>>107494089
You *are* trying to make a smarter solution while the broot runs, right?
>>
>>107494200
i believe ಥಥ
>>
File: Capture.png (3 KB, 406x41)
3 KB
3 KB PNG
Bloodbath today
>>
>>107494231
>bashar in power
>25 puzzles
>bashar deposed
>12 puzzles
not very subtle sheikh eric waslooni
>>
>>107494192
>this fails on adjacent lines
Yes it does; it's supposed to be ran on "true polygons" in lR^2, not these width-having grid-based ones.
Probably there's a much better way to do it for integer coords, but Eric was kind enough to make this work as-is.
>validating the perimeter of each rectangle
Should work, no? Maybe you just had a small bug. Better fix it and broot for another few hours (:
>>
>>107494159
all I see is a bunch of no arguments lmao stfu
>>
>>107490349
Hi, I'm one of the anons who skipped on yesterday and did today. I had a rough morning and no time to put more than a few minutes of thought into the puzzle.
>>
>people pointing out the zero gap problem.
fuck. glad that didn't show up in real inputs.
>>
>>107493485
>yes, if you did not derive all of your code from first principles alone you were filtered
as a baby I looked upon grains of sand and pondered hard to come up with mathematical theory. as a child I studied lightning during rainstorms in order to fundamentally reinvent circut boards and electrical currents from scratch. As a teenage I studied the vibrations of telephone and tv cables in order to completely reverse and build all modern hardware needed to connect to the internet. Now finally as an adult trans woman I have meticulously studied Rust docs in order to apply LGBT friendly patches to the GNU/Linux kernel and post code puzzle solutions online in Rust.
>>
File: images(6).jpg (6 KB, 185x273)
6 KB
6 KB JPG
EE here about to get filtered
120 lines just to build some helper data structures LOL
>>
>>107494435
is there a way to check if the programmer is straight and if so introduce a 5 second sleep call in their compiled binary? I'd like to work on that pr for the rust compiler
>>
>>107494491
you and 20,000 others lol
>>
idgi. why are people seething about the zero width tiles/gaps like anyone cares? i'm pretty sure the intended solution was basic 2D collision detection which is basically just 4 booleans
>>
>>107494530
First /aocg/? Quibbling over contrived edge cases is half the fun. Too bad Eric is only giving us 4 puzzles this year.

notice how this is the first day that could yield a funny calendar image. FUCK YOU ERIC YOU RUINED CHRISTMAS YOU FUCK
>>
>>107494530
if you're scanning right to check intersection no. parity, then you can ignore all horizontal segments
if ignoring horizontal segments, then there's no way to tell between a single segment and two joined segments
the solution is to omit the last cell in each segment, but it's an annoying edgecase
>>
>>107494518
Yes, the most straighforward way is to check if a user has discord installed. That alone guarantees queerness at a minumum standard deviation differential when compared to the general population. Also, Blender.
>>
File: 1753468989334632.gif (227 KB, 220x221)
227 KB
227 KB GIF
>>107494524
helper data structures verified to be working, we are so back
>>
>>107494563
hmm... I guess?
the easiest sln i can think of is similar to half assed game of life paper rolls thing. you can just pick through a window of three lines, remove the ones that are zero width, repeat til none left... shouldn't be too hard.

let me try some of the reddit ones and see.
>>
>>107490931
>14 seconds and I get 26813976 for part 2

It's absolutely over
I wish I'd been filtered earlier to save me from this humiliation
>>
File: 09.cc.png (626 KB, 1988x3182)
626 KB
626 KB PNG
Ugly ass C++ code that will not work on the corner cases in this thread, but got me my two stars. Maybe I will come back to this archived thread over christmas and try to make it faster and more correct.
>>
>>107494731
part 2 is implementation dependent, this bigboy isn't "proper" so to speak
>>
>>107494530
nvm... I now have to check concave / convex in the polygon since biggest rect fitting in a valley causes issues.
>>
hold up
why does my input have duplicate points
>>
>>107494928
Redownload it, you fucked up.
>>
Is there anything smart you can do in part 2 to avoid checking all pairs
pls respond
>>
>>107494955
import shaply
>>
For graph compression to solve this maze one
https://everybody.codes/event/2025/quests/15

Would this go to like
    #######
# #
# #
# #
# #
# #
#### #######
# #
# ........ #
#### .######S #
# .# #
# .# #
#### .####### ####
# . # #
# . # #
# .E #######
# #
# #
#######

To like this and then you can just do regular A* on the small guy and you're storing the distances of both the horizontal and the vertical compression seperately for when you need to go up/down or left/right?
   ####
# #
### #####
# #
### ###S #
# # #
### #### ###
# # #
# E #####
#####
>>
>>107494955
Yes but you need an insight of what the overall shape all points are drawing. Then you can find two points that are not quite the same as all others. One of those is part of the part 2 solution.
>>
>>107494955
you could create a spatial grid on the 2d space (say divide the region into 100x100 chunks). for each segment of the green polygon, check it's span, and add it to all bounding boxes it's going through. then, when you're checking candidate rectangles, you can only check polygon segments that are in the cells that the rectangle occupies, instead of all segments.
>>
>>107494563
True.
Remember the retards who couldn't conceptualize a file of size 0 last year? Lol good times
>>
>>107495081
how much space does a 0 sized file take up?
>>
Tomorrow is the great filter
>>
>>107494530
yeah you kinda have to swtich to bitmap understanding, so to say.
where interval <1;1> occupies one pixel
>>
>>107495110
>8 and half hours to go
hold the line
>>
I'll be honest. I whiteboarded a solution that depends on the shape being convex(y) and it utterly fails for meme concave shapes. it's over. I have been, le filtered.
>>
my input compression does not work. I'll go take a shit to think this through, I'm missing something obvious
>>
File: nom burger.jpg (51 KB, 277x632)
51 KB
51 KB JPG
>broot finished
>wrong answer
>>
>>107495093
how much space its filesystem entry costs. directories aren't free
>>
>>107495093
>>
>>107495081
the way the problem worked, the concept of zero sized file was undefined.
>>
File: 1761414157532928.gif (605 KB, 265x264)
605 KB
605 KB GIF
>>107494491
Based EEbro you did what I couldn't yesterday, today I managed to solve it.
>>
>>107494491
Another EE here. I just put everything inside matrices. I know it is hard without all that knowledge but you can do it
>>
File: 1749429432429512.png (511 KB, 1810x2094)
511 KB
511 KB PNG
>200ms to start up
>actual calculation finishes instantly
A numpy kind of feel.
>>
Filter graph anon here.
I'll probably be sleeping at the time I should make the graph but this one is going to be epic, I don't want to miss it. So can you download those 2 json files in the last hour before midnight EST please? Upload them on catbox or pastebin, I'll make the graph from them when I wake up. Also it'd be great if you'd save the Unix timestamp when downloading them.

https://adventofcode.com/2025/leaderboard/private/view/224303.json
https://adventofcode.com/2025/leaderboard/private/view/383378.json

pic rel is yesterday's graph
>>
File: wall.png (358 KB, 521x687)
358 KB
358 KB PNG
>>
>>107495596
> "completion_day_level": {
> "2": {
> "1": {
> "get_star_ts": 1764660007,
never mind
>>
File: carbon(3).png (907 KB, 1784x7804)
907 KB
907 KB PNG
finally got it, though i guess i'm technically filtered since i wouldn't have finished without the "compress the points" hint i got from these threads

almost fucked it because my floodfill around the exterior wasn't working until i realized i needed to add a little bit of buffer space so i could fill around the edges
>>
>>107495596
wtf, I tried to find myself, turns out I was in the wrong leaderboard this whole time.
>>
>>107493059
>Behold the master of brute forcing.
>This version took 3h15h03s.
And I thought my 6s solution in pure Tcl was brute forcing! lol
>>
>>107495892
filtered
>>
File: image.png (80 KB, 398x321)
80 KB
80 KB PNG
>>107495898
But I have all stars
>>
Forgive my ignorance, but what do you guys mean when you say "compress" the input in this case? I solved it by just checking if we ever intersect an outer edge on a candidate rectangle. I know that won't work in all cases, but for the input Eric gave us it did. I am curious about these other approaches though, so I am trying to understand them.
>>
>>107495926
>45 minute difference between parts on day 1
bruh
>>
>>107495159
>>107495182
here's what worked for me

>makes list of x vals and list of y vals from input as well as an ordered list of the coordinates
>sort each list
>make compression dicts for each where you iterate through the list and map idx to the real coordinate (make the reverse dicst to where coordinate maps to idx)
>make a set for your boundary
>iterate through your list of corner coordinates from the input. compress the coordinates using your dict. save those compressed coordinates to a set and also save them to your boundary set. with each iteration, find the points between the current corner and the last corner you checked and add those points to the boundary set as well
>don't forget to link the last point to the first point or you're fucked
>now make a set for exterior points
>start at coordinate (-1,-1), which is guaranteed to be outside your boundary, and flood fill (stop if the point is in your boundary set or is less than -1 or greater than 1+ your biggest compressed x/y)
>now you have a compressed set of point that are outside your shape
>iterate through your compressed corners to form rectangles and check every point in that rectangle. if none of its points are in your exterior set, it's a valid rectangle.
>get the biggest area (uncompress the points when doing the math using the dicts you made in the beginning)
>>
>>107490852
i did the exact same thing
>>
>>107495971
if you sincerely look through this thread and the previous you will find your answer
>>
>>107495971
Suppose you're given these X or Y coordinates: 123, 2468, 47996, 99999
Replace them with this: 1, 2, 3, 4.
All you're doing is removing the blank space between them. This shrinks the grid size from 100000x100000 to at most a few hundred in each axis, trivial to brute force by checking every point along the edges.
Just make sure to remember what the coordinates originally were for the size calculation.
>>
>>107494999
the compression people are talking about is where essentially the only x and y values you care about are ones for the corners

so if you have a rectangle with the following corners:

(500, 2000000)
(1600, 2000000)
(1600, 50)
(500, 50)

you just remap things so the coordinates become
(0,1)
(1,1)
(1,0)
(0,0)

obviously that's a simple example with one rectangle but i can't be fucked to write out a longer one. you could probably do something like this for that EC problem, but for the points you compress, it wouldn't just be the boundary corners, it would some points around each corner
>>
>>107495467
>>107495577
Thanks EE bros, i think now im on the right track. Previous approach was worthless, but it is being fun
>>
>>107492223
idk but it's probably a combination of the fact that this was a significant ramp up in difficulty given how piss easy the past week has been, meaning a lot of shitters are still in it, but also the part one was extremely easy so the remaining shitters got through it fine
>>
>just realised I have a different compression to everyone else
>>
File: file.png (2 KB, 116x53)
2 KB
2 KB PNG
well well well
the broot finished
>>
File: I_KNEEL.png (403 KB, 600x906)
403 KB
403 KB PNG
>>107496331
>>
bros, i've never made it to the third to last day of aoc before... maybe i'll actually finish now that it's half as long
>>
>>107496121
>brute force by checking every point along the edges
People did that? Huh; there I was working out how to tell if a line segment intersects a rectangle efficiently. (It's not that complicated to do, but it's a little easier if you think about the complement instead.)
>>
File: 4234234.png (1.48 MB, 1984x6756)
1.48 MB
1.48 MB PNG
Finally got it. Spent hours because I didn't read `very red tile is connected to the red tile before and after it by a straight line of green tiles. The list wraps, so the first red tile is also connected to the last red tile.` and I tried to connect red tiles basically at random. Then I spent another few hours because in my calculate_area() function I had `(x1-x2+1).abs()*(y1-y2+1).abs()` instead of `((x1-x2).abs()+1)*((y1-y2).abs()+1)`

```
cargo run --release 51.79s user 89.26s system 91% cpu 2:34.29 total
```
>>
>>107496389
Intersection checks are always a pain in the ass, while broot just werks and takes care of all edge cases.
Easy enough to shit out a quick broot and let it run while working on a smarter solution.
>>
File: AoC-09-stars.png (25 KB, 725x317)
25 KB
25 KB PNG
>Still more silvers than golds
>>
>>107493059
Very nice.
>>
>only 3 days left
Please tell me your day 13 puzzles are done. I am genuinely depressed over this
>>
>>107496410
How? Mines a broot too and runs in 0.4s
>>
>>107496526
Don't be depressed.
Just remember the time enjoyed.
>>
>>107496526
Mine is ready to go, I just need to proompt the website
>>
>>107496526
Join us for Everybody Codes next year. I'm on 29 daily puzzles in a row (plus the latter half of an old AoC year I ground out during EC's weekend breaks) and I'm ready for it to be over.
>>
>>107496486
>>107495720
>>
>>107492357
Nice code.
>>
File: aoc09.png (890 KB, 1280x8177)
890 KB
890 KB PNG
holy smokes I got my two stars but at what cost
>>
Generating, filling and working on a ~96k x ~96k grid of 3bit elements takes time. I didn't focus on optimizing the solution, just wanted it to work
>>
>>107496656
just better hope you didn't fuck something up and have to run it again
>>
File: 2025_day9.png (243 KB, 1643x2325)
243 KB
243 KB PNG
Finally a good puzzle, Eric and his "death star" looking contraption got me. I had some stupid mistake, so went to bed and of course caught it first thing when I woke up. Still room to optimize it a bit.
>>107492984
Bring it.
>>107496331
Based.
>>
>>107490349
i decided to sleep on it and then couldn't work on it til after lunch. looking at the leaderboard now, i'm kind of surprised how good we're looking, got at least like 70 people who are caught up now
>>
>>107496728
someone posted the shape last night and i found the coordinates in my input for the end of the tunnel. i knew one of those ends would have to be one of the corner points and almost made a cheeky solution that just hard codes that and then looks for opposing corners that makes sense, but decided to just do a real solution.

curious if anyone went that route tho
>>
File: 1724031593621568.png (163 KB, 399x498)
163 KB
163 KB PNG
but can your solutions handle this bad boy
1,1
20,1
20,5
17,5
17,3
4,3
4,5
1,5


...................... 
.#..................#.
......................
....#............#....
..... .....
.#..# #..#.
>>
>>107496758
I may have messed up the chungus at the bottom by not adding enough empty space
>>
>>107496650
based
>>
>>107496758
Yes.
>>
>>107496758
I get:
100
51
>>
>>107496758
100,51
>>
>>107496758
i got 100, is that right
>>
>>107496650
I really like that you can mark a function as "pure". Fortran continues to impress me.
>>
>6 hours to go
COME ON BRUTE YOU CAN DO IT
>>
>>107496835
I imagine the compiler will be able to determine it most of the time but at least it enforces the intent on the user
>>
>those 8 people who bothered joining the leaderboard and didn't get a single star
shameful
>>
>>107496823
>>107496805
should be from what I can tell
I have a bug that fails to mark the big open space with 3 edges at the bottom as invalid
>>
>>107496854
>5 hours later
>teehee OOM :3
>>
>>107496882
beats teehee integer overflow
>>
File: canvas.png (10 KB, 497x495)
10 KB
10 KB PNG
>>107496728
I got the rhombus.
>>107496758
100
51
>>
>finally compress the coordinates
>get this

.#.#
##..
#.#.
..##


>even though the relationships are preserved the largest rectangle is not

Sheeeeiit
>>
File: 1canvas.png (144 B, 9x9)
144 B
144 B PNG
>>107496929
It should look like the image.
>>
>>107496929
I didn't do that, but my understanding is you flood fill a rect and if it's a valid rect then recover the original corner coords to do area calc.
>>
I worked myself into a shoot, brothers. I kept chasing the incorrec thing.
I managed to solve it eventually.
>>
File: aoc-day-9-sloppa.jpg (1.14 MB, 1408x768)
1.14 MB
1.14 MB JPG
>>
my algorithm picked 2 random vectors, checked area of rectangle, got gold
>>
File: Capture.png (27 KB, 366x326)
27 KB
27 KB PNG
>>107496751
>curious if anyone went that route tho
yes, i am the one that posted the shape and I am also the one that did that

don't tell eric
>>
File: despair.jpg (29 KB, 520x476)
29 KB
29 KB JPG
>>107497012
ebin, but it hurts
still brooting, 6:30 hrs in, 5 hrs left, hope is leaving me faster that all the electricity I'm wasting
>>
>>107497092
Surely you have a progress counter? Will you make it?
>>
>>107497080
extremely based, brooters and mathfags should kneel before hard-coded single-use script chads
>>
>>107497103
os killed the program hours ago, his terminal is just frozen
>>
>>107493863
BUT
in reverse
>>
This solution is horrible. It fails for edge cases not in input and accounting for them would make the code even messier. It feels like it shouldn't run fast. Compressing the coordinates to run localized checks would far smarter but I'm honestly done at this point.
At least I'm not filtered though.
>>
>>107496929
>doesn't work on example
>works on real input

Holy shit, I'm saved!
>>
File: file.png (5 KB, 332x104)
5 KB
5 KB PNG
that's it? that's the whole game?
>>
what do you mean I can't create a 78gb array computers fucking suck man I swear
>>
>>107497149
lol
>>
>>107497231
>he didn't buyed 128gb ram before october
>>
Bros how bad is day 10 going to be? Will I throw my computer out of a window? This day almost made me.
>>
>>107497268
Chinese remainder theorem problem incoming
>>
>>107497220
More people got silver today than they did yesterday by the way. Also its the first day that most people with silver didn't get gold.
>>
File: 1744981552030495.png (7 KB, 250x114)
7 KB
7 KB PNG
oh no...
>>
>>107496389
compressing is efficient
the problem with doing an array on uncompressed values (beyond the size) is that you check all numeric values, where 99% have no significance in regards to the input, so just checking every rect against every edge is faster than checking 1B cells average for a rectangle
after compressing every single cell has a logical meaning, it represents a combination of 2 (or more) edge in the original input
even though you've added a dimension you need to check, you've also gained the ability to discard the vast majority of edges you need to check each rect
>>
Ok how did you homos solve it?
I drew some shapes like the example on my board, played around with some comparisons and points and got something that worked well, but only if the shape isn't significantly concave, like a giant bowl. I assume zero width space to be invalid since it seems nonsense (For this problem, the perimeter one was different but also easier).

I can't think of a good, fast, solution for simply connected arbitrary polygon for this problem.
>>
>>107496410
>uncompressed grid
yikes
https://doc.rust-lang.org/std/primitive.u32.html#method.abs_diff
>>
look ma no loops.
any array language anons
>>
>>107497422
are you like that other anon that didn't read the question properly and is trying to guess the shape?
>>
File: 1761191658405458.png (5 KB, 565x353)
5 KB
5 KB PNG
I just did an overlapping rectangle function comparing between all rectangles and all edges for part 2 and it worked perfectly. I made the assumption that no geometry like pic related existed and it appears to have been the case

no idea how I would take this into consideration lol
>>
File: carbon(157).png (1015 KB, 1394x6068)
1015 KB
1015 KB PNG
>>107497422
>I assume zero width space to be invalid
Same, I just assume that if any line segment intersects the interior of the rectangle then it should be disqualified.
>but only if the shape isn't significantly concave, like a giant bowl.
I also had this issue but fixed it by making sure that the loop goes through all four quadrants (+/-x,+/-y) in order relative to one of the corners of the rectangle.
>>
>>107497268
Part 1 will be easy but part 2 will probably filter you for good.
Honestly, more anons should have been filtered last night than actually were. He have some cheaters ITT
>>
>>107497481
I just "guessed" the shape would behave and it did. That's it...
>>
>>107497422
Two viable ways to solve it is to
1: check if a line crosses your rectangle for a given rectangle or
2: compress the grid and flood.
You can propably combine the above.
Im pretty stumpted as far as a solution without much complexity goes however
>>
>>107497504
the vertices are sequential and form a loop, either X or Y is the same from the previous vertex
>>
>>107497489
this + a 0-wide gap insert into the best rectangle would've been a BLOODBATH
>>
>>107497548
even better if there was a maze leading up to the 0 wide gap.

I could have sworn we have a solution for something like that from a previous year though? something about pipes and needing to know which side of the edge is exterior & interior as you follow it. something like that could tell you if your rectangle is inside or outside
>>
>>107497519
The problem with 1 is the concave case though. You can naively do some intersections per edge of the poly, but if your rect fits in the concave void, it's over.

I thought some more on it and wonder if I can encode which side of a poly edge faces "out."

>>107497533
Are you suggesting scanning like a beam? Like cross through x, x+n, then go down til out? Hmm.
>>
FUCK YOU ERIC WHAT THE FUCK IS THIS POLYGON
>>
>>107497500
stay mad faglord I got my star
>>
>>107497597
it's only 9.4GB in ascii, print it out and look
>>
>works on test input
>fails on actual input
FUCK YOU ERIC YOU FUCKING FUCK TONGUE MY ANUS YOU NIGGGGGERR
>>
>>107497597
Tbh it's probably your best friend if you actually understand it. It's a very forgiving one and your answer is probably near the cut.
>>
>>107497595
for your concave case you'd just need to add in a check that the rectangle is inside/outside the polygon e.g. ray casting from centre of the rectangle
>>
>>107497612
64 bit int?
the other trip up for me was walking my edges, I accidently 1 outside of the array before doing my n-1 & 0 check generating a fake condition
>>
>>107497595
>You can naively do some intersections per edge of the poly, but if your rect fits in the concave void, it's over
this is >>107497489 this edge case, you don't need to consider it for gold
>wonder if I can encode which side of a poly edge faces "out."
also known as being clockwise or a counter-clockwise polygon
looking it up online you can figure it out by calculating the signed size of the polygon, if it's positive, it's the order you checked in, if it's not it's in the opposite
>>
File: grim.png (92 KB, 1318x554)
92 KB
92 KB PNG
>>
>Advent of Off By One

I solved it, but I still consider myself filtered because I had to resort to python.

Fucking geometry problems kill me every year.
>>
File: ocaml9.png (1.36 MB, 1586x6916)
1.36 MB
1.36 MB PNG
shame:
1. seeing the shape
2. instantly solving p2 after seeing >>107497629 - I'd already given up twice on raycasting to fill the shape and was working with a much slower method that only does a single cast to flood from a single inside tile

even so I enjoyed the mmapped bigarray.
>>
>>107497519
>2: compress the grid and flood.
I flooded without compressing the grid, what do I win
>>
>>107497422
Compress
Mark each cell as interior or exterior with scanline polygon fill
2D prefix sum over compressed range
Rectangles are interior iff prefix area == coordinate area

Be slower than other anons
Waste your evening adding binary search range subtraction only for runtime to increase because bigboy isn't a simple polygon and most tiles are interior
>>
Can I assume that if any point is within the rectangle (not on the line) it is definitely invalid?
>>
>>107497878
Big RAM award.
>>
>>107497991
Yes
>>
File: 2025-09.png (535 KB, 1900x2356)
535 KB
535 KB PNG
$ mix aoc.solve -y 2025 -p b -r input/real -d 9 -b 1
4755429952
1429596008

Ran in 152.377ms

Naively did AABB without considering possible weird shapes and it worked anyway. I noticed some of the perimeter segments were really long, so I sorted them by length thinking that the longer ones would be more likely to be overlapped and cause more potential rectangles to fail earlier. Ended up cutting the runtime by about 75%.
>>
>>107497991
For the input yes, but given Eric’s own rules, no. This would technically be a valid input that is a counterexample to such logic:

……..
.#X##X#.
.X.XX.X.
.X.XX.X.
.#XXXX#.
……..

The answer would be the whole rectangle.
>>
>>107497818
cheaters. p1 was so easy that it might just be there to ridicule them for not doing p2. such small gap means most people just submitted others solutions while coping that they understood it
>>
>>107497422
Compute all rectangle areas for all point pairs.

Sort by that computed area.

Find the first candidate rectangle that satisfies the condition of not enclosing another point or midpoint.
>>
>>107497991
Sorry, the formatting here: >>107498168 got messed up. This post here illustrates the point better: >>107493383.
Like I said though, it’s not relevant to Eric’s input.
>>
Did AI handle this one? Or is there still a use for bioBrains?
>>
>>107498192
Isn't this still basically weak to >>107497489 ?
>>
Just over 3 hours to go faggots, and then you're filtered, forever. I bet none of you would have believed last year that you'd be filtered by 2025 day 9, kek.
>>
>>107498332
actually i did get filtered last year on day 9 pt2 last year, my worst showing ever
>>
>>107494563
eric always throws soft balls. the question you should be asking is are you a soft boy?
>>
As we are now in Eric's reign of terror phase, what trouble awaits us tonight? Multi-agent path finding puzzle? 3D grids? Adding up all the numbers in a list?
>>
>>107498392
Last night's puzzle had path finding elements so I'd say we're due for some lame math shit.
Get ready nerds, brootchads will need formulas asap. No excuses.
>>
Tonight is the reverse engineering problem.

BTW, day 12 is implementing most of an operating system.
>>
>>107498452
AoC# anon, you didn't check the input?
just boot the image up in qemu and you're done. did you think you're really supposed to follow that ENORMOUS task? If you read carefully there are plenty of lines like
>You sure hope you don't really have to do this.
>Maybe the elves left a perfectly good emulator around here.
>>
File: screenshot.png (141 KB, 1140x1752)
141 KB
141 KB PNG
>>107497422
Store all horizontal/vertical connections between consecutive red tiles in dataset. Sort each segment by y/x positions.
For every possible rectangle, calculate if any part of any horizontal/vertical segment is inside the rectangle. Save the area of the largest rectangle that does not meet this criteria.

it's O(n^3) but still runs <1s
>>
>>107497422
Part 1 is trivial obviously.
Part 2, compute the 4 corners, then “walk” from the top left corner to the bottom right corner through the other two. If we ever crossed through a boundary, it’s invalid.
>>
>>107491321
>ag, au
You know there's no such thing as argentum stars, right anon? They're all aurum.
>>
why is the slow version so... weird?
https://www.youtube.com/watch?v=UxvmdR7oYdQ
>>
NEW THREAD
>>107498650
>>107498650
>>107498650
>>
File: ronaldinho-sonhar.gif (103 KB, 640x480)
103 KB
103 KB GIF
>>107494491
>>107494524
>>107495577
>>107496196
Solved! it takes 4 seconds for p2
bigboy is running as we speak

Feels good
>>
File: screenshot9.png (15 KB, 1144x1150)
15 KB
15 KB PNG
easiest to draw with svg
(* ocamlfind ocamlopt -linkpkg -package str -O3 -o draw draw.ml *)
let read file =
In_channel.with_open_text file
(In_channel.fold_lines
(fun ((lx, ly, hx, hy), points) line ->
match Str.split (Str.regexp ",") line |> List.map int_of_string with
| [x; y] -> (min x lx, min y ly, max x hx, max y hy), (x, y) :: points
| _ -> failwith "read")
((max_int, max_int, 0, 0), []))

let svg file ((lx, ly, hx, hy), points) =
Out_channel.with_open_text file (fun out ->
Printf.fprintf out
{|<svg width="%d" height="%d" viewBox="0 0 %d %d" xmlns="http://www.w3.org/2000/svg"><rect x="0" y="0" width="100%%" height="100%%" fill="#000000"/><polygon points="|}
(hx - lx) (hy - ly) (hx - lx) (hy - ly);
List.iter
(fun (x, y) -> Printf.fprintf out "%d,%d " (x - lx) (y - ly))
points;
Printf.fprintf out
{|" fill="#ff0000" stroke="#ff0000" stroke-width="4"/></svg>|})

let () = read Sys.argv.(1) |> svg (Sys.argv.(1) ^ ".svg")

screenshotted because image converters don't really like the uncompressed dimensions
>>
>>107498452
import os
>n-no it'll be harder I SWEAR!
will it really
>>
File: 1.png (23 KB, 915x600)
23 KB
23 KB PNG
AOC flavor of C++23
It can broot the input in 29ms.



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