Factorions: Difference between revisions

Content added Content deleted
m (Updated description and link for Fōrmulæ solution)
Line 1,079: Line 1,079:
<lang Ring>
<lang Ring>
load "stdlib.ring"
load "stdlib.ring"
see "working..." + nl


for n = 1 to 100000
for n = 3 to 100000
fac = 0
Digits = []
numStr = string(n)
sumFact = 0
for m = 1 to len(numStr)
strn = string(n)
num = number(numStr[m])
for m = 1 to len(strn)
fac = fac + factorial(num)
fact = factorial(number(strn[m]))
sumFact += fact
add(Digits,fact)
next
next
if n = fac
if sumFact = n
see "Factorion: " + n + nl
for ind = 1 to len(strn)-1
see "" + strn[ind] + "! + "
next
see "" + strn[ind] + "! = "
for p = 1 to len(Digits) - 1
see "" + Digits[p] + " + "
next
factLast = Digits[p]
see "" + factLast + " = " + n + nl
ok
ok
next
next

see "done..." + nl
</lang>
</lang>
<pre>
<pre>
working...
Factorion: 1
1! + 4! + 5! = 1 + 24 + 120 = 145
Factorion: 2
4! + 0! + 5! + 8! + 5! = 24 + 1 + 120 + 40320 + 120 = 40585
Factorion: 145
done...
Factorion: 40585
</pre>
</pre>

=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>
<lang ruby>