Primes which contain only one odd digit: Difference between revisions

→‎{{header|Quackery}}: made more efficient
(Added Quackery.)
(→‎{{header|Quackery}}: made more efficient)
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.
 
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
Line 910 ⟶ 912:
5 5 ** times
[ i^ evendigits
' [ 1 3 5 7 9 ] witheach
[ over +
dup isprime iff
Line 916 ⟶ 918:
else drop ]
drop ]
5 swap 1 stuff
dup say "Qualifying primes < 1000:"
dup findwith [ 999 > ] [ ]
1,462

edits