Numbers with prime digits whose sum is 13: Difference between revisions
Content added Content deleted
(→UNIX Shell: add) |
(→Tcl: add) |
||
Line 2,061: | Line 2,061: | ||
[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] |
[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> |
</pre> |
||
=={{header|Tcl}}== |
|||
<syntaxhighlight lang="tcl">set res {} |
|||
set src [list {} 13] |
|||
while {[llength $src]} { |
|||
set dst {} |
|||
foreach {n r} $src { |
|||
foreach d {2 3 5 7} { |
|||
if {$d > $r} break |
|||
if {$d == $r} { |
|||
lappend res "$n$d" |
|||
} else { |
|||
lappend dst "$n$d" [expr {$r - $d}] |
|||
} |
|||
} |
|||
} |
|||
lset src $dst |
|||
} |
|||
puts $res</syntaxhighlight> |
|||
{{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|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
<syntaxhighlight lang="sh">set -- |
<syntaxhighlight lang="sh">set -- '' 13 |
||
res='' |
|||
while [ $# -ne 0 ] |
while [ $# -ne 0 ] |
||
do |
do |
||
Line 2,072: | Line 2,093: | ||
if [ $d -eq $2 ] |
if [ $d -eq $2 ] |
||
then |
then |
||
res=$res${res:+ }$1$d |
|||
else |
else |
||
set -- "$@" |
set -- "$@" $1$d $(($2 - d)) |
||
fi |
fi |
||
done |
done |
||
shift 2 |
shift 2 |
||
done |
done |
||
echo $ |
echo "$res"</syntaxhighlight> |
||
{{out}} |
{{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> |
<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> |