Additive primes: Difference between revisions
Content added Content deleted
(add FreeBASIC) |
(Added AppleScript.) |
||
Line 75: | Line 75: | ||
<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 |
<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</pre> |
311 313 317 331 337 353 359 373 379 397 401 409 421 443 449 461 463 467 487</pre> |
||
=={{header|AppleScript}}== |
|||
<lang applescript>on sieveOfEratosthenes(limit) |
|||
script o |
|||
property numberList : {missing value} |
|||
end script |
|||
repeat with n from 2 to limit |
|||
set end of o's numberList to n |
|||
end repeat |
|||
repeat with position from 2 to (limit ^ 0.5) div 1 |
|||
if (item position of o's numberList is not missing value) then |
|||
repeat with multiple from position * position to limit by position |
|||
set item multiple of o's numberList to missing value |
|||
end repeat |
|||
end if |
|||
end repeat |
|||
return o's numberList's numbers |
|||
end sieveOfEratosthenes |
|||
on additivePrimes(limit) |
|||
script o |
|||
property primes : sieveOfEratosthenes(limit) |
|||
property additives : {} |
|||
end script |
|||
repeat with p in o's primes |
|||
set sum to p mod 10 |
|||
set n to p div 10 |
|||
repeat until (n = 0) |
|||
set sum to sum + n mod 10 |
|||
set n to n div 10 |
|||
end repeat |
|||
if (sum is in o's primes) then set end of o's additives to p's contents |
|||
end repeat |
|||
return o's additives |
|||
end additivePrimes |
|||
-- Task code: |
|||
tell additivePrimes(499) to return {additivePrimesBelow500:it, numberThereof:count}</lang> |
|||
{{output}} |
|||
<lang applescript>{additivePrimesBelow500:{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}, numberThereof:54}</lang> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<lang AWK> |
<lang AWK> |