Primality by trial division: Difference between revisions
→{{header|langur}}
Langurmonkey (talk | contribs) |
Langurmonkey (talk | contribs) |
||
Line 3,040:
following the Raku example, which states, "Integer $i is prime if it is greater than one and is divisible by none of 2, 3, up to the square root of $i" (plus an adjustment for the prime number 2)
val isPrime = fn(i) {
▲<syntaxhighlight lang="langur">val .isPrime = fn(.i) {
▲ .i == 2 or .i > 2 and
▲ not any fn(.x) { .i div .x }, pseries 2 .. .i ^/ 2
}
writeln filter
</syntaxhighlight>
=== Recursive ===
{{trans|Go}}
<syntaxhighlight lang="langur">
if n <= 2: return n == 2
val
if
return
}
return true
}
return
}
writeln filter
</syntaxhighlight>
{{out}}
|