Primality by Wilson's theorem: Difference between revisions

Jakt
(Added XPL0 example.)
(Jakt)
Line 1,353:
2 3 5 7 11 13 17 19 23 29 31
</syntaxhighlight>
 
=={{header|Jakt}}==
<syntaxhighlight lang="jakt">
fn factorial_modulo<T>(anon n: T, modulus: T, accumulator: T = 1) throws -> T => match n {
(..0) => { throw Error::from_string_literal("Negative factorial") }
0 => accumulator
else => factorial_modulo(n - 1, modulus, accumulator: (accumulator * n) % modulus)
}
 
fn is_prime(anon p: i64) throws -> bool => match p {
(..1) => false
else => factorial_modulo(p - 1, modulus: p) + 1 == p
}
 
fn main() {
println("Primes under 100: ")
for i in (-100)..100 {
if is_prime(i) {
print("{} ", i)
}
}
println()
}
</syntaxhighlight>
{{out}}
<pre>
Primes under 100:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
</pre>
 
=={{header|Java}}==
89

edits