Jump to content

Primes whose sum of digits is 25: Difference between revisions

m
→‎{{header|AppleScript}}: →‎Idiomatic: Digit-summing code to own handler. Tidied
(Add Tcl)
m (→‎{{header|AppleScript}}: →‎Idiomatic: Digit-summing code to own handler. Tidied)
Line 347:
end repeat
repeat with positionn from 2 to (limit ^ 0.5) div 1
if (item positionn of o's numberList is not missing valuen) then
repeat with multiple from positionn * positionn to limit by positionn
set item multiple of o's numberList to missing value
end repeat
Line 357:
return o's numberList's numbers
end sieveOfEratosthenes
 
on sumOfDigits(n) -- n assumed to be a positive decimal integer.
set digitSumsum to n mod 10
set n to n div 10
repeat until (n is= 0)
set digitSumsum to digitSumsum + n mod 10
set n to n div 10
end repeat
return sum
end sumOfDigits
 
on numbersWhoseDigitsSumTo(numList, targetSum)
Line 364 ⟶ 375:
end script
repeat with thisNumbern in o's numberList
setif (sumOfDigits(n) = targetSum) then set end of o's output to thisNumbern's contents
set digitSum to n mod 10
repeat until n is 0
set n to n div 10
set digitSum to digitSum + n mod 10
end repeat
if (digitSum = targetSum) then set end of o's output to thisNumber's contents
end repeat
Line 378 ⟶ 383:
 
-- Task code:
set primesBelow5000 toreturn numbersWhoseDigitsSumTo(sieveOfEratosthenes(4999), 25)</lang>
set thoseWhoseDigitsSumTo25 to numbersWhoseDigitsSumTo(primesBelow5000, 25)</lang>
 
{{output}}
557

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.