January 20, 2022, 06:20:33 AM

## News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........

## Puzzlet #38

Started by GWS, March 28, 2014, 08:57:49 PM

0 Members and 1 Guest are viewing this topic.

#### GWS

##### March 28, 2014, 08:57:49 PM
Here's another maths puzzle by Dave Ellis from 2003 ..

This one is to find a 5-digit integer whose value is equal to the sum of the factorials
of its own digits.

`declare SumFactorials(s: int)declare Factorial (f: int)declare PrintResult()def flag, n, sumFact: intopenconsoleprint "Searching ...": printn = 10000flag = 0do sumFact = SumFactorials(n) if sumFact = n flag = 1 else n = n + 1 endifuntil flagPrintResult()print: print "Press any key to exit ..."do: until inkey\$ <> ""closeconsoleendsub SumFactorials(s)' returns the sum of the factorials of' the individual digits of sdef i, num, sum: intnum = ssum = 0for i = 1 to 5 sum = sum + Factorial(num % 10) num = int(num/10)next ireturn sumsub Factorial(f)' returns the factorial of fdef it, fact: intfact = 1for it = 1 to f fact = fact*itnext itreturn factsub PrintResult' pretty printerdef i, digit: intdef n\$: stringprint "Answer: ", n: printn\$ = str\$(n)for i = 2 to 6 digit = val(mid\$(n\$, i, 1)) print mid\$(n\$,i,1) + "! = ", print using ("########", Factorial(digit))next iprint: print "Sum: ",print using ("########", n)return`

Hope you find these little puzzles interesting ..

Graham
Tomorrow may be too late ..

#### LarryMc

##### March 28, 2014, 09:43:37 PM #1
nifty little brain teasers.
LarryMc
Larry McCaughn
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library