Numbers with prime digits whose sum is 13: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: used a better format for showing the output.) |
(Added solution for Action!) |
||
Line 2: | Line 2: | ||
Find all the positive integers whose decimal digits are all primes and sum to '''13'''. |
Find all the positive integers whose decimal digits are all primes and sum to '''13'''. |
||
<br><br> |
<br><br> |
||
=={{header|Action!}}== |
|||
<lang Action!>DEFINE PRIMECOUNT="4" |
|||
BYTE ARRAY primedigits(PRIMECOUNT)=[2 3 5 7] |
|||
PROC PrintNum(BYTE ARRAY code BYTE count) |
|||
BYTE i,c |
|||
FOR i=0 TO count-1 |
|||
DO |
|||
c=code(i) |
|||
Put(primedigits(c)+'0) |
|||
OD |
|||
RETURN |
|||
BYTE FUNC Sum(BYTE ARRAY code BYTE count) |
|||
BYTE i,res,c |
|||
res=0 |
|||
FOR i=0 TO count-1 |
|||
DO |
|||
c=code(i) |
|||
res==+primedigits(c) |
|||
OD |
|||
RETURN (res) |
|||
PROC Init(BYTE ARRAY code BYTE count) |
|||
Zero(code,count) |
|||
RETURN |
|||
BYTE FUNC Next(BYTE ARRAY code BYTE count) |
|||
INT pos,c |
|||
pos=count-1 |
|||
DO |
|||
c=code(pos)+1 |
|||
IF c<PRIMECOUNT THEN |
|||
code(pos)=c |
|||
RETURN (1) |
|||
FI |
|||
code(pos)=0 |
|||
pos==-1 |
|||
IF pos<0 THEN |
|||
RETURN (0) |
|||
FI |
|||
OD |
|||
RETURN (0) |
|||
PROC Main() |
|||
DEFINE MAXDIG="6" |
|||
BYTE ARRAY digits(MAXDIG) |
|||
BYTE count,pos |
|||
count=1 pos=0 |
|||
Init(count) |
|||
DO |
|||
IF Sum(digits,count)=13 THEN |
|||
IF pos+count>=38 THEN |
|||
pos=0 PutE() |
|||
FI |
|||
PrintNum(digits,count) Put(32) |
|||
pos==+count+1 |
|||
FI |
|||
IF Next(digits,count)=0 THEN |
|||
count==+1 |
|||
IF count>MAXDIG THEN |
|||
EXIT |
|||
FI |
|||
Init(count) |
|||
FI |
|||
OD |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Numbers_with_prime_digits_whose_sum_is_13.png Screenshot from Atari 8-bit computer] |
|||
<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|ALGOL 68}}== |
=={{header|ALGOL 68}}== |