Share your repls and programming experiences

← Back to all posts
##### π in APL

@TheForArkLD recommended that I make a pi approximation in APL, so here it is! By the way, I don't know if I did it the way you are technically supposed to, but it works! APL has almost no available documentation online...

hotnewtop
RahulChoubey1 (184)

@AmazingMech2418 where can I find documentation?

AmazingMech2418 (1102)

@RahulChoubey1 I just looked up Wikipedia articles honestly. LOL!

theangryepicbanana (1701)

You could probably simplify this whole thing:

``((4÷(c×((c×(c+3))+2)))×s)``

to:

``((4÷c×(c×c+3)+2)×s)``

because I believe the APL evaluates from right to left (rather than left to right). It might even be able to be simplified further.

TheForArkLD (770)

Thanks :D
Really cool!
(Dyalog is our friends)

AmazingMech2418 (1102)

@TheForArkLD I don't think Repl.it uses Dyalog. Loops don't work. I had to use tail-end recursion.

AmazingMech2418 (1102)

@TheForArkLD Well, ngn doesn't support loops with the same syntax as Dyalog...

AmazingMech2418 (1102)

@TheForArkLD You have to use tail-end recursion though...

TheForArkLD (770)
``````n←0
max←10
func←{
⍝Do something
n←n+1
{n < max:func 1} 1
}
func 1``````
TheForArkLD (770)

@AmazingMech2418 I found symbol that recursion for function, lol

TheForArkLD (770)

good news

``4×+/((-1)*⍳n)÷((2×⍳n)+1)``