Primes which contain only one odd digit: Difference between revisions

Content added Content deleted
(Added Quackery.)
(→‎{{header|Quackery}}: made more efficient)
Line 897: Line 897:


<code>evendigits</code> returns the nth number which has only even digits and ends with zero. There are self-evidently 5^5 of them less than 1000000.
<code>evendigits</code> returns the nth number which has only even digits and ends with zero. There are self-evidently 5^5 of them less than 1000000.

We know that the only prime ending with a 5 is 5. So we can omit generating candidate numbers that end with a 5, and stuff the 5 into the right place in the nest (i.e. as item #1; item #0 will be 3) afterwards. This explains the lines <code>' [ 1 3 7 9 ] witheach</code> and <code>5 swap 1 stuff</code>.


<syntaxhighlight lang="Quackery"> [ [] swap
<syntaxhighlight lang="Quackery"> [ [] swap
Line 910: Line 912:
5 5 ** times
5 5 ** times
[ i^ evendigits
[ i^ evendigits
' [ 1 3 5 7 9 ] witheach
' [ 1 3 7 9 ] witheach
[ over +
[ over +
dup isprime iff
dup isprime iff
Line 916: Line 918:
else drop ]
else drop ]
drop ]
drop ]
5 swap 1 stuff
dup say "Qualifying primes < 1000:"
dup say "Qualifying primes < 1000:"
dup findwith [ 999 > ] [ ]
dup findwith [ 999 > ] [ ]