Primality by Wilson's theorem: Difference between revisions
Content added Content deleted
Catskill549 (talk | contribs) (added AWK) |
Not a robot (talk | contribs) (Add CLU) |
||
Line 594: | Line 594: | ||
7919 7927 7933 7937 7949 7951 7963 7993 8009 8011 8017 8039 8053 8059 8069 8081 |
7919 7927 7933 7937 7949 7951 7963 7993 8009 8011 8017 8039 8053 8059 8069 8081 |
||
</pre> |
</pre> |
||
=={{header|CLU}}== |
|||
<lang clu>% Wilson primality test |
|||
wilson = proc (n: int) returns (bool) |
|||
if n<2 then return (false) end |
|||
fac_mod: int := 1 |
|||
for i: int in int$from_to(2, n-1) do |
|||
fac_mod := fac_mod * i // n |
|||
end |
|||
return (fac_mod + 1 = n) |
|||
end wilson |
|||
% Print primes up to 100 using Wilson's theorem |
|||
start_up = proc () |
|||
po: stream := stream$primary_output() |
|||
for i: int in int$from_to(1, 100) do |
|||
if wilson(i) then |
|||
stream$puts(po, int$unparse(i) || " ") |
|||
end |
|||
end |
|||
stream$putl(po, "") |
|||
end start_up </lang> |
|||
{{out}} |
|||
<pre>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|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
Line 622: | Line 646: | ||
17 |
17 |
||
19 </pre> |
19 </pre> |
||
=={{header|Cowgol}}== |
=={{header|Cowgol}}== |