Digit fifth powers: Difference between revisions
Content added Content deleted
(Added AppleScript.) |
|||
Line 297: | Line 297: | ||
{{out}} |
{{out}} |
||
<pre>443839</pre> |
<pre>443839</pre> |
||
=={{header|AppleScript}}== |
|||
<syntaxhighlight lang="applescript">on join(lst, delim) |
|||
set astid to AppleScript's text item delimiters |
|||
set AppleScript's text item delimiters to delim |
|||
set txt to lst as text |
|||
set AppleScript's text item delimiters to astid |
|||
return txt |
|||
end join |
|||
on digit5thPowers() |
|||
set sums to {} |
|||
set total to 0 |
|||
repeat with n from 2 to 6 * (9 ^ 5) |
|||
set temp to n |
|||
set sum to 0 |
|||
repeat until temp = 0 |
|||
set sum to sum + (temp mod 10) ^ 5 |
|||
set temp to temp div 10 |
|||
end repeat |
|||
if (sum = n) then |
|||
set end of sums to n |
|||
set total to total + n |
|||
end if |
|||
end repeat |
|||
return join(sums, " + ") & " = " & total |
|||
end digit5thPowers |
|||
digit5thPowers()</syntaxhighlight> |
|||
{{output}} |
|||
<syntaxhighlight lang="applescript">"4150 + 4151 + 54748 + 92727 + 93084 + 194979 = 443839"</syntaxhighlight> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang="awk"> |
<syntaxhighlight lang="awk"> |