Numbers with prime digits whose sum is 13: Difference between revisions

J
(→‎AWK: add faster alternative)
(J)
Line 805:
32233 32323 32332 33223 33232 33322 52222 222223 222232 222322
223222 232222 322222</pre>
 
=={{header|J}}==
 
Galloway's algorithm, from the talk page:
 
<syntaxhighlight lang=J>ps13=: {{
seq=. 0#,D=. ,Q=. ":,.p:i.4
while. #Q do.
N=. ,/D,"0 1/Q
i=. +/"1"."0 N
Q=. (12>i)#N
seq=. seq,,".(13=i)#N
end.
}}0</syntaxhighlight>
 
Here, upper case names are character arrays representing digits, lower case names are numeric arrays.
 
<code>Q</code> (number suffixes) and <code>N</code> (candidate numbers) represent sequences of sequences of characters. (The top level sequence -- rows -- distinguishes different potential numbers and the secondary sequence -- columns -- distinguishes digits within potential numbers).
 
Meanwhile, <code>D</code> (prime digits), <code>i</code> (digit sums) and <code>seq</code> (numbers whose digit sum is 13) are simple sequences.
 
<syntaxhighlight lang=J> ps13
337 355 373 535 553 733 2227 2272 2335 2353 2533 2722 3235 3253 3325 3352 3523 3532 5233 5323 5332 7222 22225 22252 22333 22522 23233 23323 23332 25222 32233 32323 32332 33223 33232 33322 52222 222223 222232 222322 223222 232222 322222</syntaxhighlight>
 
=={{header|Java}}==
6,962

edits