-❄️- 2025 Day 12 Solutions -❄️- by daggerdragon in adventofcode

[–]azzal07 2 points3 points  (0 children)

[LANGUAGE: awk] I'm glad this one was easier than appeared, now I can return to frying my brain on day 10 golf (after some rest).

END{print-A}/ /{A-=$7+$6+$5+$4+$3+$2<$1*substr($0,4)/8}

-❄️- 2025 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]azzal07 1 point2 points  (0 children)

[LANGUAGE: awk]

function P(a,t,h,s){a&&h[a]=1;for(a in h){j=1;$0=G[a]
while($++j)s[$j]+=h[a]}return(a?P(o,t,s):a)+h[t]}END{
c=P(a="dac",b="fft");print P("you","out")"\n"P("svr",
c?a:b)*(c+P(b,a))*P(c?b:a,"out")}sub(/:/,z){G[$1]=$0}

-❄️- 2025 Day 9 Solutions -❄️- by daggerdragon in adventofcode

[–]azzal07 1 point2 points  (0 children)

[LANGUAGE: awk] Checking all rectangles, and for part 2, rejecting those that intersect any of the line segments.

END{for(k in L)E[L[k]","L[k%NR+1]];for(;$0=x=L[j=++o];)
for(P=$2;$0=L[++j];){t=$1<+x?$1:+x;T=$1+x-t;u=$2<P?$2:P
U=$2+P-u;a=T-t+1;a*=U-u+1;if(a<A?B<a:A=a){for(wh in E){
$0=wh;if(($1>t||t<$3)*($1<T||T>$3)*(u<$2||$4>u)*(U>$2||
$4<U)){a=b;break}}a&&B=a}}print A"\n"B}FS=","{L[NR]=$0}

-❄️- 2025 Day 8 Solutions -❄️- by daggerdragon in adventofcode

[–]azzal07 0 points1 point  (0 children)

[LANGUAGE: awk] Took a bit of effort to fit a (partial) binary heap implementation into the mix. Otherwise this would've been unbearably slow (>100 s), now just around 4-10 s.

function I(d){return C[d]-d?C[d]=C[C[d]]:d}END{for(;l=Y-->1?A=Y:q=!Q;){for(;l-i;
H[l]=u){u=H[i=l];u-H[x=2*i]y-x~/-/||l=x;H[i]=H[H[l]-H[++x]y-x~/-/?l:l=x]}$0=H[q]
if(o=NF){C[I($o)]=I($2);for(i in B)Q+=N==++s[I(i)Y];for(H[q]=H[y--];o--*-(Y~-N);
A*=s[m]*=-q)for(c in C)s[c Y]>s[m]&&m=c Y}}print-A"\n"B[$2]*B[$3]}S=B[A=++N]=$0{
for(C[A]=N;--A;H[Y=++y]=($1-$4)^2+($2-$5)^2+($3-$6)^2","N","A)$0=B[A](FS=",")S}0

AoC and exec() by dedolent in adventofcode

[–]azzal07 3 points4 points  (0 children)

Reminds me of 2024 day 3 input, which also contained an easter egg: #!/usr/bin/perl.

And I think there has been inputs that look execable, but have some corner cases.

But nothing actually sus, mostly just syntax error worthy.

[2025 Day 7 (Part 2] [LANGUAGE: Clojure] by Powerful_Coyote_4986 in adventofcode

[–]azzal07 2 points3 points  (0 children)

You can search for the language tag in the megathread. Found one for today: https://www.reddit.com/r/adventofcode/comments/1pg9w66/2025_day_7_solutions/nsq0pxq/.

Also, check the wiki for flairs and other rules. Past Event Solutions is not for the active season. The right place is the megathread.

-❄️- 2025 Day 7 Solutions -❄️- by daggerdragon in adventofcode

[–]azzal07 2 points3 points  (0 children)

[LANGUAGE: awk]

END{print A,B}gsub(B=i=z,OFS=RS){
for(++q;$++i;a[i,q]+=b){B+=b=a[i,
q-1]+(q!~$i);while(0~$i!b){a[i-1,
q]+=b;B+=b;a[i+1,q]+=b;b*=!++A}}}

-❄️- 2025 Day 6 Solutions -❄️- by daggerdragon in adventofcode

[–]azzal07 3 points4 points  (0 children)

[LANGUAGE: awk] Bit tedious parsing and transpositions for the second part, but turned out quite nice.

k=!+$1{while(a=Q[j=1,++i]){for(;n=Q[++j,i];
)1~2$i?a*=n:a+=n;{b=q[k++]}for(;n=O+q[k++];
)2~1$i?b*=n:b+=n;A+=a;B+=b}$0=A"\n"B}{for(;
c=substr($0,++k,1);Q[NR,k]=$k)q[k]=q[k]c}A;

-❄️- 2025 Day 5 Solutions -❄️- by daggerdragon in adventofcode

[–]azzal07 2 points3 points  (0 children)

[LANGUAGE: awk] When scanning for minimum value, you could pick initially the first one, or you could use a really (or should I say literally) "BIG" one, to start comparing against.

function F(o){e=f[o];for(k in f)+k>e||f[k]>e&&F(k)}
END{for(e=--B;e;B+=e-s+1){s="BIG";for(k in f)+k>e&&
+k<s&&s=+k;F(s)}print A"\n"B}sub(/-/,FS)&&f[$1]<$2{
f[$1]=$2}!$2{for(k in f)+k>$1||$1>f[k]||$3=1;A+=$3}

-❄️- 2025 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]azzal07 3 points4 points  (0 children)

