LdBeth · @ldbeth
133 followers · 724 posts · Server mastodon.sdf.org
Aaron Ash · @aaronash
49 followers · 248 posts · Server mastodon.sdf.org

I just noticed the "Best Seller" sticker on my second hand copy of Alan Holt's Network Performance Analysis Using the J programming language. 😂 I love it but somehow I doubt the sticker

#apljk #jlang

Last updated 2 years ago

Aaron Ash · @aaronash
44 followers · 179 posts · Server mastodon.sdf.org

Why J? (The programming language) code.jsoftware.com/wiki/Essays

#jlang #apljk

Last updated 3 years ago

Alex Strick van Linschoten · @strickvl
224 followers · 92 posts · Server mathstodon.xyz

Slowly building up my wall of primitives. Working through the J Primer to start off with.

#apljk #j

Last updated 3 years ago

Xavier (DuoSRX) · @xavier
60 followers · 18 posts · Server hachyderm.io

d←{⌊5÷⍨⍵+⍺}
g←{⍵=0:''⋄r←5|⍵⋄r=3:'=',∇2d⍵⋄r=4:'-',∇1d⍵⋄(⍕r),∇0d⍵}
⌽1↓g+/∊{((⊂'210-='⍳⌽⍵)⌷3-⍳5)×5*⍳⍴⍵}¨⊃⎕NGET'input'1

It's over. It's done. Whew!

Not exactly elegant but it works. I might revisit it a later time!

#adventofcode #apljk #apl #AdventOfCode2022

Last updated 3 years ago

Jan Stępień · @jstepien
203 followers · 97 posts · Server mastodon.social

/ Couldn't make it one this time, sorry

/ Read the jets
j:"><"?*0:"17.real"

