-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial II: Simple programs
Conor O'Brien edited this page Mar 17, 2017
·
1 revision
This page is meant to get used to the language itself. I provide here various programs and functions, along with their python equivalents.
(Python)
print("Hello, World!")(Stacked)
'Hello, World!' out
Checks if a ≡ b (mod c).
(Python)
modequiv = lambda a, b, c: a % c == b % c(Stacked)
{ a b c : (a b) c mod ... = } @:modequiv
This is a 3-arg function. It pairs a and b, implicitly maps with c mod, merges it to the stack with ..., then checks for equality with =.
Wilson's theorem: (Python)
import math
Wilson = lambda n: math.factorial(n - 1) % n == (n - 1) and n > 1(Stacked)
{! n 1-! _1 n modequiv n 1 > and } @:wilson
This is an n-lambda that uses Wilson's theorem, that (n - 1)! ≡ -1 (mod n) ⇔ n is prime.
Trial division via recursion: (Python)
todo
(Stacked)
{ x :
{ e i :
(e i) out
[ 1 ]
[
[e i 1 + tdrec] [0] e i % 0 != ifelse
] i e sqrt > ifelse
} @:tdrec
[0] [x 2 tdrec] x 1 < ifelse
} @:tdprime