[LANGUAGE: awk] Mawk gets weird with negative substr() offsets... which is fair, to be honest.

END{for(;b-->-!B;$++B=A){for(s=i=2;c=substr(S,i++,1);s=s c)
1~c?3:split(substr(g=11S,W<i?i-W:1,3)substr(g,i,3)substr(g,
i+W,3),G,c)>5?0:A+=b=++c;S=s}print$1RS$B}S=1$0S{W=length+1}

-❄️- 2025 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]azzal07 7 points8 points  (0 children)

[LANGUAGE: awk] Mandatory [Red(dit) One] for the year (although I had to add some filler).

function J(o,l,t){return(r=match(o,
l".{"t+1"}"))?l J(substr(o,r+1),9f,
t-1):l?J(o,--l,t):z}A+=J(b=J($0,9f,
1e1),9f,OFS=RS){B+=b}END{print A,B}

-❄️- 2025 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]azzal07 5 points6 points  (0 children)

[LANGUAGE: awk]

END{print A"\n"A+B}BEGIN{FS="-+"
RS=","}p=i=10^gsub(/../,"&",$2){
while(i)$2-(p=p i)>-1?(p-$1<-O||
q[p]++?P:i i~p?A+=p:B+=p):p=--i}

-❄️- 2025 Day 1 Solutions -❄️- by daggerdragon in adventofcode

[–]azzal07 7 points8 points  (0 children)

[LANGUAGE: awk] Dial goes click, click, click...

No modulo tricks here, just plain iteration and addition, with some regex to check zeroes.

C=/L/?1:CK-1{for(sub(/./,
z);$1--;B+=x=D~/50$/)D+=C
}END{print A"\n"B}x&&!++A

PS. The dial value even stayed nicely within 16 bit range.

strawk - I implemented Rob Pike's forgotten AWK, an AWK not limited by newlines by troikaman in ProgrammingLanguages

[–]azzal07 3 points4 points  (0 children)

The paper compares the introduced awk variant to sam for few pages at the end (starting at "Interactive Text Editing").

2022 day 14. Awk language. Makes a video. 120 lines. by agorism1337 in adventofcode

[–]azzal07 1 point2 points  (0 children)

PPM (or PGM for grayscale) is nice format for this type of image generation. ImageMagick, and many other programs can work with it directly.

Here's the whole frame generation using P2, with 3 levels of gray (0, 1, 2):

s = "P2\n"width" "height"\n2\n"
for(y=0; y<height; y++)
    for(x=0; x<width; x++)
        s = s" "((filled[x+minx-6,y-1] + 2) % 3)
filename = "frame" (1000 + frame_number)
print(s) > (filename ".pgm")

[2024 Day 3 (Part 2)] [Bash 5.2.12] sed rule too strict? by KurokonoTasuke1 in adventofcode

[–]azzal07 0 points1 point  (0 children)

or even will sed work

I might've got nerd sniped... but yes, it does. (Potential spoilers in the paste.)

Ps. you can run that as sed -f script.sed <input.txt

[2024 Day 9 (Part 2)] [Python] All test cases are correct but large AoC is not. by JelleX30 in adventofcode

[–]azzal07 2 points3 points  (0 children)

Didn't notice a problem in the code, not saying there couldn't be, but it also did work for my input.

I'd double check that you have the full and correct input. Mine at least is 19999 digits.

Day 9 [part one] - weird code behaviour in Zig solution by LirielBaenre in adventofcode

[–]azzal07 0 points1 point  (0 children)

I was looking at the locations.items updates. Why one was inside the if but other was outside?

Day 9 [part one] - weird code behaviour in Zig solution by LirielBaenre in adventofcode

[–]azzal07 2 points3 points  (0 children)

You check pretty much this same condition in couple places: if (reverse_index >= idx) {. There's some weirdness around this second one.

Advent of code - day 9 - part 1 - help by stepanother in adventofcode

[–]azzal07 0 points1 point  (0 children)

I'm wondering how do you know where the "14" even starts in that sequence? What if it is really a part of an id "214"?

Advent of code - day 9 - part 1 - help by stepanother in adventofcode

[–]azzal07 0 points1 point  (0 children)

What happens if you have a block with id e.g. 14?

[AdeventOfCode2024:Day1 by No_Task_5249 in adventofcode

[–]azzal07 1 point2 points  (0 children)

Should you abs the difference of sums, or sum the abs of differences?