/ 3 layers of air
a:((3,w:7)#0),

/ Define rock types
ts:({0 0,x,(-2+w-#:x)#0}(1_2\)@)''32\'31 10730 9519 101475 231

/ Check right and left for edges
cr:|/*|+:
cl:|/*+:

/ Push, accounting for collisions
p:{$[|//2=((#:n)# z)+n:{x_(x+#:y)# y}[((w!-1 1)*~(cr;cl)@\:x) y]'x;x;n]}

/ Try to drop one layer
d:{$[|//2=y+(h:#:y:p[y;z;x])#1_x;(y+h# x),h_x;x]}

/

#adventofcode #k #apljk #apl

Last updated 3 years ago

Jan Stępień · @jstepien
201 followers · 96 posts · Server mastodon.social

Anyone up for another AoC in K live coding stream later today? Today's problem looks fun. twitch.tv/janstepien

#apljk #apl #adventofcode #k

Last updated 3 years ago

Jan Stępień · @jstepien
197 followers · 95 posts · Server mastodon.social

/ ...of course there was a better way

f:"15.txt"
n:2000000
c:"-",,/$!10
i:{2 2#.`c$(" "*~i)+x*i:+/c=\:x}'0:f
a:{x|-x}
d:{+/a x-y}
r:{x@&&/(&/~0>+x;&/~(2*n)<+x)}
f:{$[:&&/x@\:+y;y i;!0]}[{{d[z;y]>x}[d .x;*x;]}'i;]
(x;y):2#,//(1 1;1 -1;-1 1;-1 -1){f r@+(*y)+x*(,p),,|p:!2+d. y}\:/:i
y+4000000*x

/ Instead of scanning every row,
/ scan only the diamonds'
/ edges

/ Now it's 10 times faster,
/ down to 25s

/ Still, there must be a better way

/

#i #adventofcode #k #apljk #apl

Last updated 3 years ago

Jan Stępień · @jstepien
192 followers · 94 posts · Server mastodon.social

f:"15.txt"
n:2000000
c:"-",,/$!10
i:{2 2#.`c$(" "*~i)+x*i:+/c=\:x}'0:f
a:{x|-x}
d:{+/a x-y}
m:{$[~~#:i:&x[0;1]>-2+1_x[;0]
(,x[0;0],|/x[0,1+*i;1]),x[(!#:x)^0,(1+*i)]
x]}
r:{cl:i@&{d[1_x;x[1],y]<1+*x}[;x]'(d.'i),'*+i;
r@<*+r:{x[1]+(-s)+0,2*s:x[0]-a y-x[2]}[;x]'(d.'cl),'*+cl}

--/*m/r[n]

x+4000000*1+*|*m/r[x:*&1<#'(m/r@)'!n*2]

/ Takes five minutes using
/ codeberg.org/ngn/k

/ There must be a better way

/

#k #apljk #apl #adventofcode #arrayprogramming

Last updated 3 years ago

Jan Stępień · @jstepien
190 followers · 93 posts · Server mastodon.social

i:(`j?'1_)'0N 3#(,""),l:0:"13.txt"
p:{y,((0&(#:y)-#:x)#-0w)}
s:{(x>0)-x<0}

/ A platter of assorted comparison functions
FF:{$[x~y;0;v@*&~0=v:s@-/(p[x;y];p[y;x])]}
Ff:{FF[x;,y]}
fF:{FF[,x;y]}
ff:-s@-/
AF:FA:AA:{$[x~y;0;0=#:y;-1;0=#:x;1;v:c(*x;*y);v;o[1_x;1_y]]}
Af:{AF[x;,y]}
fA:{FA[,x;y]}

/ “Parametric Polymorphism”
c:{(.,/$@'x).x}

+/&0,0<c'i

d:`j?'("[[2]]";"[[6]]")

*/1 2+{+/0<{c(x;y)}[;x]',/i}'d

/ Try out with codeberg.org/ngn/k
/

#k #apljk #apl #adventofcode

Last updated 3 years ago

Jan Stępień · @jstepien
190 followers · 92 posts · Server mastodon.social

i:{.'c@&~|/'">"=c:" "\x}'0:"14.txt"
h:2+|/*|+,/i
s:500
p:{(|/{x|-x}d:y-x)(((d>0)-d<0)+)\x}.
r:,/,/(p'2':)'i
f:{@[x;y[1];(y[0]=!#:*x)|]}
m:((h,2*s)# 0) f/r
c:{{v_((v:(n-y-1))+n:#:x)# x}[2 3 1,((-3+#*m)# 0);x]}

/ Keep simulating sand until we converge

t:{d:*&d=b:|/d:c[z]*~x[y+1];
$[~y<-1+#:x;l[x;y;z];~b;f[x;z,y];o[x;y+1;d]]}
a:{+//-m-t[;0;s]/m}

/ The last row behaviour is the only difference

l:{z;x}
a[]

l:{f[x;z,y]}
a[]

/

#k #apljk #apl #adventofcode #programming

Last updated 3 years ago

Jan Stępień · @jstepien
190 followers · 91 posts · Server mastodon.social

l:{p,x,p}'f,l,f:,(#*l:0:"12.txt")#p:"z"
m:`i$(-"a")+{@[@[x;&"E"=x;{"z"}];&"S"=x;{"a"}]}'l
g:{2>x[m]-m}
sh:{y_(y+)#x}
(s;n):{sh[;x]}'1,-1+
(e;w):{sh[;x]'}'1,-1+#*l
i:1000
nc:{cn/cw/cs/ce/x}

/ Part one, from S

c:{x&t+i*0=t:z@g[y]*x+1}
ce:c[;e;w]
cw:c[;w;e]
cs:c[;s;n]
cn:c[;n;s]

|//("E"=l)*nc/i*~"S"=l

/ Part two, backwards from E

c:{x&t+i*0=t:g[y]*y@x+1}
ce:c[;e]
cw:c[;w]
cs:c[;s]
cn:c[;n]

&//(i*~r)+(r:l="a")*nc/i*~"E"=l

/

#x #l #k #apljk #apl #adventofcode #programming

Last updated 3 years ago

Jan Stępień · @jstepien
190 followers · 90 posts · Server mastodon.social

/ read & parse
v:!#:i:0N 7#(,""),0:"11.txt"
s:(.18_)'i[;2]
n:19_'i[;3]
a:$*/.'d:(*|" "\)'i[;4]
t:|'(.*|)''i[;5 6]

/ simians → functions
sf:{."{[old](,w),,t[",($x),"]@~",(d x),"!w:",a,"!_(",n[x],")%rf}"}'v

/ turn, round, play
tr:{@[y;x;0#],'*'(t[0]@&)''(!#:y)=\:1_t:sf[x;y[x]]}
rn:{x{tr[y;x]}\!#:x}
pl:{*/t 2#>t:+/(m# v){y*x=v}'(m:(#:i)*x)##''h,,/(h:,s){y; rn@*|x}\!x}

/ relief factor and round no.
rf:3
pl 20

rf:1
pl 10000

/

#k #apljk #apl #adventofcode #arrayprogramming

Last updated 3 years ago

Jan Stępień · @jstepien
189 followers · 89 posts · Server mastodon.social

/ The screen size
(h;w):s:6 40

/ The cycles that matter
c:20+w*!h

/ This parses our input
p:{$[x[3]="x";(`I$5_x),0;,0]}

/ Parts one and two
+/c*(r:+\1,,/p'0:"10.txt")c-2
(`0:" #"(!w){3>d*d:y-x}')'s# 1,r;

/ How about another live solving stream this Monday?
/ twitch.tv/janstepien

/

#k #apljk #apl #adventofcode #arrayprogramming #programming

Last updated 3 years ago

Jan Stępień · @jstepien
189 followers · 89 posts · Server mastodon.social

/ The screen size
(h;w):s:6 40

/ The cycles that matter
c:20+w*!h

/ This parses our input
p:{$[x[3]="x";(`I$5_x),0;,0]}

/ Parts one and two
+/c*(r:+\1,,/p'0:"10.real")c-2
(`0:" #"(!w){3>d*d:y-x}')'s# 1,r;

/ How about another live solving stream this Monday?
/ twitch.tv/janstepien

/

#k #apljk #apl #adventofcode #arrayprogramming #programming

Last updated 3 years ago

Jan Stępień · @jstepien
187 followers · 87 posts · Server mastodon.social

i:`I$''0:"8.txt"

/ external view from left side
v:{1_|1_|+1_|2_|+(x,\:0)>(|\0,)'x}

/ count trees on the edges
e:4*-1+#:i

/ count trees visible from the left side
m:|~0=!-1+#:i
l:{1+(*&)'~((m&1_)'(*'x)>x)}

/ count trees visible to the right in the
/ entire forest
f:{+(|!#:x)&{l@(y_(y+s:#:x)#)'x}[x]'!#:x}

/ invoke x with all four rotations of y
a:{(4-y)(+|:)/ x y(+|:)/i}

e++//|/a[v;]'!4
|//*/a[f;]'!4

/

#k #apljk #apl #adventofcode #arrayprogramming #programming

Last updated 3 years ago

Jan Stępień · @jstepien
187 followers · 84 posts · Server mastodon.social

e:{(" "\x) y}
a:{(,x,(,"/"),*y),y}
c:{n:e[y;2];@[x;0;$[n~,"/";{,,"/"};n~"..";1_;a[n]]]}
d:l:{y; x}
s:{.e[y;0]; @[x;1;((`$'*x)!(#*x)#.e[y;0])+]}
f:{."clds"@*&("clr"=x[2]),1}
d:(!0;`!!0){(f y)[x;y]}/i:0:"7.real"
+/v@&~100000<v:.*|d
g:40000000
t@*<t:-:g-r+t@&0<t:(.m)+g-r:(m:*|d)@`"/"

/ Fold the input lines using a dynamic dispatch
/ and keeping the directory sizes in a dictionary.

/ The language is growing on me.

/

#k #apljk #apl #adventofcode #arrayprogramming #programming

Last updated 3 years ago

Xavier (DuoSRX) · @xavier
60 followers · 18 posts · Server hachyderm.io

This was a lot more straightfoward than day 5 :blobfoxdealwithit:

{1-⍨⍵+⍵⍳⍨≢¨⍵∪/⊃⊃⎕NGET'input'1}¨(4 14)

#adventofcode #apljk #apl #AdventOfCode2022

Last updated 3 years ago

Xavier (DuoSRX) · @xavier
56 followers · 11 posts · Server hachyderm.io

p←⊃⎕NGET'input'1
j←⊂{⊃' '(≠⊆⊢)⌽⍵}¨{4{⍵⌿⍨0=⍺|⍳≢⍵}(0 0,⍵)}↓⍉↑⌽8↑p
s←j,⍨⌽(⍎¨(⊂2 4 6)⌷' '(≠⊆⊢)⊣)¨10↓p
f←{c f t←⍺ ⋄ ((∊(g c↑⊃⍵[f]),⍵[t])(c↓⊃⍵[f])@t f)⍵}
g←⊢⋄⊃¨⊃f/s ⍝ Part 1
g←⌽⋄⊃¨⊃f/s ⍝ Part 2

This was trickier than I anticipated 😵

#adventofcode #apljk #apl #AdventOfCode2022

Last updated 3 years ago

Jan Stępień · @jstepien
183 followers · 81 posts · Server mastodon.social

{x+(*&x=(#=)'x':)'0:"6.txt"}'4 14

/ Run it with either
/ codeberg.org/ngn/k
/ or
/ johnearnest.github.io/ok/

/ Watch the stream recording at
/ twitch.tv/videos/1671764330

/

#k #apljk #apl #adventofcode #arrayprogramming

Last updated 3 years ago