// // Show prime numbers using the Wilson theorem: https://en.wikipedia.org/wiki/Wilson%27s_theorem#Primality_tests // // Also using a recursive function for the loops // def loop(from number, to number, fn func (number) bool) { if from > to { return; } if !fn(from) { return; } return loop(from + 1, to, fn); } def wilsonPrime(n number) bool { var acc number = 1; def fact(i number) bool { acc = (acc * i) % n; return acc != 0; } loop(2, n - 1, fact); if acc == n - 1 { println(n, " is prime"); } return true; } loop(2, 100, wilsonPrime);