# Write a Mathematica program to find the four known factorions

so i have come up with code that will find the four factorion numbers. I have a bunch of ideas of how it needs to be done theoretically but its still not quite clicking for me not too mention i am new to mathematica so the syntax is a bit confusing. So can anyone show me the proper code with brief explanations?

• Is this what you mean? oeis.org/A014080 – Amzoti Oct 20 '13 at 20:41
• Yeah that's what i mean. Wow what a good website too i bookmarked it i can definitely see this coming in handy thank you : ) – Achilles Oct 21 '13 at 13:17
• Did you see the Mathematica code that is on that page? – Amzoti Oct 21 '13 at 13:22
• yeah i saw it. Its more or less what Calle has said below. – Achilles Oct 21 '13 at 13:25

## 1 Answer

Actually, the numbers are so small we can do this very quickly by just testing for each combination below a certain threshold:

Reap[If[Total@Factorial[IntegerDigits[#]] == #, Sow@#] & /@ Range[50000]][[2]]


Which returns

{{1, 2, 145, 40585}}

• Yeah, that makes complete sense i don't know why i didn't think of that hahaha. Thanks a lot i appreciate i understand everything that's going on in the code to besides the "Reap" function you are using. I have never seen it before but i will look this function up in mathematica for further incite. I just hope that sooner or later i can start recognizing that there are alternate ways to solve a problem when i look at it. Thanks so much for the help its appreciated. I – Achilles Oct 21 '13 at 13:02
• What is the purpose of the 2 at the end ? – Achilles Oct 21 '13 at 21:24
• @Achilles Look up Part in the docuentation. Reap reurns a list; the first part is the result of the calculation as it would have been without Reap present. The second part is a list of valued that were "sown". – user3680 Oct 21 '13 at 21:49