Anonymous user
Numbers with prime digits whose sum is 13: Difference between revisions
Numbers with prime digits whose sum is 13 (view source)
Revision as of 21:23, 6 June 2021
, 2 years ago→{{header|Nim}}
Line 948:
22225 22252 22333 22522 23233 23323 23332 25222 32233 32323 32332
33223 33232 33322 52222 222223 222232 222322 223222 232222 322222 </pre>
=={{header|Nim}}==
<lang Nim>import math, sequtils, strutils
type Digit = 0..9
proc toInt(s: seq[Digit]): int =
## Convert a sequence of digits to an integer.
for n in s:
result = 10 * result + n
const PrimeDigits = @[Digit 2, 3, 5, 7]
var list = PrimeDigits.mapIt(@[it]) # List of sequences of digits.
var result: seq[int]
while list.len != 0:
var nextList: seq[seq[Digit]] # List with one more digit.
for digitSeq in list:
let currSum = sum(digitSeq)
for n in PrimeDigits:
let newSum = currSum + n
let newDigitSeq = digitSeq & n
if newSum < 13: nextList.add newDigitSeq
elif newSum == 13: result.add newDigitSeq.toInt
else: break
list = move(nextList)
for i, n in result:
stdout.write ($n).align(6), if (i + 1) mod 9 == 0: '\n' else: ' '
echo()</lang>
{{out}}
<pre> 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 </pre>
=={{header|Pascal}}==
|