Hi,
Many years ago, using BASIC, we encountered the following problem:
Find all 3-digit numbers, that equal the sum of the factorials of their
digits.
In other words: We need all 3-digit numbers of the form ABC which
maintain: ABC=A!+B!+C!
I wanted to test UCBLogo to see how good it solves that problem.
Here's one possible solution:
========================================
to solve
for[num 100 999][
if equalp :num(sum fact item 1 :num
fact item 2 :num
fact item 3 :num)
[pr :num]]
end
to fact :n
op ifelse :n<2[1][:n*fact :n-1]
end
========================================
The above solution is quite fast: It took some 9 seconds on P-120.
Next week I'll get my new P-266 machine. How faster is it? We wait and
see.
Regards...
[[Yehuda]]
---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org. Mail
questions about the list administration to logofdn@gsn.org. To
unsubscribe send unsubscribe logo-l to majordomo@gsn.org.
Global SchoolNet Foundation -
Linking Kids Around the World!
Copyright GSN - All Rights Reserved
- Comments
& Questions
Visit GSN's
Global
Schoolhouse for more exciting learning resources!
Search our Site
-
Home