Task

Write a boolean function that tells whether a given integer is prime using Wilson's theorem.

By Wilson's theorem, a number p is prime if and only if p divides (p - 1)! + 1.

Remember that 1 and all non-positive integers are not prime.



See also

 Cut-the-knot: Wilson's theorem.
 Wikipedia: Wilson's theorem


 [ 1 swap times [ i 1+ * ] ] is !     ( n --> n )
 
 [ dup 2 < iff
     [ drop false ] done 
   dup 1 - ! 1+
   swap mod 0 = ]            is prime ( n --> b )
 
 say "Primes less than 500: "
 500 times 
   [ i^ prime if 
       [ i^ echo sp ] ]