Primality by Wilson's theorem: Difference between revisions

Add Scala implementation
(Add Dart implementation)
(Add Scala implementation)
Line 2,549:
7919 7927 7933 7937 7949 7951 7963 7993 8009 8011 8017 8039 8053 8059 8069 8081
</pre>
 
=={{header|Scala}}==
{{trans|Java}}
<syntaxhighlight lang="Scala">
import scala.math.BigInt
 
object PrimalityByWilsonsTheorem extends App {
println("Primes less than 100 testing by Wilson's Theorem")
(0 to 100).foreach(i => if (isPrime(i)) print(s"$i "))
 
private def isPrime(p: Long): Boolean = {
if (p <= 1) return false
(fact(p - 1).+(BigInt(1))).mod(BigInt(p)) == BigInt(0)
}
 
private def fact(n: Long): BigInt = {
(2 to n.toInt).foldLeft(BigInt(1))((fact, i) => fact * BigInt(i))
}
}
</syntaxhighlight>
{{out}}
<pre>
Primes less than 100 testing by Wilson's Theorem
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|Sidef}}==
337

edits