Primes whose sum of digits is 25: Difference between revisions
Content added Content deleted
(Add Tcl) |
m (→{{header|AppleScript}}: →Idiomatic: Digit-summing code to own handler. Tidied) |
||
Line 347: | Line 347: | ||
end repeat |
end repeat |
||
repeat with |
repeat with n from 2 to (limit ^ 0.5) div 1 |
||
if (item |
if (item n of o's numberList is n) then |
||
repeat with multiple from |
repeat with multiple from n * n to limit by n |
||
set item multiple of o's numberList to missing value |
set item multiple of o's numberList to missing value |
||
end repeat |
end repeat |
||
Line 357: | Line 357: | ||
return o's numberList's numbers |
return o's numberList's numbers |
||
end sieveOfEratosthenes |
end sieveOfEratosthenes |
||
on sumOfDigits(n) -- n assumed to be a positive decimal integer. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
set n to n div 10 |
|||
⚫ | |||
return sum |
|||
end sumOfDigits |
|||
on numbersWhoseDigitsSumTo(numList, targetSum) |
on numbersWhoseDigitsSumTo(numList, targetSum) |
||
Line 364: | Line 375: | ||
end script |
end script |
||
repeat with |
repeat with n in o's numberList |
||
if (sumOfDigits(n) = targetSum) then set end of o's output to n's contents |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if (digitSum = targetSum) then set end of o's output to thisNumber's contents |
|||
end repeat |
end repeat |
||
Line 378: | Line 383: | ||
-- Task code: |
-- Task code: |
||
return numbersWhoseDigitsSumTo(sieveOfEratosthenes(4999), 25)</lang> |
|||
set thoseWhoseDigitsSumTo25 to numbersWhoseDigitsSumTo(primesBelow5000, 25)</lang> |
|||
{{output}} |
{{output}} |