[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: 69cover1.jpg (49 KB, 800x450)
49 KB
49 KB JPG
advent of parsing 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: >>107443386
>>
bigboy #6
https://files.catbox.moe/rqtzac.7z
117485221516
163985089394
>>
hint: it's not "an exercise in whitespace parsing". think columnar.
>>
This one goes out to the Haskell anon from the other day, part 2 in Erlang.

-module(day06).
-compile(export_all).

run() ->
{ok, Data} = file:read_file("day06.txt"),
Lines = string:lexemes(Data, "\n"),
{Numbers, Ops} = get_parts(Lines, []),
process(Numbers, Ops, []).

get_parts([LastLine], NumberAcc) ->
{lists:reverse(NumberAcc), string:reverse(LastLine)};
get_parts([NumberLine|Rest], NumberAcc) ->
get_parts(Rest, [string:reverse(NumberLine)|NumberAcc]).

mul([A]) -> A;
mul([A|Rest]) -> A * mul(Rest).
add([A]) -> A;
add([A|Rest]) -> A + add(Rest).

pop_all_head(Lists) ->
Number = string:trim([ hd(List) || List <- Lists ]),
NewLists = [ tl(List) || List <- Lists ],
{Number, NewLists}.

process(_, [], []) -> 0;
process(NumberLines, [Op|RestOps], Numbers) ->
{Number, NewNumberLines} = pop_all_head(NumberLines),
NewNumbers = case Number of
[] -> Numbers;
_ -> [list_to_integer(Number)|Numbers]
end,
case Op of
$* -> mul(NewNumbers) + process(NewNumberLines, RestOps, []);
$+ -> add(NewNumbers) + process(NewNumberLines, RestOps, []);
_ -> process(NewNumberLines, RestOps, NewNumbers)
end.
>>
File: funnymeme.jpg (100 KB, 800x450)
100 KB
100 KB JPG
>>
>>107455644
Funny
>>
>>107455644
idgi
>>
Unwashed, started late.
Part 1
data = [i.split() for i in open("Day 06 input.txt", "r").read().strip().split("\n")]

total = 0
for step in zip(*data):
if step[-1] == "*":
num = 1
for i in step[:-1]: num *= int(i)
elif step[-1] == "+":
num = 0
for i in step[:-1]: num += int(i)
else:
print "screwup"
total += num

print total

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

total = 0
current = 0
op = None
for step in zip(*data):
num = "".join(step[:-1]).strip()
if step[-1] != " ":
total += current
current = 0
op = step[-1]
if op == "*": current = 1
if len(num):
if op == "+": current += int(num)
else: current *= int(num)
total += current

print total

zip came in clutch
>>
File: rape_me.png (120 KB, 1006x1351)
120 KB
120 KB PNG
couldnt solve it, went and had sex, came back and saw what i was doing wrong and solved it in 5 minutes (in my exit from the loop i was just adding the temp to the total regardless of the operator. the last problem's operator is *)
>>
Definitely tending towards easy this year. By day 12 of previous years there was at least a couple medium difficulty puzzles
>>
>>107455604
i spent 10 minutes fighting with vscode removing trailing whitespaces
>>
>>107455755
So you decided to edit the puzzle input instead of solving the problem correctly?
>>
>>107455770
no, i literally solved the problem correctly, the inputs contained whitespaces
>>
File: 2025-12-06_11-48-51.jpg (51 KB, 412x92)
51 KB
51 KB JPG
>>107455778
Sure it did, buddy.
>>
File: 1753853479295804.webm (473 KB, 500x272)
473 KB
473 KB WEBM
>The left/right alignment of numbers within each problem can be ignored.
I knew I KNEW Eric would pull some fuckery here so I made my part 1 parser prepare for positions too
I almost went with the "replace all double spaces with space and split by space" but I just had a hunch of some fucking bullshit incoming in part 2
Absolutely disgusting
>>
>>107455801
>i knew there was gonna be a part 2, i just knew it!
>>
>>107455733
no idea why the fuck he said right to left
>>
File: 6.png (191 KB, 1080x1240)
191 KB
191 KB PNG
>>107455610
$ time ./a.out <bigboy.txt
117485221516
163985089394

real 0m0.098s
user 0m0.055s
sys 0m0.041s
$
>>
>>107455828
the operator on the last line is always left-aligned so parselets know when they've reached the last column of an equation by working right to left
>>
>>107455828
imagine this
on day 13 the website announces: Part 3 on all problems!
and then in some way it adds division to the puzzle input
>>
>>107455854
oh, that could have made it easier to split the groups
>>
File: file.png (442 KB, 1618x2990)
442 KB
442 KB PNG
day 4 rust
>>
>>107455610
oh no
117485221516
163991266978

is everyone getting the correct ans? is the input formatting correct?
>>
File: AoC-06.png (77 KB, 970x554)
77 KB
77 KB PNG
Eh.
>>
File: day06p1.png (32 KB, 603x523)
32 KB
32 KB PNG
Part 1 done.
Now to just copy that subroutine, rename all the jumps and switch around which registers I am referencing at certain points and that should be part 2.
>>
>>107455884
it crashes my script
>>
File: carbon.png (178 KB, 1964x582)
178 KB
178 KB PNG
>>107455884
>>107455610
It's wrong, has double spaces between columns and also whitespace between digits inside a column.
117485221516
163996061678

Takes 10s for my list comprehension python if I ignore those.
>>
>>107455693
Spend more time here.
>>
Boring puzzle.
I don't even feel like doing part 2, even though ut would probably just be 5 lines of code.
>>
File: Day06_CShart.png (137 KB, 856x1263)
137 KB
137 KB PNG
Where my C# at?

Task 1: 4648618073226
Task 2: 7329921182115
Day 06 finished in 00:00:00.0345513
>>
>>107455604

https://markdownpastebin.com/?id=387dd4460e18492a90c25653f9c3a262

/aocg/2024#48=103661747 #-1=107371611 #0=107379367
d1=107379367/107389983 #1=107391909 #2=107400869
d2=107400869/107402978 #3=107407288 #4=107413670
d3=107413670/107415107 #5=107417323 #6=107424958
d4=107424958/107428346 #7=107430428 #8=107439547
d5=107439547/107441181 #9=107443386
d6=107443386/107453478 #10=107455604
>>
tried to be smart about it but I guess I'll solve part 2 the way eric wants me to :/
>>
>>107455898
>double spaces between columns
not wrong
>whitespace between digits inside a column
huh
where
>>
>>107455610
How hard can it be to acutally keep the same formatting and follow the rules of the puzzle?
>>
>>107455985
>not wrong
>Problems are separated by a full column of only spaces
>A, as in one. Not two, one.
>>
>>107455898
Get the same answer as you
>>
File: aoc_day6.png (152 KB, 587x1479)
152 KB
152 KB PNG
I love iterators
>>
>>107456010
they are still separated by a full column of only spaces
can fix it when I'm back home if more people complains though
>>
File: carbon(6).png (135 KB, 1498x982)
135 KB
135 KB PNG
> Wake up
> Browse the problem while pooping
> Go to sleep for 2h
> When I wake up my brain has solved the problem for me

r8 my solution
>>
>>107456059
Shit I realize now I can flip the arguments and directly feed the fold to zipWith to golf it further. Anyway still happy.
>>
File: 6.png (1.22 MB, 5708x4232)
1.22 MB
1.22 MB PNG
idiomatic Rust solution
>>
File: file.png (43 KB, 566x329)
43 KB
43 KB PNG
>>107455985
Took me a bit to parse my output, there's plenty, for instance column 53 (0-indexed):
59
100
88
487
318

has a "0 78" column.
>>
File: day06emu.webm (366 KB, 628x808)
366 KB
366 KB WEBM
A few gremlins I had to deal with (including my own stupidity in places).
>>
>>107456134
how did I miss that lmao
>>
File: day06.png (1.12 MB, 2207x2692)
1.12 MB
1.12 MB PNG
>>107456142
I actually made use of some of the parallel instructions in the EE today, which was fun.
Essentially seeing I was walking the input horizontally and then stepping down a line, I could reverse that for part 2. But then I found that there were some 2 column sets in part 2 that threw me off, and apparently not clearing out my numlist became a problem in part 2 (in part 1 there were always 4 numbers, or 3 in the example, in the list).
>>
File: aoc2025-06.png (118 KB, 475x1018)
118 KB
118 KB PNG
>>
File: 20251206_205114586.webm (1.27 MB, 853x480)
1.27 MB
1.27 MB WEBM
>>107456244
As for how fast it is... It completes before vsync, so less than 16ms at least.
>>
File: semiwashed25.06.png (52 KB, 514x3173)
52 KB
52 KB PNG
>>
fucking animals can't read like normal people do
>>
>>107456134
>>107456010
>>107455898
>>107455893
>>107455884
amended bigboy #6
https://files.catbox.moe/y6nuey.7z
117309571763
163990321309
>>
File: fanspeed100.png (26 KB, 1500x118)
26 KB
26 KB PNG
>>107455610
I regret nothing, see you in 18 hours
>>
>>107456270
looooooooooooooooool
>>
>>107456032
If problems are separated by a full column of spaces, then having two columns in a row implies that there is a completely empty problem between the two columns, which is ill-defined.
>>
>>107455610
>>107455884
>>107455898
>>107456017
Why am I getting
117485221516
163996125249
My gold is 63571 larger than yours. Suggests you are all missing something. Where would I get this 63571 from?
>>
>>107456284
>.7z
nice virus. extracted and reuploaded: https://0x0.st/KvNu.txt

41ms with >>107456121
>>
>>107456315
>.txt
nice virus
>>
>>107456284
Works for me now
117309571763
163990321309
./06.py 8.32s user 0.29s system 99% cpu 8.685 total

>>107456306
Try the new one.
>>
>>107456315
>nice virus
>>
>>107456326
>Try the new one.
I'm getting
117309571763
163990321309
(same answer) on the new one. Still kinda interested in the old one and whether I'm correct or you guys are, since I'm the odd one out here :)
>>
>>107456339
the old one had broken columns like this one >>107456134
>>
>>107456339
you are neither wrong nor right; however, you are retarded.
>>
>>107456339
Well, the old one had empty spaces inside numbers and I just ignored those, so my answer would be lower.
>>
>>107456287
lmao
>>
>>107456347
yes, and I'm pretty sure my solution is correct for that. Considers that
51843+90881+78
Just find it interesting that my solution was ready for these "changed requirements" without changes and you Pythoids were not

>>107456349
Yes, I know that, but thanks for the input
>>
>>107456387
my solution let me know input's malformed. It's production ready
>>
>>107456391
You are getting calls from your client who's trying to input the malformed format while I'm enjoying my vacation knowing I'm ready for all kinds of inputs
>>
>>107456387
if the requirements changed then its not the same puzzle
>>
>>107456284
total:163990321309

[Done] exited with code=0 in 2.2 seconds
>>
>>107456423
>>107455741 (this)
>>
>>107456421
Tell that to your boss, NEET
>>
>Reading the problems right-to-left one column at a time
nice try, eric
>>
>>107456542
Oh shit.
I solved it by reading from left to right. Damn, I guess I failed really.
>>
File: day6.png (460 KB, 1818x1722)
460 KB
460 KB PNG
>>107455898
I was getting mad on broken bigboy. Thank you for restoring my sanity. I got the same results.

Also many thanks to kind anon that told me Data.Text library yesterday. This is my fastest bigboy and given that I am using a pre M1 macbook air it this feels super fast.

And this is for the amended bigboy
________________________________________________________
Executed in 3.11 secs fish external
usr time 2.15 secs 0.45 millis 2.14 secs
sys time 0.10 secs 1.43 millis 0.10 secs
>>
File: saddam.png (58 KB, 1013x500)
58 KB
58 KB PNG
what - or who - could be hiding out there?
>>
File: file.png (271 KB, 2560x1047)
271 KB
271 KB PNG
>>107455610
Too big, too shit with my solution. I need to stop coping with vectors and heap allocations.
>>
>>107456678
>fn silver
there are no silver stars though
>>
File: file.png (996 KB, 753x946)
996 KB
996 KB PNG
good morning sir

kindly see the needful

~ H.B. Gopalakrishnan
>>
what a shit fucking puzzle, bravo eric
>>
>>107456680
this was debunked
>>
>>107456753
NO ITS COOL
>>
File: two gold stars.png (295 KB, 6336x136)
295 KB
295 KB PNG
>>107456760
>>
Part 2 in 9 lines of pure Python. I couldn't figure out how to get rid of iter+next, that could have saved one more line.
*data, ops = open("input.txt").read().splitlines()
it = iter(ops.split())
ans, subtotal, op = 0, {"+": 0, "*": 1}, next(it)
f = lambda x, op, y: x + y if op == "+" else x * y
for number in map(lambda digits: "".join(digits).strip(), zip(*data)):
match number:
case "": ans, subtotal, op = ans + subtotal[op], {"+": 0, "*": 1}, next(it)
case _: subtotal[op] = f(subtotal[op], op, int(number))
print(ans + subtotal[op])
>>
I should start renaming my part 1 and 2 to silver and gold so my code gets (You)'s
>>
>>107456778
>rajesh learns about ctrl+shift+j
>>
>>107456794
call them Ag and Au girls dig that shit
>>
>>107456614
nice font. what language is this? swift? f#?
>>
>>107456778
You earn gold stars.
You are ranked with silver and gold stars.
We have been over this.
>>
File: _3.jpg (722 KB, 1778x2000)
722 KB
722 KB JPG
>>107456814
Doing that from now on, I'm a huge sucker for pushing latin stuff wherever possible
>>
>>107456827
Thanks anon. Font is Right Serif Mono
Here is official link but I just pirated it.
https://pangrampangram.com/products/right-serif-mono

And the language is Haskell. I am trying to learn it.
>>
>>107456862
>agrees with me
>still insists he is right/I'm wrong
cognitive dissonance
>>
>>107456284
you are the real big boy, anon <3
877ms

>>107456297
wow, didn't think about that. I was iterating from right to left so that might be the reason why my wrong answer was different from everyone else's wrong answer

>>107456315
>42ms
wtf how so fast, idiomatic rust anon. am I just hitting into zig issues now, or just a skill issue?

>>107456783
what counts as pure python?

missing c23 anon's cute solution
>>
>>107456886
>brain damage
I'm sorry for you. This is supposed to be a happy time of year.
>>
File: file.png (382 KB, 1680x2496)
382 KB
382 KB PNG
day 5 rust
>>
>>107456680
I will forever call it part 1 silver. Part 1 as text is ugly, and it's so close to part 2.
Silver? Silver is a metal. It's bold, it shines and kills vampires. And it is sufficiently differentiated from gold on both a textual and color level. Even if Eric went to my flat and said it's part 1, I will still use silver because silver/gold is, to put it in hip nomenclature, kino.
>>
File: file.png (218 KB, 1680x1432)
218 KB
218 KB PNG
>>107457069
realized I can skip the sorting by just inserting in the right place
>>
>>107457016
>what counts as pure python?
I meant without third party libraries. Sometimes you can get shorter solutions with numpy, but that may be considered cheating to some.
>>
File: code.png (294 KB, 1508x1948)
294 KB
294 KB PNG
Python
>>
This took me 3 hours, am I retarded??

>>107456059
is great, simpler than mine
>>
File: aoc_day6.png (114 KB, 558x1017)
114 KB
114 KB PNG
reused part 2 for part 1
>>
>>107457016
zig is definitely at fault too here. same thing recompiling gives vastly different times. can be varying system load also
>>
File: day06p1.png (34 KB, 602x525)
34 KB
34 KB PNG
I improved the colors.
>>
File: carbon (2).png (311 KB, 2020x1326)
311 KB
311 KB PNG
>>
I’m doing in Rust this year instead of Haskell; there is so much stuff in my code that is not related to the problem I am solving (iterators munging, deref, cloning...). I should have tried ocaml or something.
Haskell really is the king of concise and readable programs.
>>
go brrrrrr
>>
>>107457450
>go brrrrrr
fuck, I wanted to type the unicode transpose symbol but 4chan stripped it
>>
will tomorrows puzzle be good?
>>
>>107457301
took you three years
>>
>>107457016
>how so fast
trannies omit I/O when timing
>>
>>107457449
skill issue
>>
File: carbon.png (367 KB, 1576x1824)
367 KB
367 KB PNG
Haskell newbie here. Having fun so far
>>
>>107457516
Every Rust solution in this thread has the same issue tbqh thobeit
>>
File: 6.png (1.09 MB, 5654x3582)
1.09 MB
1.09 MB PNG
>>107457449
iterators munging is a good thing, deref happens automatically, cloning stuff usually is a sign of skill issue
>>
>>107457016
brought it down to 162ms with I/O from stdin and 141ms with @embedFile. am I doing good anons?
>>
>>107457490
Famicon was kinda limited in which colors I could choose from anyway.
>>
>>107457582
show code. >>107455843 this is 60ms sans I/O with both big inputs
>>
>>107457487
No. We are getting no good puzzles this year.
>>
I'm glad the input was properly padded. P2 would have been that much more annoying.
>>
>>107457530
What are you talking about? The code looks the same in rust as anything else. You're literally just parsing digits in a string and translating the input on its side. tf
>>
File: Day-6.png (1.43 MB, 2676x6460)
1.43 MB
1.43 MB PNG
>>107457610
can you time yours on the new bigboy?
>>
>>107455604
Wow this one was difficult. But still solved it in 90 minutes.

So like what was actually the right alogorithm? Right now my solution is:
>split into lines
>iterate over the array lengthwise, splitting it into chunks of stringbuilders.
>since I don't know how to rotate arrays, iterate on this from top to bottom, store the numbers and operator in a list of classes.
>loop over all of those classes to calculate the end result
Ugly ass inelegant solution, 100 lines and far too many arrays and nested for loops.
>>
>>107457690
>90 minutes
filtered
>>
File: carbon(5).png (787 KB, 1586x3648)
787 KB
787 KB PNG
I did not appreciate today.
>>107456315
337ms
>>
Anyone leading the charge on the day 13 puzzle yet. We have 6 days
>but its hard to make puzzles
Have you seen the puzzles this year? We can shit out 12 Eric Quality (tm) puzzles by then, easily.
>>
>>107457672
I have. No difference
>>
>>107457743
an anon posted this >>107441379 but imo it's soulless without a nice grid format. . for snow, A for home, 0 for block, etc. easy enough for a day 13

>>107457755
yeah missed that you mentioned it already. my old code had column major iteration for p2 so I changed all to row major for locality. still got beaten tho :<
>>
>sample ok
>input: too low
>using bigint too
that was a quick filter
>>107453553
same, time to cheat and see what tripped up the others
>>
>>107457743
sure
input is a 2D grid
you start at S at the top left
you end at E at the bottom right
dot (.) tiles are empty, you can move there
hash (#) tiles are obstacles, you cannot move there
here's an example maze
S#...
...#.
####.
.....
....E

which takes ten steps
how many tiles do you need to move to get from the start to the end?

part 2: now tile the input 100000x100000 and get steps
(the secret quirk of the input that makes this possible is that the input does not have any # tiles in it actually)
>>
bigboy in my Golang solution without IO runs in 1.2 second. Very slow compared to other solutions. i guess i could spawn go routines to compensate for my slow algorithm, will try later
>>
>>107457816
that was yesterdays puzzle

maybe try stealing some medium/hard leetcode and reword it like eric does
>>
feeeewwwww, advent of parsing
didn't like it either
took me 50min
>>
anyone remember https://adventofcode.com/2022/day/17 ? man I have some fond memories from aoc 2022. that was a good year. kind of wild I got through that with seer perseverance, without much algorithm knowhow
>>
>>107457743
i should have mine ready by then unless someone else wants day 13 and i can do day 14?
>>
>>107457816
i like grid problems but this is bfs 101 bro
>>
File: d06.png (204 KB, 821x1552)
204 KB
204 KB PNG
idiotic Rust solution
>>
>>107457907
more like idiomatic rust solution lmaooo
>>
>>107457913
idiomatic rust anon in shambles kek
>>
>>107457809
I'm rarted, did grid.indices instead of grid.head.indices and the sample was well prepared to have equal dimensions
d6p1
val grid = scala.io.Source.stdin.getLines.toSeq
.map {_ split ' ' map {_.trim} filter {_.nonEmpty}}

def procCol(i: Int) =
val xs = grid.init map {row => BigInt(row(i))}
grid.last(i) match
case "+" => xs.sum
case "*" => xs.product

println(grid.head.indices.map(procCol).sum)
>>
>>107457204
well i certainly feel silly
>>
>>107457978
>uncurry
haskell confirmed indian programming language
>>
>>107457859
Was 2022 the one with elephant valves as well? I think thats the hardest puzzle I have completed.
>>
>>107457978
Do you not know about string literal patterns, or do you just really like the robotic monkey head operator?
>>
>>
File: 1357414719373.jpg (43 KB, 700x500)
43 KB
43 KB JPG
what the fuck are these soulless leetcode puzzles this year?
why is the lore so vapid and hollow?
2020 was shit but I gave a pass for covid
Later years have been pretty lame but there are still some standout puzzles that harken back to the puzzles of yore
This year with the announcement of only 12 i assumed we’d be dealing with some really fun types of challenges
Instead we got leetcode
Fuck you eric
>t. aoc veteran from the legendary 2018 campaign and all-year-solver
>>
>>107457859
Ugh. One of those problems where I instinctively cringe remembering it. I spent hours figuring out the looping math.
>>
>>107458071
no im just retarded
>>
Anyone else also using eval?
It makes my solution work with other operators too.
>>
>>107458056
Yeah
Only 8 people in the world solved it within 30 minutes. Many elephants died that day.
>>
>>107458189
no i'm not a brownoid
>>
>>107458189
hey what do you get for part 1 on this input?
13 74929104856183 6
53 93716859327 65
3 93462648 42
+ sudo rm -rf /* *
>>
File: 1755395873795435.jpg (513 KB, 1024x1024)
513 KB
513 KB JPG
>>107458141
>>
>>107458210
my screen has gone black, can't see the result
>>
>>107458189
Hadn't considered it. I suppose it could make it more compact but in general hell no.
>>
>>107458210
Not sure, my computer is being weird now
>>
>>107457743
How hard should it be?

After saving christmas, it's time for santa to deliver the packages.
The elves have already made a schematic for how to arrange the presents in a pile (your puzzle input) in the trunk of santa's sleigh.
However, some presents are fragile!
Santa wants to make sure these will not break, before he loads the packages in his trunk.

An example schematic the elves have drawn is shown below:

......[===]...
.[=].[==].[f].
[==][==]..[==]
[====].[====].
[f][=][f]..[=]

Here `.` indicates empty space, and `[===]` denotes a present.
A present like `[f]` or `[ff]` is *fragile*.
All presents have a depth and height of 1, and variable width.
Presents cannot rotate, cannot slide, and remain exactly where drawn during santa's flight.

The mass of a present is the number of spaces it occupies, i.e. it's width.
For example, `[x]` has 3 units of mass, and `[xxxx]` has 6 units.
Gravitational acceleration on the north pole is 10 m/s^2, so each package weighs 10 times its mass.
Thus, a present of width w weighs 10w Newton.

You are tasked with calculating the total weight on the fragile presents.

(cont'd)
>>
>>107457743
I'm working on a puzzle. This is how far I've gotten.

Part 1:
"The elves are notifying you that the roof is leaking. In order to stop water from reaching Santa's naughty dungeon they have gathered a huge amount of buckets (your puzzle input) of varying sizes in liters. For example:
5 L bucket
3 L bucket
3 L bucket
4 L bucket

In order to protect Santa's naughty dungeon the elves need to understand how many buckets they have. In the example below they have 4 buckets.
How many buckets do the elves have?"

Part 2:
"After fixing the roof the elves decide to celebrate with an eggnog party. They decide to serve the eggnog in said buckets, but need to use one to mix eggnog in. In the example above they now have three buckets avaiable to make eggnog in.
How many buckets of eggnog will the elves be able to serve?"

What do you think? Too hard? I think it is a noticable step up in difficulty from the quality of this year's puzzle, which is what you want from Day 13. But it feels like the curve may be a bit to steep.
>>
>>107457968
d6p2 was comfy too
val lines = scala.io.Source.stdin.getLines.toSeq
.transpose.reverse
.map {_.mkString filter {_!=' '}}
.filter {_.nonEmpty}

var res = BigInt(0)
val grp = scala.collection.mutable.ArrayBuffer.empty[BigInt]

lines foreach {
case s"$x+" => grp += BigInt(x); res += grp.sum ; grp.clear
case s"$x*" => grp += BigInt(x); res += grp.product; grp.clear
case s"$x" => grp += BigInt(x) }

println(res)
>>
File: out.png (590 KB, 5776x4115)
590 KB
590 KB PNG
>>
>>107458274
A present on a row may be supported by the presents on the row below it.
In particular, the elves use the following model: a present can be supported at those grid cells immediately below its occupied positions.
Each cell with a present below it is a contact point.
The vertical normal force at each such contact point must be nonnegative.

For example, in the following configuration:
[==]
[ff]

There are four contact points between the top and fragile presents.

Every present must satisfy *vertical force balance*: the sum of all contact forces from below must equal the weight of the present.
Note that a present may overlap with several presents below it, but physically, only a subset of contacts will carry load.
To determine which, the elves use the following rule:
*among all force assignments that satisfy *vertical force balance*, the physically faithful assignment is the one that minimizes the sum of squares of all contact forces.

For example, in the schematic
[==]
[ff]

the weight of the top present is 40.
Each contact point will carry 10N of force, and the total weight on the fragile present is thus 40.

(todo: some more examples, probably)

The *total weight* on a fragile present is the sum of all contact forces it receives from the presents above it.
What is the sum of the total weights on every fragile present?
>>
>>107458286
>out.jpg
Nice :D
>>
>>107458303
?
>>
>>107458286
Why `expect` at the end instead of another `ok_or` or whatever? Input data unexpected vs internal consistency?
>>
>>107458370
Because at that point it shouldn't fail. I could've used unwrap instead but I like expect more.
>>
>>107458274
>>107458293
sounds good and interesting, but definitely advent of reading comprehension. idiomatic aoc would probably make up units instead of using real physics terms

>>107458275
too hard, how am I supposed to parse that input?
>>
>>107458210
I'm not a nigger. The evaled code has an environment without access to IO. Worst it can do is cause an infinite loop.
>>
>>107458189
yep, eval and join
>>
The elves has been given some instructions for the candy-cane machine, the instructions are snowflake (brainfuck) programs. They need to know which of the instructions will finish running and return a result and which will not. What is the sum of all the instructions which finish running
>>
File: aoctex.png (156 KB, 1280x2329)
156 KB
156 KB PNG
I just spent 6 hours trying to parse it with tex macros
it is not working

\getline returns the expected character but when I try to ifx it with + or * to check which operation I should use I get no match

this is so aids
>>
>>107458275
this is day 1, day 2 at most, not day 13 lol
>>
>>107458541
>a program is nice if it terminates and naughty otherwise
>find a way to determine if a given program is naughty or nice
>>
you don't have to parse verticaly, you can just store the left / right alignment of a column on intake and then pop the digits off the right to extract each vertical number.

e.g.
123
4

accumulator *= 10
accumulator += 123 % 10
result: 3

12
4

accumulator *= 10
accumulator += 12 % 10
result 2

1
4

accumulator *= 10
accumulator += 1 % 10
accumulator *= 10
accumulator += 4 % 10
result 14

---------------------

123
4

accumulator *= 10
accumulator += 123 % 10
accumulator *= 10
accumulator += 4 % 10
result: 34

12

accumulator *= 10
accumulator += 12 % 10
result 2

1

accumulator *= 10
accumulator += 1 % 10
result 1


steal your count digits function from day 2 and that with the alignment tells you if you what numbers are currently 'in range' of the column
>>
>>107458541
The elves have been given a list of sprinkles codes but they have lost the labels! Compute a valid label that matches the spinkles code (sha-3) so the kids can get the right presents this year
>>
>>107458558
kek godspeed anon
>>
this was the easiest day so far
>>
>>107457755
anon I got it to 60ms too. extra int parsing step was not worth it. I keep having a bad intuition about caching
>>
>>107458688
perf stat/record might be helpful
>>
>>107455610
this is wrong. I have a lot of blanks in my p2 because some columns are padded out by more than one whole empty column and then go out of bounds.
>>
>there are 3 Rust users I recognise purely through program style
>>
>>107458848
try reading before posting
>>
>>107458876
it's wrong anon. keep coping, but you're a shitter.
>>
Anyone else know exactly how part 2 can be solved but have been too lazy to implement? The problem is just hella boring tbqh
>>
>>107458889
try reading before posting, dumb retard
>>
>>107458897
>write incorrect big boy
>start shitting and pissing self in rage when people point it out
kys, unironically. why do these threads always have egotistical retards?
>hurr your wrong (no call out)
>not idiomatic enough
>.7z LE VIRUS
>nooo you didn't heckin readerinos

I wish you fucks would all die.
>>
File: carbon.png (139 KB, 744x938)
139 KB
139 KB PNG
>>107456284
  Time (mean ± σ):      59.3 ms ±   3.1 ms    [User: 54.1 ms, System: 4.9 ms]
Range (min … max): 54.2 ms … 64.5 ms 52 runs
>>
>>107458910
>doesn't read
>crashes out because of it
dumb retard
>>
>>107455644
came here to post this
>>
>>107458911
Why do people post runtimes without mentioning what hardware/OS they're using? Especially when the runtime is like sub 100ms, it seems like anything could cause radical fluctuations.
>>
>>107458987
Because I don't want to be called poor.
>>
>>107458987
unless you're on some mobile part or you're 10 years out of date, I can't fathom algorithmic choices not dominating your runtime.
your I/O should be fully cached and near instant when benching this problem too.
>>
>>107458671
ya, I don't get why they keep getting easier. it's bizarre.
>>
>>107458671
no, day 4 was the easiest. literally game of life but missing the "life" part. this problem was easy to implement but required minor amounts of brain power to do efficiently with how retarded eric's formatting was. if all the numbers had been left or right aligned, or there had been some simplistic "uhh uhh modulo your answer by the number of odd digits" trick to the cephalopod """"math"""", then sure, easiest day.
>>
>>107459055
>literally game of life but missing the "life" part
you mean missing sovl? kek

>how retarded eric's formatting
that was part of the problem though. otherwise p2 will have a bland input
>>
So, uh.... We're half way through and the problems aren't getting harder. Is it over?
>>
>>107459019
Really? Because I just benched the exact same program as >>107458911

and got a ~40% improvement
  Time (mean ± σ):      36.9 ms ±   0.5 ms    [User: 34.0 ms, System: 2.3 ms]
Range (min … max): 36.0 ms … 38.5 ms 74 runs


Not using any special hardware, just a 2020 m1 mac mini.
>>
File: shock.gif (1.62 MB, 288x204)
1.62 MB
1.62 MB GIF
>>107459019
>anon when he finds out disk is slower than ram
>>
>>107458848
Yeah other anons pointed it out as well and I posted the corrected one here >>107456284
>>
>>107459161
Eh. That's still kind of plus or minus. Mine is about 150ms and it's an alder lake i9, but I'm also not making "best performance" choices.
>>
>>107459169
>anon doesn't understand what cached I/O means
>>
>>107459170
Thanks.
>>
>>107459181
im not doing that shit
>>
>>107459191
Agreed, I've also manually disabled the L1/2/3 caches on my CPU.
I only want to use FRESH memory, not some stale cached shit.
>>
is there a bigboy with 4 numbers instead of 5? i hardcoded my solution :^)
>>
>>107459191
no you're not, the kernel is doing it
>>
>>107459238
2 seconds for the bigboy with 4 numbers, good enough for me
>>
File: sol_6.png (108 KB, 2053x829)
108 KB
108 KB PNG
Comprehensive Python solution to day 6
>>
>>107457106
Man, I feel guilty even for using math. Luckily, this has happened only a couple of times.
>>
>>107459293
unreadable
>>
>>107459293
'ate wide code
luv me tall code
simple as
>>
>>107459322
Sorry, I meant List Comprehensive Python solution :)
>>
File: sol_6_tall.png (174 KB, 809x1630)
174 KB
174 KB PNG
>>107459335
Got'chu senpai
>>
>>107459336
I know anon, I'm just amuzed to see write-only Python code
>>
>>107459293
>>107459336
I use list comprehension with python all the time, but at least I break the lines to make the code more readable.
>>
>>107459293
Mogged your part 1
>>
>>107459398
>imports
Hey, that's cheating!
>>
>>107459381
Every time I tried to break that huge line it got way uglier...
I can't into line breaks :(
>>
>>107459421
Its crazy to me that python doesn't include reduce by default when it does include map and filter
>>
>>107459432
python is run by a braindead monkey who hates functions
>>
>>107459428
Just break before each for.
>>
https://docs.python.org/3/library/functools.html#functools.reduce

??? I agree python sucks ass though and I legitimately hate shit like list comprehension.
>>
>>107459505
Also the badly named https://docs.python.org/3/library/itertools.html#itertools.accumulate
>>
File: day 6.png (39 KB, 1322x256)
39 KB
39 KB PNG
>>107459398
Mogged you
>>
>>107459398
>>107459421
Fully mogged. Don't know if I want to try part 2 it seems miserable
>>
yikes
not even getting a (You) for that
>>
>>107459205
Stalefags btfo
>>
File: 1712916781798342.jpg (35 KB, 318x239)
35 KB
35 KB JPG
>>107459205
based and puritan-pilled
>>
File: 1742693311823669.png (384 KB, 1650x2644)
384 KB
384 KB PNG
took me a bit to do it in 1 pass but i guess i learned something new today even tho the input was stupid
>>
File: Day6_2025.png (248 KB, 1406x1182)
248 KB
248 KB PNG
>>107459293
>tfw we're nearly the same person although my haircut is slightly better
>>
File: day6go.png (199 KB, 1077x1359)
199 KB
199 KB PNG
Baby's fifth Go program.
>>107456284
128ms
>>
>>107459745
>waitgroup
into the trash it goes
>>
>>107459745
Hey, you finally did multithreading. Now how are you liking Go?

Every time I see your solutions I feel like doing the next one in Go but then I think about if err == nil and having to use a for loop for every single basic operation and I change my mind.
>>
File: 6.png (839 KB, 5492x2022)
839 KB
839 KB PNG
idiomatic Rust solution
>>
>>107458275
>In the example below
>example is actually above
unplayable
>>
>>107459769
Why, what's wrong with waitgroup?
>>107459786
It's growing on me a little. Writing out the loops for stuff isn't so bad, but unused imports and variables being errors is infuriating. If I comment out the one line of code using an import, now I have to go comment out that import too.
The standard library is kind of shit though. The int parsing code is SUPER slow, and scanners refusing to parse long lines got me today. I had to write the lines function for bigboy because of that.
The documentation is annoying too. The builtin functions and builtin types not being documented in the standard library docs, the specification saying a bunch of stuff (like modules or the magic comments) is an "implementation detail" despite there being just the one implementation, etc.
>>
>>107459791
idiotmatic
>>
File: go-day6.png (150 KB, 1151x808)
150 KB
150 KB PNG
>>107459786
>but then I think about if err == nil
Not really relevant for AoC
>and having to use a for loop for every single basic operation
Very true, I don't mind this at all in my day job, but for these little things that is quite annoying

>>107459877
>unused imports and variables being errors is infuriating
You can often do
_ = thing
to get around that, but yeah

Anyway here is my Go solution, it's a mess and probably pretty slow
>>
Advent of junk
#include <stdio.h>
#define MAX_LINE_LEN 4000

#define cnum(c) \
if(c != ' '){ \
num+=mul*(c-'0'); \
mul*=10; \
}

static inline long getNum(char c1, char c2, char c3, char c4){
long mul = 1, num = 0;
cnum(c1)
cnum(c2)
cnum(c3)
cnum(c4)
return num;
}

int main(){
char pTable[4][MAX_LINE_LEN] = {0}, op = 0;
long sol = 0, idxp = 0, tmp = 0;
for(int i = 0; i < 4; i++)fgets(pTable[i], MAX_LINE_LEN, stdin);

for(int i = 0; pTable[0][i-1] != '\n' && i < MAX_LINE_LEN; i++){
if((pTable[0][i] == ' ' && pTable[1][i] == ' ' && pTable[2][i] == ' ' && pTable[3][i] == ' ' )||
pTable[0][i] == '\n'){
scanf(" %c", &op);
for(tmp = 0 + op == '*'; idxp < i; idxp++){
if(op == '*') tmp *= getNum(pTable[3][idxp], pTable[2][idxp], pTable[1][idxp], pTable[0][idxp]);
else tmp += getNum(pTable[3][idxp], pTable[2][idxp], pTable[1][idxp], pTable[0][idxp]);
}
sol += tmp;
idxp++;
}
}
printf("%ld\n", sol);
}
>>
>>107459877
>The builtin functions and builtin types not being documented in the standard library docs
Not sure what you mean by this. Check out https://pkg.go.dev/builtin
Also, in vim, typing `gd` on `len` takes me right to its implementation.
>>
>>107455604
2025 day 06 (Part 2):

This one is a little trickier. Parse the input reversed into a matrix of runes, keeping the whitespace. When you parse the final line, trim the whitespace and parse it into an operations vector. Reverse the operations vector too.

Transpose the matrix of runes and iterate through the transposed matrix. Convert each row into an int and apply each operation as detailed in the operations vector accordingly.

https://pastebin.com/YrwiGV9L
>>
>>107459877
use goimports instead of manually managing your imports, which also does a fmt. I have a key bound to it in vim. go's tooling is frustrating because it's not documented in one place with clean versioning and deprecation notices, but after you find the tooling it's generally great. I got a several-minute cloud build down to several-seconds by vendoring my dependencies after figuring that out.
>long lines
buf := make([]byte, 0, 500*1024*1024)
scanner.Buffer(buf, len(buf))

scanner can now handle long lines
>just the one implementation
there's also tinygo and gcc-go, but yeah the language documentation is strangely terrible and if you go looking for answers, the details have all changed radically over time so you're constantly running into stale advice. The library documentation is generally very usable, meanwhile.
go has plenty of WTF design, like the magic date formats, but what it has over near competitors is that it's done well and that the WTF design represents a small group's consistent idiosyncrasies instead of a large group's chaos or a madman's pathless search for the one true way to do things.
I started liking go a little more after reading 100 Go Mistakes.

pic: day 1 in OCaml. YOU ARE DOING THIS TO ME, ERIC
>>
>>107459995
I forgot about that page, but maps and channels still aren't there.
>>
File: o1.png (368 KB, 1054x1075)
368 KB
368 KB PNG
>>107460026
>>
>>107459999
>QUADS

Can somebody say amen?
>>
>>107459999
no i don't think i will
>>
>>107459999 = 733 * 146603
you're redoing the work of rebuilding that regex once per line
the large loop can just be: for _, o := range operations {
>>
>>107458025
how many indians do you need to write a proper Haskell program?
(hint: use the infinite money theorem)
>>
>>107458025
you've got it backwards, anon
Haskell is curried by default, making it Indian, but you can fix it with uncurry
>>
File: aoc06.png (413 KB, 1280x3808)
413 KB
413 KB PNG
ok I might be dumb
but I think we can safely conclude that we pass up on doing more vanilla tex during advent of parsing significant whitespace
>>
my solution is so ugly that I'm not even gonna post it.
but hey star is a start
>>
>>107460448
You realize you're anonymous and a retarded ugly solution is more entertaining than an efficient try-hard one, right?
>>
>>107460363
how loose is the \ key on your keyboard?
>>
>>107460505
lol
>>
Was keen on doing the aoc in rust this year, and on part 2 of day 6 the solution just ran forever and I killed the program when I saw it was using 35GB of ram. not to mention the retarded hoops I had to jump through thus far because "uhhh the value is being moved here" and "no, you can't index characters directly, sweaty"
went back to c++ and had a solution in half the time I was messing with rust that runs immediately and worked the first time. meme language.
>>
>>107460544
c++ made this easy for once since i can just stripe through the lines for pt2 about as quickly as i was parsing them wholesale in pt1
>>
>>107460544
I tried to do the AoC in Rust last year and I simply couldn't get warm with that language.
>>
File: code.png (535 KB, 1590x3802)
535 KB
535 KB PNG
>>107460476
ok you beat me to it
initially I wanted to transpose the whole input for part2 so I could just parse the numbers line-by-line
but the I said fuck it and just wrote the number parsing function in different direction.
I went through so many bugs, one because editor stripped trailing whitespaces but they mattered here to make it a proper grid
or leading spaces in first row, you simply can't break a group on, it must be full column of spaces

it was ugly but worked. I had no motivation to go back and do it properly.

I rather watched a movie - Eddington - but it was such a crap that I stopped in middle and rather went to wash a toilet.
>>
>>107460544
>>107460610
It just prioritizes things that are relevant for coding puzzles, like an extensive type system and unique memory management model. Obviously.
The only languages that are actually a good fit for AOC are high level scripting languages. Everything else has some level of pointless hoop-jumping involved.
>>
File: day6stretch.png (2.34 MB, 8760x996)
2.34 MB
2.34 MB PNG
>>107459555

Jesus Wept
>>
>>107460743
wow good job
>>
>>107460793
I coerced a list into a string, performed string operations on it, and eval()ed it back into a list. It's awful.

As I'm typing this I realize I could have done what I wanted properly with reduce(), but I'm not rewriting that shit
>>
>>107460743
>using map and reduce instead of list comprehensions

Not pythonic enough. List comps aren't as clear as map reduce but personally I think they're worth it for the added width they give your code.
>>
Where are the arrayfags? This is a glorified cross product, should be right up their alley.
>>
File: ocaml2.png (479 KB, 1310x1570)
479 KB
479 KB PNG
>>107460037
day 2 in OCaml
this is somehow faster while using less memory than the equivalent d
>>
>>107460974
the transpose summoned a rare J poster >>107454280
>>
File: 1739618734136980.png (9 KB, 683x384)
9 KB
9 KB PNG
need to go to bed soon to wake up for the wall tomorrow
>>
First day I'm unhappy with one of my solutions, part 2 made me write some nasty code.
>>
>>107461093
>wall tomorrow
I hope so. on the halfway mark last year, the corner counting raped a lot of people. this was a shameful display compared to that problem.
>>
>>107461093
what the fuck am i looking at
>>
>>107461506
Nice try mirror fiend
>>
File: day6stretch.png (2.36 MB, 8760x996)
2.36 MB
2.36 MB PNG
>>107460908
You are so right.
>>
File: 1702495811364840.png (357 KB, 680x678)
357 KB
357 KB PNG
>>107461506
>>>/wsg/6045254
https://i.4cdn.org/wsg/1765060603012448.webm
>>
>>107461506
also this
https://i.4cdn.org/wsg/1765060755702225.webm
>>
>>107461635
what are they expecting to see instead? the void?
>>
>>107461654
I think they were expecting an empty paper but I'm not sure since I'm not retarded
>>
File: carbon(152).png (726 KB, 1478x4096)
726 KB
726 KB PNG
Washed ass featuring divine intellect self modifying code
>>
Is there any way to get this AWK solution working or should I give up on my dream of parsing line-by-line?
>>
File: 1757929389669255.png (33 KB, 182x150)
33 KB
33 KB PNG
>>107461635
>>
File: day5.png (267 KB, 1312x1540)
267 KB
267 KB PNG
my day 5 trying to catch up
>>
File: ocaml4.png (446 KB, 1442x1603)
446 KB
446 KB PNG
>>107460987
day 4 in OCaml
the OCaml time/space advantage (vs d) disappears on the bigboys, so it's just a difference in runtime overhead.
>>
>>107458293
>>107458274
This is looking pretty good.
>>
>>107461902
Filtered
>>
>>107455935
>I don't even feel like doing part 2
You can just say "I don't like working with strings in Haskell". We'll understand your faggotry.
>>
>>107462060
Anon, there is no global leaderboard anymore. It's not possible to be filtered.
>>
File: day6_washed.png (695 KB, 1478x3948)
695 KB
695 KB PNG
>>107461750
Whoops missed a spot
>>
>>107462085
Filtered.
>>
>>107460697
>The only languages that are actually a good fit for AOC are high level scripting languages.
Appears to be so. The scripters in my group are all having a blast because they all have the right tools already. The diehard C++ and C# fans are all struggling to keep up.
And there's some who appear to have not realized that it's started. All that eggnog and Mariah Carey not a big enough clue for you guys yet?
>>
>>107462133
As long as he does them all before Christmas, he isn't filtered.
>>
>>107462143
I don't understand it. You don't have to go full "muh idiomatic Rust." My sln for day 6 is 79 lines long, including empty lines. It feels about the same as any higher level language.
>>
>>107461000
That stuff looks like someone stripped almost all the letters out of a Perl script. Must be idiomatic J.
>>
>>107462175
except that rust is like a thick, dense mud that tries its very hardest to hinder your every move, while C++ is like stepping on the smooth back of a baby
>>
>>107462209
How? It looks and feels much like kotlin or typescript to me. I'd argue rust is better and easier than both but that's because I enjoy the explicitness of borrows and mutability.
>>
>>107462175
My solution was 33 lines (of Tcl) for part 2, but only because I put blank lines and comments in. No artificial cramming-things-onto-one-line either; that would feel like cheating myself. I could knock a third off that if I didn't want some readability for future me.
Some of AoC is about using the tools of one's language efficiently and effectively.
(I put part 1 in a separate file because I think that way.)
>>
>>107458276
d5p1 was bleh due to the stupid max element limit on ranges due to Java brain damage
val Array(fresh, ids) = scala.io.Source.stdin.mkString.split("\n\n")

val freshRanges = fresh.linesIterator.toVector map {
case s"$from-$to" => (from.toLong,to.toLong) }

def isFresh(id: Long) = freshRanges exists {(from,to) => from <= id && id <= to}

println(ids.linesIterator map {_.toLong} count isFresh)
>>
File: d6.png (1.13 MB, 1200x4667)
1.13 MB
1.13 MB PNG
advent of simd

>>107456284
6ms for multi-threaded, 14ms for single-threaded

single-threaded
Silver: 117309571763
Gold: 163990321309

Performance counter stats for './6_st ../../../inputs/6/bigboy.txt' (500 runs):

13,526,768 user_time ( +- 0.06% )
1,264,091 system_time ( +- 0.22% )
52,471,949 cycles:u ( +- 0.03% )

0.0148277 +- 0.0000125 seconds time elapsed ( +- 0.08% )


multi-threaded (4 cores)
Silver: 117309571763
Gold: 163990321309

Performance counter stats for './6_mt ../../../inputs/6/bigboy.txt' (500 runs):

24,578,767 user_time ( +- 0.12% )
1,938,016 system_time ( +- 0.19% )
94,710,263 cycles:u ( +- 0.58% )

0.0061752 +- 0.0000309 seconds time elapsed ( +- 0.50% )
>>
>>107462328
for d5p2 I got lazy and cheated. Might be more elegant with a fold or uglier, don't really care atm. A proper multirange type that doesn't have the int max element limit and does unions properly would have been the most pleasant to do with a short fold + final .size, but it's not in the cards today
val ranges = scala.io.Source.stdin
.mkString.split("\n\n").head.linesIterator // first stanza
.map {case s"$from-$to" => (BigInt(from), BigInt(to))}
.toSeq.sorted

var total = BigInt(0)
var l = ranges.head._1
var r = ranges.head._2

for range <- ranges do
if range._1 > r + 1 then // gap: finish current block
total += r - l + 1
l = range._1
r = range._2
else // overlap or just touching: extend
r = r max range._2

println(total + r - l + 1) // close last block
>>
>>107461800
I don't know awk, but my idea to parse line by line would be to keep an accumulator for each character in the line, then multiply it by n=100 where n/10 each line, also you divide the accumulator by 10 if the accumulator is non-zero and the digit is empty to account for top aligned numbers
>>
>>107461000
Isn't J a bit disliked among the array languages/APL. Also for all the cniles here, look at the J source code
>>
>>107462450
they're all disliked and they all have fans. J has decent libraries and tooling. I still use it for math/uu and primitives like q: for pointless mathing.
(Dyalog) APL's the most employable and also the oldest feeling. K's the most approachable and also the most hacky. BQN's the most modern and also the most limiting. uiua's the most LGBT with LGBT operators, pretty much the king of LGBT in programming until a language comes along that can molest you itself. J's in a happy medium.
>>
>>107462501
isn't K also ascii only, whats the real difference with J, and i know most of these languages from the code_report youtube channel
>>
>>107462547
K is a very different APL-inspired language
J is ASCII APL
>>
C23, day6 bigboy in 111 ms
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
typedef struct {HANDLE f_, m_; char* begin, *end; } MmFile;
MmFile Map(const char* s) {
MmFile 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(MmFile* 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; auto a = in.begin;
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!");
size_t size = in.end - in.begin, p1 = 0, p2 = 0;

for (size_t e = size - w + (a[size - 1] != '\n'), x = size; x-- > e;) {
int o = a[x];
if (o < '*') continue;
size_t r = o == '*';
for (auto y = x - e; y < e; y += w) {
size_t n = 0, l = 0;
for (auto i = y; i < e; ++i) {
int c = a[i]; unsigned d = c - '0';
if (d <= 9) n = n * 10 + d, ++l;
else if (n && c <= ' ') break;
}
if (l) { if(o == '*') r *= n; else r += n; }
}
p1 += r;
}
for (size_t o = 0, r = 0, x = 0; x < w; ++x) {
if (a[x] == '\n') { p2 += r; break; }
size_t n = 0, l = 0;
for (auto y = x; y < size; y += w) {
int c = a[y]; unsigned d = c - '0';
if (d <= 9) n = n * 10 + d, ++l;
else if (c >= '*') p2 += r, r = c == '*', o = c;
}
if (l) { if (o == '*') r *= n; else r += n; }
}
printf("%llu\n%llu", p1, p2);

UnMap(&in);
}
>>
>>107462726
omg it's cutie pie anon ;)
>>
get a room
>>
File: ocaml5.png (485 KB, 1474x1768)
485 KB
485 KB PNG
>>107461916
day5 in OCaml
ocamlopt doesn't have -O so I assumed it didn't need any optimization flags, but it has -O2 and -O3
with those it's back to beating d
>>
>>107460544
Are you me I had almost the same experience. Except borrowing checking isn't that bad. What gets me is options/results. Good god I gotta spam unwrap/get the stupidest type errors.
But I ain't gonna quit just yet.
>>
>>107461093
#include <limits.h>
#include<stdio.h>
void main(){
for (size_t i =0; i < ULLONG_MAX; i++) {
printf("Jesus Christ my sides");
}
}
>>
If today is a day-1 leetcode-easy math problem for the 7th time in a row I am going to lose my mind
>>
>>107463072
>void main
>>
File: carbon.png (70 KB, 1540x564)
70 KB
70 KB PNG
C L E A N
>>
>>107463114
nice
>>
File: day6.png (210 KB, 1312x1294)
210 KB
210 KB PNG
finally caught up now
>>
>>107460544
>>107463040
You can literally just treat the input as a grid. What is the problem?
>>
There's a major gap in the market for an modern, compiled, mainstream programming language without gc. Rust is pointlessly obtuse if you don't care about "safety", and it's only as popular as it is because there aren't any serious alternatives. Mark my words, it'll go the way of Ruby the millisecond something else comes along.
>>
>>107463205
>>>107463040(You)
I just don't like having to unwrap bunch of stuff. I get in production code it's a good standard, but for puzzles it's a needless constraint. I like the parts I like but it's asking for strict correctness in areas that are not needed. It's also creating bad habits, since I end up ignoring/unwrapping errors.
>>
also some basic things like direct indexing is now considered harmful and will get a lint out of clippy. the recommended approach is writing idiotic rust like seen itt, which is fine if you're into that, in the same way that people like functional languages, but it's not for me.
>>
>>107462430
I eventually gave up and just piped my input in in reverse. Eric put the operator in the same position in the string as the first digit in each problem.
>>
File: day 6 part 1.png (310 KB, 1443x2067)
310 KB
310 KB PNG
painful
>>
>>107463515
what is this i dont get it
>>
THE SHAMEFUL FILTER
>>
File: ocaml6.png (565 KB, 1490x2230)
565 KB
565 KB PNG
>>107462955
day 6 is no less unpleasant in OCaml.
debugging in this language is a pain because OOB exceptions don't have useful information by default, and because there's no general debugging printer. With a -g and OCAMLRUNPARAM=b the first is improved.
You can derive a printer with ppx_deriving.show,
type wtf = int list array [@@deriving show
(* later ... *)
let () = print_endline (show_wtf nums')

but that requires dune, a project layout, adding a preprocess step to a dune file. It's not a lot of work, but compared to any convenient language it's already a strange amount of work.
thank you for following my blog, it will be shorter than usual this year.
>>
>>107463564
Dam, really? Today was one of the easier ones so far
>>
>>107463553
Prolog
>>
>>107463575
oh i see why its so cursed then
>>
>>107463564
nooo
i appear as filtered but i just completed it now :(
millions must die
>>
>>107463608
you will show up again on tomorrows (unfortunately)
>>
>>107463615
hell yeah. beign european sucks for aoc honestly, the timing couldn't be worse
>>
>>107463643
Nah, US East coast is worse. I go to bed 30 minutes for the next one releases.
>>
>>107463608
Filtered.
>>
>>107460544
>went back to c++
you failed anon

>>107463260
we learn in plight
I am doing in zig this year. it's pretty comfy. you can give it a try

>>107460743
if you resorted to eval then why even use reduce, etc. just do eval(op.join(nums)).
in p2 you can remove your reduce(...) part with (item[0][-1] == "+" and sum else math.prod)(map(lambda x: int(x[:-1]),item)

>>107463380
>direct indexing is now considered harmful
based. manual indexing is a source of many bugs in degenerate cases like the array being empty and so on. just do iter.skip(start).take(len)

>>107463437
did you use tac for reversing the file linewise?

>>107462726
cute as always <3
another anon posted a cute C solution you might find it interesting >>107455843

>>107459169
that's why you do warmup runs to fill the fs cache

>>107459161
that doesn't necessarily mean it's due to file IO tho

>>107458911
anon use github.com/andrewrk/poop for more stats
>>
>>107463676
>like the array being empty and so on
did you write the article from the other day?
>>
DRAW ANON!
DRAW ANON WHERE ARE YOU???
>>
>>107463703
no, which article?
>>
>>107463676
last year I hated zig more and more for how incredibly verbose and inconvenient the integer casting was. Zig is worse than most languages in this respect. Worse than Ada.
there's a lot of code where that just doesn't come up though, especially if you stick to generous signed types and lots of intermediaries to @intCast into
>>
>>107463710
the one that says direct indexing is bad. because it's the same argument and I don't see how that could happen in practice.
>>
>>107463676
>if you resorted to eval then why even use reduce, etc. just do eval(op.join(nums)).
>in p2 you can remove your reduce(...) part with (item[0][-1] == "+" and sum else math.prod)(map(lambda x: int(x[:-1]),item)
I was able to get rid of the eval, i agree that was stupid.

And as for the second thing, I missed that thanks. that syntax wasn't accepted though the correct syntax is (sum if item[0][-1] else math.prod)
>>
>>107463676
>did you use tac for reversing the file linewise?
Yep! Iterated over the now-first line, tracking the position of each operator and then used that ro write down the results line by line in a hash table.

No fancy math, just string concatenation.
>>
>>107463736
I used to avoid it too because I always found all Zig code to be overly verbose. So far I have been able to avoid any integer casting mess by just sticking to unsigned types. You can use wrapping and saturating operations, distinction between mod and rem is much appreciated, int upcasting is done automatically (unlike rust), etc. I am glad that they put thought into the details that most languages just skim over.

Also, Zig's @Vector finally got me into trying SIMD. It sucks in C/C++. It's relatively painless in Zig and supports much more operations. Most operations that can operate on int and float can operate on a Vector too.

>>107463747
For a slice of len 5, what would slice[10..20] result in your language? It should ideally be an empty slice and the skip/drop + take pattern follows that. Not to forget that the indices are just the intermediaries you need to eventually access the elements, which iterators/ranges allows directly. Most real world use cases deal with simple scenarios, not strided loop over a 3D matrix.
>>
>>107463834
sorry I meant (item[0][-1] == "+" and sum or math.prod)
you can drop the explicit import statement for (item[0][-1] == "+" and sum or __import__("math").prod)

>>107463845
pretty cool solution. and a rare sight of tac. someday I will get to learning awk finally :). awk anons' solutions are so comfy
>>
>>107463873
Yeah i completely forgot about and/or short-circuiting or whatever its called, that's a good trick
>>
>>107463889
it's what Lua uses in place of the ternary operator, and it has some limitations which http://lua-users.org/wiki/TernaryOperator notes
>>
>>107463845
did the same for part one then switched to C for part two
>>
>>107463873
Awk is a lot of fun. Plus it lets me jam in shell utils when I don't want to, say, reverse a file.
>>
>>107463952
AWK's type system was actually really useful for part 2; you can concatenate numbers together and then just do math on the result.
>>
>>107463853
>For a slice of len 5, what would slice[10..20] result in your language?
I personally never use that, so I can't say for sure. I guess c++ kind of has this with *_view and the new views api. maybe you can also put something together with iterators. c# has slices and Take/Skip but I also rarely use either, unless I'm already writing Linq.
Imo it just feels wasteful, unless I'm misunderstanding how iterators work in rust, that you have to iterate over n elements to then take the amount you want (using skip+take), even if it may have a negligible performance impact, instead of just accessing directly which is essentially free.
>>
>>107463705
i'm worried...he might've been filtered
>>
>>107463705
Christmas is cancelled.
>>
>>107464014
skip+take is free on random access iterators too. Another optimization iterators allow is skipped bound checking. The compiler can reason about your code more in declarative style as compared to you manually iterating while i < len. It can unroll loops more easily.
I use C++20 ranges a lot these days and it's very convenient, especially when dealing with ranges that are not random access like set, map, etc. You can iterate in reverse like for (auto& i : range | views::reverse) without having to do for (auto it = range.rbegin(); it != range.rend(); ++it) and then dereferencing that it on each use. Similarly with drop, take, enumerate, chunk_by, etc.

>>107464044
nooo :<
>>
>>107463705
I'm still here I was occupied for much of the day. Working on today's thing currently. I did day 6 so quickly after release I probably should've did the drawing before bed instead of sleeping on it
>>
>>107464107
hmm cool, maybe I should learn more about c++ ranges/views.
>>
>>107463964
>AWK's type system
no idea what that is but yeah high level features are cool
until they aren't
$ printf '%s\n' 100 2 | awk '{a[$0]}END{for(i in a)for(j in a)if(i>j)print i " is greater than " j}'
2 is greater than 100
>>
>>107464120
can we get a drawing of elves writing a computer program?
>>
one hour anon must have been filtered
>>
>>107464134
Ouch. Can't say I remember coming across this behavior in the wild.
>>
>>107463964
>AWK's type system was actually really useful for part 2; you can concatenate numbers together and then just do math on the result.
you mean the implicit conversion of a string to a number?
>>
>>107464134
wtf is going on here?
$ printf '%s\n' 100 2 | awk '{ a[$0] } END {for(i in a) { for(j in a) { print(i, j, i > j) } } }'
2 2 0
2 100 1
100 2 0
100 100 0
>>
>>107464148
todays (recursion day btw) should be elves drawing elves drawing elves drawing elves
>>
>>107464399
>recursion day btw
which would make part 2 memoize day
>>
>>107464383
oh I see
If the operands are string, it's doing a lexicographical comparison.
$ echo | awk 'END { print("2" < 10) }'
0
$ echo | awk 'END { print("2" < "10") }'
0

This is why perl has lt, le, gt, ge, cmp, eq, ne.
>>
>>107464414
which would make this thread tabular-on-memoization violence
>>
File: file.png (111 KB, 1200x1200)
111 KB
111 KB PNG
Only real idea I had was continuing the Factorio theme from yesterday. Pentapod math isn't that dissimilar from cephalopod math.
>>
File: file.png (69 KB, 1200x1200)
69 KB
69 KB PNG
>>107464449
>>
>>107464449
>>107464456
balancing your belts is for nerds just overproduce, and on gleba simply hang yourself.
>>
>>107464449
also of course there was no idea for today. Eric has given up
>whats the story for today..... hmmm.... uhhh the puzzle is math homework! Yep Eric, you still got it
>>
>>107464449
>>107464456
the only good part about today's puzzle
>>
where the fuck is everyone
>>
>>107464356
Yep.
>>
>>107464538
out, probably
>>
File: homework.png (13 KB, 400x100)
13 KB
13 KB PNG
>>107464499
eric has an inner redditor which marks problems as duplicates but he publishes them anyway
>>
>>107464499
Yeah, it was like those jokes we used to make. "The elves give you a list of prime factors..."
>>
>>107464424
everything's a string in standard awk
numeric strings are converted using strtod() when they're involved in numeric operations
>>
MASSIVE FILTER INCOMING
>>
>>107464602
i seriously hope so
if even half of you retards are still here on day 12 then i'm molesting eric
>>
>>107464615
none of us are making it to day 25
>>
im at such a low point in my life anons... only thing that doesnt want me to rope is solving these retarded puzzles and looking how smarter people do it after
>>
File: wall1.jpg (127 KB, 675x1000)
127 KB
127 KB JPG
>>
normal day 7 puzzle incoming , proving once and for all that eric got halfway through designing the puzzles this year and just gave up.
>>
>>107464615
Better get your molesting gloves ready then.
>>
>>107464449
>>107464456
better than the puzzles themselves
>>
File: wall2.jpg (183 KB, 862x575)
183 KB
183 KB JPG
>>107464631
>>
File: wall3.jpg (364 KB, 424x626)
364 KB
364 KB JPG
>>107464637
>>107464632
>>
I'm not even going to shit before this one.
If I complete it before I have to shit, it's shit.
>>
>>107464449
>>107464456
love you anon <3. thank you for saving christmas and aocg
>>
page 9, new thread before puzzle drops?
>>
>>107464602
If it isn't then the memes about Eric giving up half-way are 100% true
>>
I just took the most massive shit of my life. But this feeling of euphoria is not going to last long because of what Eric has prepared for us today. (Please Eric, I beg you)
>>
>>107464660
since when do threads on /g/ go to 500 replies? last one did
>>
>>107464660
please wait 300 seconds
>>
Just took a huge shit, you will see it in about 9 minutes
-Eric
>>
File: WALL_INCOMING.jpg (157 KB, 462x260)
157 KB
157 KB JPG
>>107464631
>>107464637
>>107464641
TONIGHT'S THE NIGHT, WALL-BROS
>>
File: AOC-D05.png (91 KB, 1092x664)
91 KB
91 KB PNG
I don't get it, are the cephalopods supposed to be inside the garbage smasher with you? If they're outside, aren't we basically underwater then? How are we not drowning?
>>
>>107464681
no john you are the demons
>>
>>107464668
cephalopod math sure was hard! the elves are impressed and give you a worksheet of elf math. elf math is structured like this:
123+456-789*321+654

can YOU help solve it?

>part 2
the elves teach you about order of operations!
now what will the answer be?
>>
5 MINUTES
>>
>>107464689
https://adventofcode.com/2020/day/18
>>
File: showtime.jpg (46 KB, 640x480)
46 KB
46 KB JPG
www.youtube.com/watch?v=hjGZLnja1o8
>>
File: saddam.png (29 KB, 1073x225)
29 KB
29 KB PNG
>>107464681
>>
>>107464709
cancer music
>>
>>107464660

NEW
>>107464708
>>107464708
>>107464708
>>
>>107464710
>garbage chute wasn't hidden by bricks and rubble
garbage
>>
one line regex incoming
>>
FUCK



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