[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: 1764826614494100.webm (270 KB, 556x556)
270 KB
270 KB WEBM
visualization 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: >>107430428
>>
File: 2024.jpg (1.53 MB, 4100x2300)
1.53 MB
1.53 MB JPG
Would any anons be interested in doing a /g/ summer of code?

I don't want to lose you guys.
>>
>>107439584
Doing AoC with you retards is unironically the highlight of my year.
>>
MASSIVE FILTER INCOMING HOLY SHIT
>>
>>107439639
in b4 reversing a string puzzle
>>
>>107439584
i think people unfortunately really underestimate the amount of effort it takes to write decent puzzles. the only thing /g/ could do better is write puzzles that slightly more advanced or more nuanced, as they'd be able to target people on /g/ specifically instead of trying to write puzzles for everyone. that'd just make it harder, though.
>>
please dont be a dumb
>repeat this 200 million times haha just find the cycle task
we had almost b2b2b cycle tasks last year or the year before and it got a bit much
>>
File: file.png (57 KB, 1200x1200)
57 KB
57 KB PNG
Making these all two parters is definitely extra work for what should be quick sketches.
>>
>>107439676
holy soul
>>
File: file.png (63 KB, 1200x1200)
63 KB
63 KB PNG
It's worth it though
>>
>>107437262
oh so a x=max(dropRight(row, batteries - 1)), return [x, ...recurse(splitAfter(row, x), batteries - 1)]
?
I tried that too and that wasn't that fast...
>>
>>107439676
>>107439688
the post that saved /aocg/
>>
>>
>>107439676
>>107439688
these posts are honestly the best part about this year's aoc
>>
>>107439676
>>107439688
I love you drawanon <3
>>
>>107439584
Cant write good puzzles for shit :D
I really like the idea tho
>>
>>107439584
>>107439651
people decide to do this every year and never actually do it
>>
>>107439584
It's over anon. We all made our peace last year.
>>
>>107439926
It's the "We should totally start a band, guys" of AoC.
>>
How's the difficulty like this year? Did eric make them harder to compensate for having fewer puzzles?
>>
>>107439998
lol good one
>>
>>107439998
too easy so far.
>>
>>107439998
honestly this is my first year and at the moment i'm not finding it that difficult (i'm not as fast as many people here but the problems themselves are fairly easy)
>>
File: 1762060070236304.jpg (14 KB, 400x400)
14 KB
14 KB JPG
>ruins your christmas
>>
File: Capture.png (16 KB, 394x368)
16 KB
16 KB PNG
>>107439998
Difficulty increase soon™
>>
File: day4.webm (1.36 MB, 560x560)
1.36 MB
1.36 MB WEBM
C23, iterative with backtracking (see video) and memory mapped file.
Bigboy https://files.catbox.moe/pj1x30.7z in 780ms.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
typedef struct { HANDLE f_, m_; char* begin, * end; } MemFile;
MemFile Map(const char* s) {
MemFile f = {0, NULL, 0, 0};
do {
f.f_ = CreateFile(s, GENERIC_READ, FILE_SHARE_READ,
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (f.f_ == INVALID_HANDLE_VALUE) break;
LARGE_INTEGER z;
if (!GetFileSizeEx(f.f_, &z)) break;
f.m_ = CreateFileMapping(f.f_, 0, PAGE_READONLY, 0, 0, 0);
if (f.m_ == NULL) break;
f.begin = (char*)MapViewOfFile(f.m_, FILE_MAP_READ, 0, 0, 0);
if (!f.begin) break;
f.end = f.begin + z.QuadPart;
} while (0);
return f;
}
void UnMap(MemFile* f) {
if (f->begin) UnmapViewOfFile(f->begin);
if (f->m_ != NULL) CloseHandle(f->m_);
if (f->f_ != INVALID_HANDLE_VALUE) CloseHandle(f->f_);
}
#include<stdio.h>
int main(int argc, char** args) {
if (argc != 2) return puts("Missing filename");
auto in = Map(args[1]); size_t w = 0;
for (auto it = in.begin; it != in.end; ++it)
if (*it == '\n') { w = it - in.begin + 1; break; }
if (!w) return puts("No end line!");
auto h = (in.end - in.begin + 1) / w;
auto m = w + 1;
auto size = (h + 2) * w + 2;
char* v = malloc(size);
auto p = v;
for (auto end = v + m; p < end; ++p) *p = 0;
for (auto it = in.begin; it < in.end; ++it) *p++ = *it;
for (auto end = v + size; p < end; ++p) *p = 0;

#define ITERATE(...) \
for (int i = m, z = size - m; i < z; \
i = si < 8 ? li + dirs[si++] : i + 1) { \
if (v[i] < roll) continue; \
int c = 0; \
for (int d = 0; d < 8; ++d) c += v[i + dirs[d]] >= roll; \
if (c >= 4) continue; \
v[i] = '0'; \
__VA_ARGS__; \
}

size_t p1 = 0, p2 = 0;
const int dirs[] = {w-1, w, w+1, -w-1, -w, -w+1, -1, 1};
int si = 8, li = 0, roll = '0';
ITERATE(++p1);
p2 = p1, roll = '@';
ITERATE(si = 3, li = i, ++p2);
printf("%llu\n%llu", p1, p2);
free(v);
UnMap(&in);
}
>>
Firstly, on behalf of all my friends and colleagues who also do AOC, a big thank you to Eric. AOC is simply the most elegant, funny and creative coding challenges I have ever come across. I find myself constantly in awe of Eric's work - when I am struggling through a problem, he is operating of a whole other level, creating these problems and generating different input data etc. It is also so impressive the way AOC caters to literally every level of programmer out there, from beginner to seasoned dev. AOC is always part of my recommendation when others ask me how to get into programming.

Amid all the noise of our weird modern world, especially in the programming space, I find AOC is a great way to reconnect with my simple love of programming and problem solving.

I also wanted to comment on a few changes I noticed in AOC 2025

There is no global leaderboard in 2025

There will be 12 days instead of the usual 25

For details, please see https://adventofcode.com/2025/about#faq_leaderboard

Congrats to Eric on making these changes

If you read the link above, the global leaderboard was clearly causing many issues and people were losing sight of the spirit of AOC. I love the bold move to simply remove it. I wish Product Managers I have worked with in the past had the guts to make decisions like this.

Everyone has a limit and kudos to Eric for recognising his and making required changes. I 100% prefer having 12 days of AOC rather than no AOC at all.

Also, to those who are smashing the AOC API, pls take a chill pill. This is why we can't have nice things!!!

Tldr: Eric, you're a legend, thank you, let's all enjoy another year of AOC
>>
>>107440284
cant tell if this is chatgpt or reddit
>>
File: images.jpg (7 KB, 249x203)
7 KB
7 KB JPG
>>107440299
>>
I think I've come to the conclusion that JS/TS is objectively the best scripting language.
It's
>fast: about as fast as a scripting language can be
>supports a wide variety of paradigms: can be super functional, imperative, even OO
>hyper permissive: you can do whatever you want with it, including have it be restrictive if that's your thing
>universal: the browser is your repl

The only other one that comes close is Python and, the more I think about it, the more I realize its primary use-case is letting no-coders and eggheads write programs.

Why don't you use the Script?
>inb4 saar
>>
>>107440284
Just wanted to second this, regardless of how long Advent of Code is or whether or not there is a global leaderboard, AoC has legitimately become one of my favorite holiday traditions and I am very thankful to Eric for all his hard work with the puzzles each year. I know it's a ton of work and a lot of stress, but thank you for all that you do, December wouldn't be the same without you!
>>
>>107440299
ChatGPT was trained off Redditors so it's virtually indistinguishable
>>
Is everyone ready? I can't wait for the new puzzle.
>>
>>107440284
it infuriates me that so many of these redditfaggots are sucking him off for removing the global leaderboard, none of them were making it on there anyway so it literally doesnt affect them
but OH NO IT HURTS MY FEEFEES so gotta remove it
>>
File: eric1.jpg (4 KB, 414x414)
4 KB
4 KB JPG
>>107440284
Hello yes I am Eric. Please delete your post as I believe it contains copywrite material. The numbers 2025 and 12 and 25 are private input data I use for my puzzles. Thanks for your understanding. Please kindly leave your contact information so my lawyers can sue you.
>>
>>107440353
wait, are there no rankings at all? or is it just the top 100 leaderboard that is gone? in the past years it used to show things like 2000/5000 (silver/gold) for each part for yourself; do they still have that too?
>>
>>107440379
>in the past years it used to show things like 2000/5000 (silver/gold) for each part for yourself; do they still have that too?
nope this is gone since it is basically the leaderboard
>>
>>107439676
based
>>
>>107440379
No, the closest you can come is to go check the stats page after you submit a correct answer and see how many gold/silver numbers are there, and you'd have to manually record it to keep track.
>>
Getting a top 1k time was always a great feeling for me. I got my last top 1k time and I didn't even know...
>>
File: 1735666599323149.png (26 KB, 744x235)
26 KB
26 KB PNG
>>107440316
>>
>>107439676
>>107439688
blessed
>>
File: day3go.png (98 KB, 650x1315)
98 KB
98 KB PNG
Baby's third Go program.
>>
>>107440416
Yeah, I'm with you Anon. I'm not the fastest speed coder but it was exciting to be in the top 1000. Without any sort of ranking on the personal times page the fast times I get hardly mean anything.
>>
>>107440488
780 ms on bigboy
>>
>>107440427
Here it is compared to Python, which is the most common scripting language (and probably programming language, in general) I see in aocg
>>
File: 2022times.png (37 KB, 644x213)
37 KB
37 KB PNG
>>107440416
I miss the long ones that took hours and then you checked the stats and "barely" anyone completed them
you sortof still can with the temporary stats but it is not the same
>>
>>107440379
You can roughly guess your place from the stats page right after you finish
>>
>>107440506
>the long ones that took hours
Reminder that 2018 day 15 took over 2 hours for the 100th spot to fill
https://adventofcode.com/2018/leaderboard/day/15
>>
>>107440516
I need to get around to completing the ones that I got filtered on in 2023+2024 and follow it up with 2015-2020 because I have not done those at all
>>
>>107440516
everyone likes the goblin game or intcode but this is my favorite
>>
>>107440488
Here it is compared to Go. Amazingly close considering Go is compiled down to machine code.
>>
File: 2025chart.png (20 KB, 672x281)
20 KB
20 KB PNG
>>107440416
>Getting a top 1k time was always a great feeling for me. I got my last top 1k time and I didn't even know...
>>107440493
>Yeah, I'm with you Anon. I'm not the fastest speed coder but it was exciting to be in the top 1000. Without any sort of ranking on the personal times page the fast times I get hardly mean anything.
I mean its probably not the same for you guys... but there's the stats chart for completion. I'm not sure how often its refreshed, but you can basically tell roughly how you placed globally. The funny thing is less than 3000 people finished even yesterdays puzzle... which most of /g/ found pretty easy so you both probably places top 1k overall.
>>
>>107440416
Good times. My main time sink is tripping over myself while trying to type faster than usual. The most genuine moment of AOC pride was figuring out the CRT problem without knowing CRT. I did it on the bus in a notebook.
>>
>>107440528
I liked the clay robots
>>
I always get filtered somewhere around day 15 in past years. Does that mean I have finally have a chance to actually complete em all this year?
>>
>>107440536
>The funny thing is less than 3000 people finished even yesterdays puzzle
Common mistake, Anon.
Less than 3000 people solved Part 1 but didn't solve Part 2.
53550 people solved both parts.
>>
>>107439797
See >>107422238 for a comparison between all 3 solutions. I rewrote the stack sol using simd but it was 16x slower, not the right use case for it.

>>107439676
>>107439688
you are the best

>>107440273
cute, as always. mine is very similar to this, except instead of iterating over the entire grid everytime I use a stack for tracking the indices with value less than '4', and only process their neighbors be decreasing then by 1 and push on stack if equals '3'. got it to 88ms on that bigboy.
>>
>>107440536
>3000 people finished even yesterdays
the grey/silver number is the number of people stuck at just the silver(!) star right?
>>
>>107439600
>Doing AoC with you retards
):<
> is unironically the highlight of my year.
(:
>>
File: flashback.gif (1.97 MB, 328x318)
1.97 MB
1.97 MB GIF
>>107440516
>2018 day 15
completed but at what cost
>>
File: day3gas.png (251 KB, 1312x1359)
251 KB
251 KB PNG
>>107440488
And now we're cooking with GAS.
Specifically GNU gas.
>55ms on bigboy single threaded
>14x faster than Go
>also more legible too
>>107440535
And how does it compare with raw x86?
>>
>>107440572
>And how does it compare with raw x86
14x less autistic for solving christmas parsing puzzles
>>
>>107440590
Sounds like 14x worse then.
>>
File: steve.gif (1.61 MB, 498x384)
1.61 MB
1.61 MB GIF
>>107439600
b-b-based. solving puzzles with buds is the best. I wish I had friends that liked to code IRL. I'm literally the only idiot I know that codes for fun.
>>
>>107439547
That's how prions work
>>
>>107440548
Ohh thank you! My bad! That makes a lot more sense.
>>
>>107439584
>>107439600
>>107439651
>>107439882
>>107439926
I'd consider hosting an IRC or making a mailing list for it but it's 2025; should I acknowledge that time has gone on and try to organize it on twitter or a certain gamer-focused IRC clone?
>>
This is your 1 hour notice. Your 1 hour notice.
Put on the kettle and start the fire. Get comfy.
>>
>>107440749
also go to the bathroom NOW
>>
File: file.png (131 KB, 996x1891)
131 KB
131 KB PNG
day 4, got my loop working for part 2 but idk why my counter isn't working. It keeps saying wrong answer
>>
>>107440847
Here's a hint ;)
>>
>>107440847
Look at the top border in your image. It has rolls that should be removed.
>>
drunk elf girls in 30 minutes
>>
>>107440572
>day3gas.png
52ms on which bigboy anon?

>And how does it compare with raw x86?
how will C++ be different from x86? unless you are writing vector instructions which the compiler cannot infer and write for you

>>107440488
>day3go.png
wtf did I suffer time skip?

>>107440714
not twitter please. it's walled. just create a page for it and host as static web pages.
>>
>>107440552
> 88ms
Nice time!
Adding a stack via recursion cut my code run time with the bigboy in half:
#include<stdio.h>
typedef struct {int a[8];} Dirs;
static Dirs dirs;
static char* v;
static size_t w, count;
static void f1(const int i) {
if (v[i] < '0') return;
int c = 0;
for (int d = 0; d < 8; ++d) c += v[i + dirs.a[d]] >= '0';
if (c < 4) v[i] = '0', ++count;
}
static void f2(const int i) {
if (v[i] < '@') return;
int c = 0;
for (int d = 0; d < 8; ++d) c += v[i + dirs.a[d]] >= '@';
if (c >= 4) return;
v[i] = '0', ++count;
for (int d = 0; d < 8; ++d) f2(i + dirs.a[d]);
}
int main(int argc, char** args) {
if (argc != 2) return puts("Missing filename");
auto in = Map(args[1]);
for (auto it = in.begin; it != in.end; ++it)
if (*it == '\n') { w = it - in.begin + 1; break; }
if (!w) return puts("No end line!");
auto m = w + 1;
auto size = ((in.end - in.begin + 1) / w + 2) * w + 2;
auto p = v = malloc(size);
for (auto end = v + m; p < end; ++p) *p = 0;
for (auto it = in.begin; it < in.end; ++it) *p++ = *it;
for (auto end = v + size; p < end; ++p) *p = 0;

Dirs da = {{w-1, w, w+1, -w-1, -w, -w+1, -1, 1}}; dirs = da;
for (int i = m, z = size - m; i < z; i++) f1(i);
printf("%llu\n", count);
for (int i = m, z = size - m; i < z; i++) f2(i);
printf("%llu\n", count);

free(v);
UnMap(&in);
}
>>
is there a convenient place to find all the bigboys?
>>
>>107440776
try holding it in until the puzzle comes out because the stress of problem solving helps you shit
this is the optimal shitting strategy
>>
File: 1701850751277354.png (1.42 MB, 1024x1024)
1.42 MB
1.42 MB PNG
>>
>>107440931
Actually an issue in my terminal not displaying a few lines above the screenshot
The real issue was a simple debug I did earlier that caused my answer to be off by one
>>
>>107440979
it's easy to make them at home
>>
day 1 part 2 filter: 24%
day 2 part 2 filter: 13%
day 3 part 2 filter: 15%
day 4 part 2 filter: 5%
eric you need to fucking kill them all
how the fuck do we activate him?
`MULLED WINE'
`SANTA SQY'

>>107440979
another anon's repo: https://github.com/Error916/Aoc2025/
>>
File: 1754935744773180.jpg (602 KB, 1024x1024)
602 KB
602 KB JPG
>>107440996
lol good idea
>>
Anyone else have a bad feeling about tonight's puzzle? I think we've been getting off too easy we're about to hit a massive filter.
>>
prepare for the easiest puzzle of the year
>>
>>107441014
My beautiful python code clocks in at TotalMilliseconds : 226.6922
>>
>>107441021
>another anon's repo
>day 1 gold doesn't fit into 53 bytes
sigh
>>
brebare bor the beasiest buzzle bof the blear
>>
File: 1546126167048.jpg (154 KB, 1440x810)
154 KB
154 KB JPG
I still cant get over that time 2-3 years ago with the broken digital clock display
somebody in the thread posted a few hours before the puzzle dropped
>I have been staring at my broken alarm clock in bed
and would you look at it the very next puzzle was the clock display puzzle

this bothers me to this day
>>
>>107441037
day 1 was my bigboy but anon used my code to generate a much larger bigboy
i did make smaller ones that day: >>107391209
https://0x0.st/KJQC.txt
silver: 1337
gold: 74936542733
>>
File: 8hoursago.png (86 KB, 726x403)
86 KB
86 KB PNG
>>107441046
found it
>>
>>107441061
there are no silver stars though
>>
>>107441046
i want to sex with that picture
>>
say what you want about erics inputs but he understands requiring bigint is retarded
>>
>>107441025
About time for the first moderate difficulty day
>>107441062
Oh hey, that was me.
Fixed the clock btw
>>
>>107441062
>>107441046
https://adventofcode.com/2021/day/8
damn
>>
>>107441075
were you a beta taster by any chance
did you freak out when you saw the puzzle
>>
10 MINUTES
>>
File: crossed.jpg (38 KB, 512x411)
38 KB
38 KB JPG
>>107441072
my bigboy; my rules
>>
File: 1740717819890757.png (17 KB, 382x104)
17 KB
17 KB PNG
there's only 24 stars this year
christmas is ruined
>>
>>107441080
Not a tester. Don't remember what I thought, just a funny coincidence I guess
>>
>>107441046
I would unironically feel bad if eric read all the shit we talk about the free event he creates every year that we all enjoy and participate in without contributing to in any way
>>
>>107441072
>not getting that it's a reference to the "silver and gold" song from the Rudolph movie
>>
>>107440970
nice improvement. I think there are some easy gains to be had here.
in f1 while processing for p1, instead of initializing v[i] = '0', initialize it with '0' + count. v can keep track of neighbor count inlined without having to do 8 iterations again.
initialize the padding space with '.' instead of '\0'

the partition point becomes the char '.'. if the value is <= '.' then it's a blank, else it is a paper roll with neighbor count v[i]-'0'.
then in f2 just go through all the neighbors and check if their decrease their neighbor count like v[j]-=1. call f2 on it if v[j]=='3'
>>
we'll have ten years of 12 days and then after the 20th anniversary year we'll get the rebrand from advent of code to week of code (7 days a year)
>>
>>107441092
ocd trannies in shambles
perhaps they will intentionally skip the last two problems so that their star count is neat and tidy
>>
>>107441099
he 100% does. we're "the other people" to his nice friendly reddit simps
>>
>>107441073
she's underage
>>
>>107441104
I meant init v[i] = '0' + c, not count
>>
>>107441099
some anons donate for AoC++ though
>>
>>107441107
You mean Advent of Diwali
>>
File: showtime.jpg (46 KB, 640x480)
46 KB
46 KB JPG
https://www.youtube.com/watch?v=hjGZLnja1o8
>>
>>107441122
cancer music
>>
5 MINUTES
>>
>>107441114
unix time 15 was 7 years ago
>>
>>107441114
Out of 10!
>>
>>107441103
i didn't even realize that was an intentional reference yet i still went "silllllllver and goooold" when solving day 1
>>
>>107441114
>draws a hag
>calls it underage
your opinion has no bearing on my penis
>>
I NEED TO SHIT
>>
File: mokou-showtime.jpg (130 KB, 440x518)
130 KB
130 KB JPG
>>
where is the wall poster
>>
>>107441136
kys time
>>
>>107441139
he hit the wall
>>
>>107441139
he hit the wall..... ironic....
>>
File: radio3.png (92 KB, 556x357)
92 KB
92 KB PNG
IT'S TIME
>>
File: IMG_6605.png (453 KB, 1858x1829)
453 KB
453 KB PNG
>>
>>107441139
Filtered by the wall
>>
>>107440966
It was this bigboy.
>107430441
>>
>>107441146
see >>107441140
>>
I still name my input files demo.txt and part1.txt
as if I am expecting part2 to use different inputs
>>
File: WALL_INCOMING.jpg (157 KB, 462x260)
157 KB
157 KB JPG
>>107441139
TONIGHT'S THE NIGHT
>>
>>107441148
FUCK
>>107430441
>>
File: 1754566911507047.jpg (118 KB, 1000x1000)
118 KB
118 KB JPG
>>
>>107441157
peace has been restored to /aocg/
>>
>>107441037
>>107392963
>>
File: 1754292203104458.png (966 KB, 768x1024)
966 KB
966 KB PNG
the wall spares no one
>>
>>107441104
The fastest way is probably to bit pack the whole thing and count neighbors by using bitwise vector operations to make a saturating adder where each of the 3 bits of the sum and the carry bit have their own register
>>
Today I WILL get a good time.
>>
>>107441162
>one letter off from /aicg/
coincidence?
>>
>>107441167
off by 1 error:
>>
incoming easy puzzle
>>
FUCK
>>
FUCK
>>
>>107441148
pretty good then. kind of hard to believe simple brute while true solution is this fast. was it a direct port of your go one?
>>
FUCK
>>
FUCK
>>
the great filter
>>
IS THIS NIGGER SERIOUS THIS IS THE EASIEST SHIT EVER
>>
>As the forklifts break through the wall
eerie
>>
>>107441114
uoh
>>
>>107441122
came here for this
>>
>part 2
uh oh
>>
brootbros are we boned?
>>
>>107441239
nah bro just let it run
>>
File: 5.png (177 KB, 1626x1064)
177 KB
177 KB PNG
unidiomatic Rust solution
>>
eric has actually lost his touch
day 12 will be day 3 difficulty
>>
>>107441239
it's just merging ranges lol
>>
>example works
>real input doesn't
and so it begins...
>>
>>107441266
make sure you're not accidentally shrinking the ranges
>>
Part 1
data = open("Day 05 input.txt", "r").read().strip().split("\n\n")

ranges = []
for line in data[0].split("\n"):
ranges.append(map(int, line.split("-")))

fresh = 0
for i in data[1].split("\n"):
for r in ranges:
if r[0] <= int(i) <= r[1]:
fresh += 1
break

print fresh

Part 2
data = open("Day 05 input.txt", "r").read().strip().split("\n\n")

ranges = []
for line in data[0].split("\n"):
start, end = map(int, line.split("-"))
ranges.append([start, True])
ranges.append([end+1, False])

ranges.sort(key=lambda x:x[0])

total = 0
stack = 0
last = ranges[0][0]
for i in ranges:
if stack:
total += i[0]-last
if i[1]: stack += 1
else:
stack -= 1
last = i[0]

print total

The inclusive ranges threw me off (edge check didn't work) but I just fixed it my making them exclusive instead
>>
part 2
ranges_2.sort(key=lambda p: p[0])

ranges_3 = []
cur_low = ranges_2[0][0]
cur_high = ranges_2[0][1]

for i in range(1,len(ranges_2)):
this_low = ranges_2[i][0]
this_high = ranges_2[i][1]

if this_low <= cur_high:
cur_high = max(this_high,cur_high)
else:
ranges_3.append((cur_low,cur_high))
cur_low = this_low
cur_high = this_high
ranges_3.append((cur_low,cur_high))

total = 0
for low,high in ranges_3:
total += (high - low) + 1

print(total)
>>
File: code.png (307 KB, 1618x1470)
307 KB
307 KB PNG
Day   -Part 1-   -Part 2-
5 00:03:40 00:15:15

finally a not-braindead puzzle
still pretty easy but had to think a little for part 2
>>
>advent of leetcode mediums
>>
>p2 works on sample doesn't work on input
>>
>>107441258
why do you wear the beanie
>>
File: carbon.png (147 KB, 992x1382)
147 KB
147 KB PNG
Day   -Part 1-   -Part 2-
5 00:03:08 00:17:48
>>
File: 1705797540162893.jpg (171 KB, 975x750)
171 KB
171 KB JPG
tfw just imported solution from aoc 2023 day 15
>>
File: carbon.png (116 KB, 834x791)
116 KB
116 KB PNG
Day   -Part 1-   -Part 2-
5 00:12:11 00:14:34

>spend forever parsing
>realize I literally wrote a solution to import and committed it to my aoc library 1 week ago to the day
weird

def merge_ranges(ranges):
"""merges list of overlapping or adjacent ranges
ranges are inclusive tuples, e.g. [(1,3),(4,6),(8,10)] -> [(1,6),(8,10)]"""
ranges = sorted(ranges, key=lambda x: x[0])
merged = []
a_start, a_end = ranges[0]
for b_start, b_end in ranges[1:]:
if b_start <= a_end + 1:
a_end = max(a_end, b_end)
else:
merged.append((a_start, a_end))
a_start, a_end = b_start, b_end
merged.append((a_start, a_end))
return merged
>>
>>107441258
dedup_by looks cool desu

only change I can see is use binary search on the merged ranges for part 1
>>
Washed Python + bigboy ready
P1 is coordinate compression + prefix sum on difference array (aka sweep line).
P2 is basic merge intervals.
>>
File: 2025_day5.png (55 KB, 1659x509)
55 KB
55 KB PNG
It gets hard tomorrow, right? Trust the plan.
>>107441318
Recalling a previous problem (out of many) and importing that solution is actually impressive.
>>
So is the broot solution ever going to finish?
>>
>>107441329
it was actually 2022 day 15, but I left a comment in my utils library about it so not that impressive
>>
>>107441333
soon, don't worry about it
>>
What the actual fuck
Why did he remove half the days if this is what he ends up delivering
A jeet can do a better job using an LLM to rephrase leetcode easy questions into holiday theme
>>
>>107441333
my answer has 49 bits
>>
>>107405109
apologize
>>
>>107441338
Exactly what he did. Eric thinks AOC should be 12, the guy is sick.
>>
>>107441333
what would the broot solution even be? maintain a set of every id and just keep trying to add to the set for every range?
>>
>>107441318
>aoc 2023 day 15
huh?
>>
>>107441325
cool p1 anon. binary search on merged intervals is a no brainer. you can also improve the constant factor by doing coord compression after merging to remove unnecessary points.
>>
>>107441353
Why? Would that be dumb or something?
>>
>>107441338
heres what actually happened
>eric starts making puzzles
>starts with all the easy ones
>gets halfway
>decides he cant be bothered anymore because reddit goys will pay him anyway
>ships the first half by itself
>>
>>107441361
Nice idea
>>
>off by one
I'm retarded fuck me
Day   -Part 1-   -Part 2-
5 00:03:45 00:31:21
>>
File: xarbon.png (9 KB, 452x484)
9 KB
9 KB PNG
extremely shit times today
I see a few anons were retarded enough to implement range merging? kek

Day   -Part 1-   -Part 2-
5 00:03:03 00:29:44
4 00:09:55 00:15:41
3 00:01:55 00:15:28
2 00:03:27 00:07:29
1 00:02:36 00:11:01
>>
>>107441363
yes, because the final no. of points has like 15 digits
>>
>>107441356
mistyped it, the puzzle was 2022-15 but I ported the code from a different language for another interval problem in 2023 so I got confused
>>
File: 1746548861920191.png (132 KB, 601x508)
132 KB
132 KB PNG
>>107441371
>I see a few anons were retarded enough to implement range merging
>>
>>107441338
Problem: Santa’s Gift Delivery with Dummy Reindeer

Santa is delivering gifts across a snowy village represented by a 20×20 grid. Each cell can be:

0 Empty snowy ground (Santa can walk here)

1 A house (Santa must deliver a gift here)

-1 An obstacle (Santa cannot pass through this cell)

2 A reindeer stable (Santa can rest here to refill energy)

Santa starts at the top-left corner (0,0) with E units of energy. Moving to an adjacent cell (up, down, left, right) costs 1 unit of energy.

Rules:

Santa must deliver gifts to all houses (1).

If Santa’s energy reaches 0, he cannot move further.

Entering a stable (2) refills Santa’s energy back to E.

Some stables are dummy reindeer—they exist but are not needed for the optimal solution.

Santa must minimize the total number of steps taken to deliver all gifts.
>>
>>107441371
I also did sweep line and half open ranges :)
>>
>>107441338
>>107441379
grid = [
[0, 1, 0, 0, -1, 0, 2, 0, 1, 0, 0, 0, -1, 0, 1, 0, 2, 0, 0, 1],
[0, -1, 0, 1, 0, 0, 0, 2, -1, 0, 1, 0, 0, 0, 0, 1, 0, 2, 0, 0],
[1, 0, 0, -1, 0, 2, 0, 0, 0, 1, 0, -1, 0, 0, 2, 0, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 0, -1, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0],
[0, 2, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, -1, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 1],
[0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0],
[1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 1],
[0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0],
[1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0],
[0, 2, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0],
[1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0],
[0, 2, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0],
[1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0],
[0, 2, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0]
]
>>
>>107441379
>>107441384
am I supposed to set any value I want for E or what.
>>
>>107441384
>>107441379
Energy is 7 for this grid
>>
>>107441381
good, faith restored
>>
File: 1755246401200905.png (3.54 MB, 1628x2174)
3.54 MB
3.54 MB PNG
>>
File: 1743986440101189.jpg (71 KB, 500x663)
71 KB
71 KB JPG
>len foldl(inp_fresh, a.union tohashset toseq b, inithashset[int]())
>works on example
>try on real input
>"out of memory"
>>
File: seethe level, maximum.jpg (107 KB, 636x800)
107 KB
107 KB JPG
>>107441371
>gloating with that slow ass time
oh nonono
>>
Still pretty easy but annoying to code (the way I did it at least). Behold my unwash if/elif/else hell:

rngs = sorted(rngs)

final_rngs = []

for r1,r2 in rngs:
if not final_rngs:
final_rngs.append([r1,r2])

new_final_rngs = []
placed = False
for f1,f2 in final_rngs:
if placed:
new_final_rngs.append([f1,f2])
continue
if r1 > f2:
# new range above existing range
new_final_rngs.append([f1,f2])
continue
elif f1 > r2:
# new range below existing range
new_final_rngs.append([r1,r2])
new_final_rngs.append([f1,f2])
placed = True
continue
elif f1 >= r1 and f2 <= r2:
# new range encompasses existing range
new_final_rngs.append([r1,r2])
placed = True
continue
elif r1 >= f1 and r2 <= f2:
# existing range encompasses new range
new_final_rngs.append([f1,f2])
placed = True
continue
else:
# overlap on one end
new_final_rngs.append([min(r1,f1),max(r2,f2)])
placed = True
continue
if not placed:
new_final_rngs.append([r1,r2])
final_rngs = new_final_rngs[:]
>>
File: aoc05.png (179 KB, 1280x1717)
179 KB
179 KB PNG
I was about to say BROOOT
but it is not a true broot
>>
>>107441371
>29 minutes
>>
>>107441408
r8 mine

Day   -Part 1-   -Part 2-
5 00:00:01 00:00:02
4 00:00:01 00:00:02
3 00:00:01 00:00:02
2 00:00:01 00:00:02
1 00:00:01 00:00:02
>>
>>107441371
merge ranging just werks, seethe
>>
I fucking panicked at the basic overlap function and fucked it up for half an hour.


I was doing older aoc puzzles a few weeks ago and literally did the same thing but 10x harder with the 3d overlapping cubes puzzle from 2021. killing myself.


Also, its time to fucking lynch eric for these baby puzzles. WHAT THE FUCK
>>
File: i kneel.png (592 KB, 600x906)
592 KB
592 KB PNG
>>107441421
>>
>>107441421
>taking twice as long to solve day 4 part 2 than it did to do day 4 part 1
NGMI
>>
>>107441379
f(e, house_mask, i, j) = min steps needed to reach cell (i, j) after having visited all the houses in house_mask and having e units of energy left. Dijkstra's on this state space.
>>
>>107441378
>>107441408
>>107441419
>>107441423
It seems that my post generated much seething
I wasn't gloating, I said my performance was very bad
Reading comprehension
>>
Reminder that it's literally halfway over tomorrow lol
>>
O(nlogn) solution
Boring!!!
>>
File: 1724642196405485.jpg (64 KB, 400x400)
64 KB
64 KB JPG
>>107441426
>3d overlapping cubes puzzle from 2021. killing myself.
this gives me anxiety as if I have some repressed memories
>>
File: 1749336842110452.png (238 KB, 874x1937)
238 KB
238 KB PNG
Day   -Part 1-   -Part 2-
5 00:18:18 00:41:08


C
>>
>>107441455
I implemented it by making cubes in blender scripting and I thought i was a fucking genius. Turns out blenders volume calculation wasn't precise enough for the answer to be correct down to the unit and I was so mad I ragequit the puzzle.
>>
>>107441432
times are additive so it would actually be equal time, not twice as long. egg on YOUR face
>>
forgivable puzzle if we had 25 days. Tomorrow will represent the halfway point and we are still getting day 2 problems.
>>
File: file.png (726 KB, 636x788)
726 KB
726 KB PNG
good morning sir
kindly see most needful answer

~ H.B. Gopalakrishnan
>>
>>107441484
he's lost the sauce. next year will down to a single puzzle about seeing how many times "LA" appears in the song deck the halls
>>
File: 1747495353780479.png (42 KB, 472x612)
42 KB
42 KB PNG
Here's my solution. Is this retarded? What's the best way?
>>
>>107441496
does hALls count
>>
>>107441484
Sir we're making the event more inclusive to everyone now
>>
>advent of 64bit integers
>>
>>107441510
there are better ways to kill babbys first brute than this right
like even just making it 2d 2Mx2M elements would work
>>
>>107441501
doesn't matter, just hitting the submit button triggers confetti and gives you 99 gold stars
>>
File: 1757172042351665.png (35 KB, 219x138)
35 KB
35 KB PNG
>MemoryError
>>
File: carbon(150).png (841 KB, 1410x4988)
841 KB
841 KB PNG
Ass came out pretty clean this time, might not have to wash.
>>
File: carbon.png (519 KB, 1784x2792)
519 KB
519 KB PNG
this problem seeming trivial till you hit the brootkiller part 2 made me wistfully reminisce on the night i did the lanternfish problem. now THAT was a real programming puzzle.

washed c++. wish i knew how to do all the epic c++ idioms to make my code look competent but i'm not that cool
>>
Remember 2023's Day 5?
https://adventofcode.com/2023/day/5
This year's Day 5 is like a babified version.
>>
>>107441537
if you want a challenge then try merging the ranges in-place without creating another merged vector
>>
>>107441551
I was trying to remember this one during the problem. Thx
>>
>solve part 2 in a much cleaner way
>answer off by less than 100 somehow
fuuuuuck im going to bed. Yes I tried +1s and -1s in every range lmao.
>>
Is there an O(n) way to do this
>>
>>107441575
try using <= in place of < or vice-versa.
>>
inputs so far
>random letter {L,R} and integers
>random integers
>random integers
>random integers [0,1] on a grid
>random integers
>>
>>107441587
first aoc?
>>
>>107441593
no i want intcode problems
>>
>>107441583
you must compare every n to every other n, there's no way around that
>>
>>107441600
Intcode will never be done again because redditors complained it was too hard.
>>
File: d5.png (282 KB, 1262x2197)
282 KB
282 KB PNG
the max() in coalesce took me the whole hour
>>
>>107441583
no, sorting is required

see this anon's solution >>107441325 for the best p1
>>
File: 1750201030759901.png (569 KB, 934x519)
569 KB
569 KB PNG
Unwashed Nim, embarassing time.

Day   -Part 1-   -Part 2-
5 00:21:30 01:00:02
>>
>>107441586
I think i tried every off-by-one permutation. there is some edge-case im not considering because it works on the test
>>
>>107441575
This is why it took me an hour to solve in the first place, the sample input doesn't help handle nearly as many corner cases as it should.
>>
>>107441583
if you ignore sorting, yes
# O(nlogn) sorting
ranges.sort(key= lambda x: (x[0],-x[1]),reverse=True)
nums.sort(reverse=True)

# O(n)
p1,p2 = 0,0
while ranges:
l,r = ranges.pop()
while ranges and ranges[-1][0] <= r:
r = max(r,ranges.pop()[1])
p2 += r - l + 1
while nums and nums[-1] <= r:
num = nums.pop()
p1 += l <= num
>>
File: 1761514147798190.png (1.6 MB, 908x897)
1.6 MB
1.6 MB PNG
>>
File: carbon(1).png (2.16 MB, 1400x2100)
2.16 MB
2.16 MB PNG
jsfag here, hour late because i was distracted playing Emperor: Rise of the Middle Kingdom
another easy one
sad!!!!
python babies with np literally didnt even have to do anything
>>
>>107441614
>sorting is required
no it isn't
>>107441497
>>
>>107441621
can you try >= instead of >? yours would answer 2 for (1, 2), (3, 3).
>>
>>107441621
nvm fixed it
>>
>>107441575
are you accounting for ranges that completely encompass other ranges? that was my problem
>>
>>107441587
all copyrighted and owned by eric btw
>>
File: d05_031440.png (159 KB, 960x1677)
159 KB
159 KB PNG
The amount of effort I am putting in is proportional to the amount of effort Eric did.
>>
>>107441280
Very nice code.
>>
>>107441657
er*c is copyrighted too, i'll see you in court
>>
>>107441587
>>107441600
I know it's been memed plenty before, but this time it's true. Eric has gone soft. The 12 days of Advent of Code era is marked by being twelve easy-to-medium problems. No more filters, because then less people can play, right? No more math tricks. No more quirk-of-the-inputs. No more assembly interpreters with an impossibly long execution time Part 2.
Advent of Code is over. It's for new programmers only now.
>>
File: file.png (406 KB, 1380x2196)
406 KB
406 KB PNG
zzz
>>
>>107441663
>samefagging
>>
>>107441668
>The 12 days of Advent of Code era is marked by being twelve easy-to-medium problems.
The 11th anniversary is marked by 11 day 1 problems (and 1 day 25 problem).
>>
tomorrows input will be an unwrapped pentahedron that you need to assemble and calculate finite state automata on it's surface
>>
>>107441587
dont forget pandering to stuff like python by basically making a disproportionately large part of the puzzle be users feeling clever about being able to split on commas instead of just having each number on a separate line like today
>>
wasted so much time going for n log(n) on part 1 only for part 2 to be even easier.
>>
File: 1640408089563.png (1.83 MB, 1200x400)
1.83 MB
1.83 MB PNG
>>107441703
anon wtf are you doing to make part1 anything other than O(n)
>>
total1 = 0
for iid in ids:
for ran in ranges:
if iid in ran:
total1 += 1
break

total2 = 0
while ranges:
r = ranges.pop(0)
new_range = None
for ind, s in enumerate(ranges):
if range(max(r.start, s.start), min(r.stop, s.stop)):
new_range = range(min(r.start, s.start), max(r.stop, s.stop))
ranges.pop(ind)
ranges.insert(0, new_range)
if not new_range:
total2 += len(r)

print(total1)
print(total2)


Actually managed sub 10 min for part 1 for once!
>>
>>107441703
lol reatrd
>>
>>107441718
you have to compare every id against every range, thats O(n^2)
>>
File: show_code.gif (22 KB, 348x480)
22 KB
22 KB GIF
>>107441676
>>
File: aoc2025_d5.png (805 KB, 928x544)
805 KB
805 KB PNG
Fun relaxed day. The input was a bit tricky. Here's some ranges that helped me debug if anyone needs a hint on why they're off by 1 too haha.
3-5
5-14
16-20
16-20
17-19
12-18
>>
>>107441280
it is indeed nice, anon. you can use tuple[int, int] for inner ranges instead of a list[int, bool]. store +1 as second element for start and -1 for end+1.
>>
>>107441725
oh right I brainfarted I should go nap
>>
>When you ask how it works, they give you a copy of their database
are these elves brain damaged?
>>
>>107441725
you can sort the ranges, track the max upper bound and then confirm or not with a bsearch.

so O(numRanges * log(numRanges) + O(numIds * log(numIds))
>>
>>107441746
that's not how O notation works
>>
>>107441750
still nlogn tho
>>
>>107441746
You can do better than binary search on the merged intervals. See this anon's solution >>107441325
>>
>>107441668
>No more assembly interpreters with an impossibly long execution time Part 2.
I just did 2017 day 23 last weekend, and hand-decompiling the input program was peak AoC.
>>
>>107441742
Wait until you meet someone running a company on an access database. Santa is definitely running that bitch as a non profit I can tell you that much.
>>
>>107441742
At this point, do you have to ask?
>>
File: 25_D05_C#.png (108 KB, 744x823)
108 KB
108 KB PNG
>code just werks the first time I run it
feels good man
>>
File: 1755813599649105.png (430 KB, 934x389)
430 KB
430 KB PNG
>>107441620
Washed, Idiomatic nim.
>>
File: merch.png (850 KB, 3025x1366)
850 KB
850 KB PNG
HECKIN YIKES!!!! WOOOWZERS GONNA PICK UP SOME MERCH.
>Advent of Code has escaped into the real world as physical objects! (I promise they are at most 5% Perl by mass.)

I cannot wait for the CANGHAF shirts to drop.
>>
>>107441770
You're right. TED.
>>
>wear AoC shirt
>no one knows what it is
>if you end up explaining it it sounds cringe
>>
>>107441788
>not even a hoodie
>>
>>107441765
damn thats fancy
>>
>>107441718
>anon wtf are you doing to make part1 anything other than O(n)
>>107441725
>you have to compare every id against every range, thats O(n^2)
Okay hear me out. You loop through all the ranges once and add each number to a hashset. Then you just loop through all the ID's and checking is only a O(1) operation. You O(2n)'d reduced to O(n) if you have a bazillion rams!
>>
>>107441796
>A competition huh. Do you win a lot of prizes?
>>
>>107441796
What's cringe about saving Christmas anon?
>>
bigboy #5
https://files.catbox.moe/oj8a57.7z (or https://gofile.io/d/xM6vCO if catbox is slow)
1554
450048181074
>>
I dont super like the interval stuff
it feels a bit uninspired and overdone
>>
>>107441788
I scrolled back through the chat at my new job, and the coders competed for an advent of code mug in 2022.
Nobody is doing it this year, and it feels awkward to bring up because I'm not a sw dev professionally.
>>
>>107441426
>>107441653

Advent of Unreadable List Comprehensions.

I wanted to further condense it into a meme one-liner but I have to be at work in a few hours and should probably go to bed.
>>
>>107440535
read on asm.js. it's a technique to exploit v8 jit compiler.
graphical applications written in C/C++ usually only get 2x slowdown when compiled this way. Used to be the way to run C on web before wasm.
>>
>>107441828
this is why I dislike list comprehensions
>>
>>107441813
>.7z
nice virus
>>
>>107441807
>You loop through all the ranges once and add each number to a hashset
I retardedly tried that first, and it isn't a ram issue. I watched it stay in range 0 out of 182 for a couple seconds before Ctrl+C and thinking of a better solution. I guess if you have infinite runtime it could work
>>
>>107441835
yeah I spend a good 10 minutes every puzzle trying to parse the input as a list comprehension before confusing myself and doing it a sane way.

I should know better by now, but the siren song of list comprehensions is too alluring...
>>
>>107441765
Maybe that's faster in practice but it's still the same time complexity
>>
>>107441807
using average time when discussing bigO is disingenuous. The entire point is worst case scenario, an adversarial input can and will happen
>>
>>107441796
A yearly programming challenge.
That explanation sounds cringe?
>>
>>107441319
>merge_ranges(ranges)
from aoc import solution
>>
>>107441828
A few years ago I did the first 5 days in python one-liners. It's an interesting challenge.

>>107441835
They feel awful to nest, and are mostly replacable by map/filter/other functional functions if you need to nest more.
In general nesting being this shit is a good enough deterrent.
>>
>PC crashed trying to broot it
F U Eric
>>
This is clearly a ruse.
>>
>>107441891
Tomorrow is going to be the HARDEST day, I swear bros.
>>
File: carbon.png (180 KB, 2048x628)
180 KB
180 KB PNG
What was the point part 1 ids if they didn't even overlap the inclusive ranges? I forgot about it and still got the right answer.
>>107441828
Did you know you can use the assignment operator inside comprehension? Helps a lot.
>>
>>107441888
I'm actually slowly working through sicp and AoC is a perfect example of problems that can be simplified down to a sequence of map,filter, and accumulate. trying to solve problems with recursive flatmaps frys my brain every time though, for some reason. My implementation is identical but I have to write it iteratively for my brain to like it.
>>
>>107441868
Let the no. of ranges be n and ingredients be m.
In the anon's solution, it would take O((m+n) log(m+n)) preprocessing/sorting, O(m+n) space, and then O(m) to find freshness of all the ingredients.
Binary search on merged intervals will be O(m log(n)) with O(1) space.

So, the simple solution will be better. Coord compression and difference array is always fancier though.
>>
>>107441882
Yes, that was the point of the post. I already wrote the exact function I needed last month for Everybody Codes, decided it might be generally useful, so I saved it, and was able to use it completely unmodified today.
>>
>>107441882
if its your solution its not cheating
if you import someone elses solution its cheating
>>
>>107441921
any person with a brain knows to break; after you found the id in one of the ranges
>>
>he uses his languages std
that's cheating
>>
>>107441647
>python babies with np literally didnt even have to do anything
oh really? whats in np that solves this?
>>107441646
>expired
STILL WOOD
>>
>>107441813
extracted and reuploaded: https://0x0.st/Ktlr.txt
>>
>he uses someone else's language
that's cheating
>>
>>107441954
I meant there wasn't any id at exactly the range's end.
>>
>>107441888
>>107441864
just do common lisp and throw loop macros everywhere. One line at a time then re-evaluate in the repl to make sure you're headed the right way.
And some stuff is wayyy easier to write with loop than with map/filter/reduce. Built in destructuring and parallel iteration really help.

find the indices of all values whose position is different in the sorted version of the list:
(loop for e in seq
and s-e in (sort seq #'<)
and i from 0
unless (eq e s-e)
collect i
end)

vs the functional equivalent:
(mapcan (lambda (vals)
(destructuring-bind (e s-e i) vals
(when (eq e s-e)
(list i))))
(zip seq
(sort seq #'<)
(cdr (reduce (lambda (acc _)
(cons (1+ (car acc))
acc))
seq
:initial-value '(0)))))
>>
>>107441967
>slouch anon is the only non-cheater
grim
>>
>>107441471
lol that actually is genius. I genuinely appreciate that solution. its insane it didn't work though.
>>
>>107441969
you didn't <= end?
>>
>>107441921
oh shit thats crazy
>>
File: 2025-day5.png (310 KB, 1588x1862)
310 KB
310 KB PNG
$ mix aoc.solve -y 2025 -d 5 -p b -r input/real -b 1
828
352681648086146

Ran in 2.433ms


>>107441796
>talking about yesterday's problem with a fellow wagie
>someone asks what we're talking about
>explain that it's a yearly programming exercise with relatively fun problems and few restrictions, which leads to people doing them in a lot of different ways/languages and sharing their solutions, which gives it a nice seasonally-appropriate sense of community and fellowship
>"oh that sounds really neat"
Skill issue.
>>
>he programs on a computer someone else designed with an OS someone else made
that's cheating
>>
>>107441993
>he programs
that's cheating
>>
>>107441993
this is why I print the input onto a piece of paper at my local library, do all the required calculations on sand with a stick, and submit them at an internet cafe
>>
For part 1, it is enough to do an O(n^2) algorithm. Check every id for whether it is contained in at least one range.

For part 2, it's exactly the same as the "merge overlapping intervals" problem in leetcode. We need to sort the ranges in increasing order of their start, then check them one by one. If you detect an overlap, which means that your current range has a beginning that's smaller than the ending of the previous range, then keep a local maximum of the possible end of a merged rate. Peek at your last range and modify it in place to reflect this once you have reached the maximum possible closing of the now-merged range.

package main

import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
"strings"
)

func main() {
res := int64(0)
ranges := make([][]int, 0)
file, _ := os.Open("input.txt")
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
s := scanner.Text()
if len(s) == 0 {
break
}
parts := strings.Split(s, "-")
start, err := strconv.Atoi(parts[0])
if err != nil {
panic(err)
}
end, err := strconv.Atoi(parts[1])
if err != nil {
panic(err)
}
ranges = append(ranges, []int{start, end})
}

sort.Slice(ranges, func(i, j int) bool {
return ranges[i][0] < ranges[j][0]
})

result := make([][]int, 0)

for _, i := range ranges {
if len(result) == 0 || result[len(result)-1][1] < i[0] {
result = append(result, i)
} else {
peek := result[len(result)-1]
peek[1] = max(i[1], peek[1])
}
}

for _, r := range result {
res += int64(r[1] + 1 - r[0])
}
fmt.Println(res)
}
>>
>>107442008
>he uses paper and a stick
NGMI
>>
File: giphy-1223144957.gif (214 KB, 480x480)
214 KB
214 KB GIF
today was easy. but tomorrow were halfway done. I don't want it to end bros. I don't feel so christmas
>>
File: 1764492884073358.png (62 KB, 476x926)
62 KB
62 KB PNG
Partially gave up for part2.
Day   -Part 1-   -Part 2-
5 00:05:06 01:46:43
>>
>>107442008
>he prints the input with someone else's printer
>he prints it on someone else's paper
>he does the calculations with sometree else's stick
>on God's sand
>and to top it all off he goes to internet cafes
that's cheating
>>
why are people using 7zip instead of gzip
>>
>>107442050
I assume wintards don't have gzip.
>>
>>107442050
viruses
>>
>windows
do they really?
>>
>>107442050
rce just dropped and they want to steal your bitcoin
https://blog.qualys.com/product-tech/2025/12/04/active-exploitation-of-7-zip-rce-vulnerability-shows-why-manual-patching-is-no-longer-an-option
>>
my cute lil part2
no deduplication or range clamping, only sort. just solve it during iteration
>>
>>107442099
Patched 7 months ago.
Handling of zip files anyway.
>>
File: unwashed25.05.png (29 KB, 460x1977)
29 KB
29 KB PNG
>>
calling code cute makes you sound like a raging tranny
>>
calling code cute makes you sound cute
>>
calling my cat cute makes her meow
>>
>>107441813
7s with >>107441921 with part 1 done after merging.
5s spent on parsing and sorting.
>>
>>107441765
wait a sec. So this does a sort for all the ids and range boundaries at once. Someone check my math, but If N is number of ids and K is number of ranges, then that's (N + K) * log(N + K) -> log((N + K)^(N + K)) -> log((N + K)^N * (N + K)^K).
and if you do bsearch on the sorted list, that's N*log(N)+K*log(K) -> log(N^N) + log(K^K) -> log(N^N + N^K). Since N < (N + K) and K < (N + K), it seems like bsearching is better...
>>
>>107441889
This is bad. It wasn't Eric. My charging port had a short circuit yesterday and now my laptop keeps crashing. I get "Video memory management internal" error. I think the RAM or motherboard got damaged :(
>>
File: mpv-shot0002.jpg (35 KB, 768x432)
35 KB
35 KB JPG
when does it get hard
why is it easier than previous years when there is half as many puzzles
why isn't it harder and instead we get 2 days per puzzle
>>
>>107442099
Yes saar, I will install very good software DurgaSoft® AutoMagic Patchifier Pro today to protect my PC from hackers and viruses. Thank you saar for the suggestion!
>>
>>107441813
Rewrote part 1 to merge ranges into a smaller list before counting fresh IDs as before. Apparently the 3 million ID ranges merge down into a single range.
>>
>>107442213
There was one year that was unusually easy, then suddenly got brutal. Whatever year had the elephants I think. Completion chart was rough.
Wonder if it's the same story. If the difficulty curve is the same, expecting the next few to be slightly harder, and a wall in ~3-4 days.
>>
>>107442265
I kinda doubt that
>>
>>107442187

>>107441325
p1 = O(n*log(n)) + O(k)
p2 = O(k*log(k))
>>
Opus 4.5 10/10
>>
File: 5c.png (358 KB, 900x1962)
358 KB
358 KB PNG
>>107441813
$ time ./a.out <bigboy.txt
1554
450048181074

real 0m1.659s
user 0m1.571s
sys 0m0.075s
$

bet it'd be faster if I sorted the ranges but this is good enough
>>
File: file.png (3 KB, 145x209)
3 KB
3 KB PNG
>Day 6
>You're trapped in a small room
>There is no escape.
>Christmas is cancelled.
>>
>>107442286
[spoiler][50000024958, 500048206031][/spoiler]
>>
File: solve.png (619 KB, 5708x4102)
619 KB
619 KB PNG
>>107441813
>>107441966
378ms
>>
File: file.png (17 KB, 634x70)
17 KB
17 KB PNG
>>107441670
>>107441813
>>
>>107442366
There is a candle, mirror, rope, and a chair.
How do you escape?
>>
>>107442366
>"Place my xbox into the christmas stocking, Santa."
>>
for big boy should I also time the file load?
>>
>>107442435
of course not
>>
>>107442286
They don't think it be like it is, but it do
>>
>>107442265
>he is right
lol
>>
>>107442435
I usually do but it doesn't matter much until you get to 100ms ranges.
>>
My broot OOMed my machine...
>>
>>107442099
i would trust any random poster in this thread with my life
>>
>>107442439
>>107442506
big boy time
650ms without file
1sec with file

sorting + merging
>>
>>107442553
download my bigboy generator for tomorrow's input, it's an .exe just run it and the .txt file will appear on your desktop, trust me bro
>>
>>107442572
thanks anon, link?
>>
File: file.jpg (185 KB, 1000x1502)
185 KB
185 KB JPG
>>107442416
>>
>>107441668
>No more math tricks. No more quirk-of-the-inputs.
these suck tho
>>
>>107441813
>>107441325

PyPy3 -
pypy3 five.py < bigboy.txt
1554
450048181074
Total Time: 12.867795600000001 seconds


Python3 -
python five.py < bigboy.txt
1554
450048181074
Total Time: 13.0003757999948 seconds
>>
>>107442651
lots of unnecessary copies
>>
>>107441938
We can optimize the binary search approach using two pointers.
>>
This was fun but also a completely inane way to write a program.
>>
File: carbon.png (350 KB, 1610x2694)
350 KB
350 KB PNG
>>107441813
170ms
>>
File: codeimage-snippet_5.png (148 KB, 698x1073)
148 KB
148 KB PNG
idiotmatic python
>>
>>107442729
ya this was my approach, do merge intervals first and sort both intervals and ingredients list to allow for 2ptr and you get
O(nlogn + mlogm + n + m)
where n is len(intervals) and m is len(ingredients)
and the second n/m are single pass

part 2 was < 1 min cuz i already had it done
>>
My code was so dogshi it crashed my PC.
This field really isn't for me.
>>
>>107442832
Genuinely, how is that possible in 2025? What language did you use?
>>
>>107442837
Not that retard, but I was annoyed that part 2 wasn't any more difficult than part 1 so I tried to write a naive python one liner for it to avoid wasting time, and it locked up immediately too. The pseudo logic is basically just
len(set(*range(r.n,r.m+1) for r in input))
. Worked on the example, but I forgot how big the number ranges are in the actual input.
>>
fucking cloudflare
>>
CLOUDFLARE
>>
>example input works
>real input doesn't work
ERIC AAAAAAAAAAAAAAAAAAAAAAAAAAAA
>>
>>107442856
>example input works
>real input shuts down half the internet
>>
File: swift_day5.png (194 KB, 1772x852)
194 KB
194 KB PNG
Another chill and easy day. Looks like we really have to wait for the weekend for something challenging.
>>
C23, O(n) solution.
Big boy https://files.catbox.moe/oj8a57.7z in 310ms.
#include<stdlib.h>
#include<stdio.h>
int f(const void* pa, const void* pb) {
size_t a = *(const size_t*)pa, b = *(const size_t*)pb;
return a < b ? -1 : a != b;
}
int main(int argc, char** args) {
if (argc != 2) return puts("Missing filename");
auto in = Map(args[1]);
size_t* v = malloc((in.end - in.begin) / 2 * sizeof(size_t));
auto p = v; int first_part = 1;
for (auto it = in.begin; it != in.end;) {
if (first_part) {
*p++ = getN(&it, in.end) << 2;
*p++ = (getN(&it, in.end) + 1) << 2 | 2;
if (it != in.end && *it == '\n') first_part = 0;
} else {
*p++ = getN(&it, in.end) << 2 | 1;
}
}
const size_t z = p - v;
// radix sort
#define BITS 9
#define MAX_SIZE (1 << BITS)
#define MASK (MAX_SIZE - 1)
size_t* w = malloc(z * sizeof(size_t));
auto u = v; auto t = w;
for (int bit = 0; bit < 64; bit += BITS) {
size_t a[MAX_SIZE] = {};
for (size_t i = 0; i < z; ++i) ++a[(u[i] >> bit) & MASK];
if (a[0] == z) break;
size_t s = 0;
for (int i = 0; i < MAX_SIZE; ++i) s += a[i], a[i] = s;
for (int i = z; i--;) {
auto const n = u[i];
t[--a[(n >> bit) & MASK]] = n;
}
auto pt = u; u = t; t = pt;
}

const int start = 0, ingredient = 1;
size_t p1 = 0, p2 = 0, low;
for (size_t inside = 0, i = 0; i < z; ++i) {
const int type = u[i] & 3;
if (type == ingredient) { if (inside) ++p1; continue; }
size_t n = u[i] >> 2;
if (inside) p2 += n - low;
type == start ? ++inside : --inside;
low = n;
}

printf("%llu\n%llu", p1, p2);
free(w), free(v), UnMap(&in);
}
>>
I am a new Programmer Did I cause 4chan error? I do not write fast programs and that is OK but did my program use internet computer time for my computer and internets like 4chan had no computer time to use? I run my program and it is very slow. I look at 4chan but I see Error 500. I stop my program and 4chan online again? Sorry for bad English
>>
File: codeimage-snippet_5.png (100 KB, 756x603)
100 KB
100 KB PNG
>>107442806
more idiotmatic python
>>
File: sfohgo.jpg (76 KB, 845x466)
76 KB
76 KB JPG
>Your program cannot possibly run on any existing computer. Creating a dictionary with 4.3 × 1014 keys is infeasible. Python 3.14 cannot allocate 41.6 petabytes of RAM.
>>
>>107443026
>rng
>>
>>107443046
all identifiers must be 1 or 3 characters long
>>
>>107443026
>>
>>107443040
your solution will never be viable. you are not very good with computers. future scientists will dig up your hard drive and laugh.

>>107443057
das rit e
>>
>>107442837
Try to allocated too much memory in Windows and it can happen.
>>
>>107442979
Map, UnMap, getN :
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
typedef struct { HANDLE f_, m_; char* begin, * end; } MemFile;
MemFile Map(const char* s) {
MemFile f = {0, NULL, 0, 0};
do {
f.f_ = CreateFile(s, GENERIC_READ, FILE_SHARE_READ,
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (f.f_ == INVALID_HANDLE_VALUE) break;
LARGE_INTEGER z;
if (!GetFileSizeEx(f.f_, &z)) break;
f.m_ = CreateFileMapping(f.f_, 0, PAGE_READONLY, 0, 0, 0);
if (f.m_ == NULL) break;
f.begin = (char*)MapViewOfFile(f.m_, FILE_MAP_READ, 0, 0, 0);
if (!f.begin) break;
f.end = f.begin + z.QuadPart;
} while (0);
return f;
}
void UnMap(MemFile* f) {
if (f->begin) UnmapViewOfFile(f->begin);
if (f->m_ != NULL) CloseHandle(f->m_);
if (f->f_ != INVALID_HANDLE_VALUE) CloseHandle(f->f_);
}
size_t getN(char** pit, char* end) {
size_t n = 0; auto u = 0u; auto it = *pit;
do {
if (it == end) { u = 0; break; }
} while (u = *it++ - '0', u > 9);
do {
n = n * 10 + u;
if (it == end) break;
} while (u = *it++ - '0', u <= 9);
*pit = it;
return n;
}
>>
>>107443026
n^2 algos can never be considered idiomatic
>>
>>107443135
it is n log n retard
>>
>>107442846
>>107443103
I tried a similar retarded approach on a mac but nothing happened except obviously the program didn't finish.
Weird. I guess you could say it just *didn't* work.
>>
File: day5part1.png (56 KB, 736x544)
56 KB
56 KB PNG
part 1 in clojure
>>
>>107443139
try actually running it friendo
>>
>>107443151
there are no silver stars though
>>
>>107443152
$ time python3 solution.py < input
silver: 638, gold: 352946349407338

real 0m0.011s
user 0m0.011s
sys 0m0.000s

okay, what next?
>>
>>107443164
bigboi
>>
File: 114758.png (94 KB, 1600x900)
94 KB
94 KB PNG
>>
>>107443168
after you tell me why it is n^2, sir
>>
>>107443146
>mac
Your ssd is now gigaraped by swap, congratulations, your overpriced laptop is officially an e-waste.
t. mac user
>>
>>107443026
>using map instead of a list comprehension
Idiotmatic yes, but not idiomatic.
Guido hates functional programming and tried to remove that function entirely.
>>
File: carbon(4).png (672 KB, 1648x2942)
672 KB
672 KB PNG
Brooted part 1 at least.
>>107439676
>>107439688
Great drawings, thanks anon.
>>
>>107443194
nice syntax highlighting
>>
>>107443197
kek
>>
>>107443197
*shrug* shit website.
That said, I like this more than the rainbow it normally puts on there
>>
>>107443206
grinch theme
>>
File: 115349.png (2 KB, 151x166)
2 KB
2 KB PNG
I don't feel good about this bros
>>
>>107443169
This shit actually made me nauseous to try to read due to the blurriness and tiny font.
Then I managed to start reading the code and got nauseous a second time.
Get help friend.
>>
>>107443213
kek
>>
>>107443217
I was trying to get it to fit in the screenshot lol
>>
>>107443214
>to reach the next room, you must climb down a chimney
>you reach the bottom and find yourself in a furnace
>``this must be how they heat the santabunker'' you think to yourself
>find a way to escape along with 20 elephants
>you have 5 minutes
>>
File: Day05_CShart.png (125 KB, 749x1193)
125 KB
125 KB PNG
I had to shart during the implementation
>>
>>107442651
anon, can you compare your coord compression solution with simple binary search over the merged ranges.
binary search method has better time complexity but it's trash on the cache. on the other hand coord compression requires sorting the combined list again.
>>
>>107443250
does it have to be indented like that or is it just style?
>>
Where is the AWK anon?
>>
File: 5.png (160 KB, 935x1294)
160 KB
160 KB PNG
>>107443344
I was waiting for the new thread lol
>>
>>107441813
horrible bigboy. anon should add validators instead of calling rand a bunch of times. all the ranges merge into a single range. so p1 becomes trivial and does not measure anything really. can't compare times for different solution methods for example.
>>
NEW BREAD
>>107430428
>>107430428
>>107430428
>>
>>107443347
Thanks, love your solutions <3
>>
>>107443348
sounds like a great opportunity for making your own
>>
>>107443188
fuck what that irrelevant manlet wants
>>
>>107443354
so funny
NEW THREAD >>107443386
>>
>>107443342
it's rustfmt
>>
>>107443172
your p1 calculation
>>
File: outhouse.png (59 KB, 656x646)
59 KB
59 KB PNG
>>107443214
>>
>>107443367
did >107443706



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