AKS test for primes: Difference between revisions
Content added Content deleted
Recombinant (talk | contribs) m (→{{header|Zig}}: fix (stdout not comptime on every platform)) |
(Added Quackery.) |
||
Line 4,448: | Line 4,448: | ||
|- |
|- |
||
|} |
|} |
||
=={{header|Quackery}}== |
|||
<syntaxhighlight lang="Quackery"> [ dup 0 peek swap |
|||
[] 0 rot 0 join |
|||
witheach |
|||
[ abs tuck + |
|||
rot join swap ] |
|||
drop |
|||
[] swap witheach |
|||
[ rot negate |
|||
dup dip unrot |
|||
* join ] |
|||
nip ] is nextcoeffs ( [ --> [ ) |
|||
[ ' [ 1 ] swap |
|||
times nextcoeffs ] is coeffs ( n --> [ ) |
|||
[ dup 2 < iff |
|||
[ drop false ] |
|||
done |
|||
true swap |
|||
dup coeffs |
|||
behead drop |
|||
-1 split drop |
|||
witheach |
|||
[ over mod |
|||
0 != if |
|||
[ dip not |
|||
conclude ] ] |
|||
drop ] is prime ( n --> b ) |
|||
[ behead |
|||
0 < iff |
|||
[ say "-" ] |
|||
else sp |
|||
dup size |
|||
dup 0 = iff |
|||
[ 1 echo 2drop ] |
|||
done |
|||
say "x" |
|||
dup 1 = iff |
|||
[ 2drop |
|||
say " + 1" ] |
|||
done |
|||
say "^" |
|||
echo |
|||
witheach |
|||
[ dup 0 < iff |
|||
[ say " - " ] |
|||
else |
|||
[ say " + " ] |
|||
abs echo |
|||
i 0 = if done |
|||
say "x" |
|||
i 1 = if done |
|||
say "^" |
|||
i echo ] ] is echocoeffs ( [ --> ) |
|||
8 times |
|||
[ i^ echo |
|||
say ": " |
|||
i^ coeffs |
|||
echocoeffs |
|||
cr ] |
|||
cr |
|||
50 times |
|||
[ i^ prime if |
|||
[ i^ echo sp ] ]</syntaxhighlight> |
|||
{{out}} |
|||
<pre>0: 1 |
|||
1: -x + 1 |
|||
2: x^2 - 2x + 1 |
|||
3: -x^3 + 3x^2 - 3x + 1 |
|||
4: x^4 - 4x^3 + 6x^2 - 4x + 1 |
|||
5: -x^5 + 5x^4 - 10x^3 + 10x^2 - 5x + 1 |
|||
6: x^6 - 6x^5 + 15x^4 - 20x^3 + 15x^2 - 6x + 1 |
|||
7: -x^7 + 7x^6 - 21x^5 + 35x^4 - 35x^3 + 21x^2 - 7x + 1 |
|||
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 </pre> |
|||
=={{header|R}}== |
=={{header|R}}== |