Additive primes: Difference between revisions

Added Action!
(Additive primes in Dart)
(Added Action!)
Line 260:
Number found : 54
</pre>
=={{header|Action!}}==
<syntaxhighlight lang="action!">
;;; find some additive primes - primes whose digit sum is also prime
;;; Library: Action! Sieve of Eratosthenes
INCLUDE "H6:SIEVE.ACT"
 
PROC Main()
DEFINE MAX_PRIME = "500"
 
BYTE ARRAY primes(MAX_PRIME)
CARD n, digitSum, v, count
Sieve(primes,MAX_PRIME)
 
count = 0
FOR n = 1 TO MAX_PRIME - 1 DO
IF primes( n ) THEN
digitSum = 0
v = n
WHILE v > 0 DO
digitSum ==+ v MOD 10
v ==/ 10
OD
IF primes( digitSum ) THEN
; the digit sum is prime
IF n < 100 THEN
Put(' )
IF n < 10 THEN Put(' ) FI
FI
Put(' )PrintI( n )
count ==+ 1
IF count MOD 20 = 0 THEN PutE() FI
FI
FI
OD
PutE()Print( "Found " )PrintI( count )Print( " additive primes below " )PrintI( MAX_PRIME + 1 )PutE()
RETURN
</syntaxhighlight>
{{out}}
<pre>
2 3 5 7 11 23 29 41 43 47 61 67 83 89 101 113 131 137 139 151
157 173 179 191 193 197 199 223 227 229 241 263 269 281 283 311 313 317 331 337
353 359 373 379 397 401 409 421 443 449 461 463 467 487
Found 54 additive primes below 501
</pre>
 
=={{header|Ada}}==
<syntaxhighlight lang="ada">with Ada.Text_Io;
3,028

edits