[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> Factorials



Hello,

Brian suggested to solve the factorials problem by using 3 nested FOR
loops, thus eliminating all 7-8-9 digits.

That was done in the procedure SOLVE:

==================================================
to main
compute_factorials
solve
end

to compute_factorials
make "fact_array(array 10 0)
setitem 0 :fact_array 1
for[i 1 9][
  setitem :i :fact_array :i*item :i-1 :fact_array]
end

to solve
for[a 1 6][
   for[b 0 6][
      for[c 0 6][
         make "num(word :a :b :c)
         if equalp :num sumup[pr :num]]]]
end

to sumup
op(sum item item 1 :num :fact_array
       item item 2 :num :fact_array
       item item 3 :num :fact_array)
end
==================================================

It runs very fast.

[[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