Digit fifth powers: Difference between revisions

Content added Content deleted
m (→‎{{header|Ring}}: added realistic limits)
Line 54: Line 54:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<lang ring>? "working..."
see "working..." + nl

sumEnd = 0
sumEnd = 0
sumList = []
sumList = ""

limitStart = 1000
pow5 = []
limitEnd = 199999
for i = 1 to 9
add(pow5, pow(i, 5))
next

limitStart = 2
limitEnd = 6 * pow5[9]


for n = limitStart to limitEnd
for n = limitStart to limitEnd
sum = 0
sum = 0
nStr = string(n)
m = n
for m = 1 to len(nStr)
while m > 0
sum = sum + pow(number(nStr[m]),5)
d = m % 10
if d > 0 sum += pow5[d] ok
next
m = unsigned(m, 10, "/")
end
if sum = n
if sum = n
add(sumList,n)
sumList += "" + n + " + "
sumEnd += n
sumEnd += n
ok
ok
next
next

see "The sum of all the numbers that can be written as the sum of fifth powers of their digits:" + nl
? "The sum of all the numbers that can be written as the sum of fifth powers of their digits:"
for n = 1 to len(sumList)-1
? substr(sumList, 1, len(sumList) - 2) + "= " + sumEnd
? "done..."</lang>
see "" + sumList[n] + " + "
next
see "" + sumList[n] + " = " + sumEnd + nl
see "done..." + nl
</lang>
{{out}}
{{out}}
<pre>
<pre>