Primality by trial division: Difference between revisions

(Add SETL)
Line 3,042:
Below, we use an implied parameter (.i) on the .isPrime function.
 
<syntaxhighlight lang="langur">val .isPrime = f .i == 2 or .i > 2 and
.i > 2 and not any ffn(.x) .i div .x, pseries 2 .. .i ^/ 2
 
writeln filter .isPrime, series 100</syntaxhighlight>
Line 3,049:
=== Recursive ===
{{trans|Go}}
<syntaxhighlight lang="langur">val .isPrime = ffn(.i) {
val .n = abs(.i)
if .n <= 2: return .n == 2
 
val .chkdiv = ffn(.n, .i) {
if .i x* .i <= .n {
return .n ndiv .i and self(.n, .i+2)
}
890

edits