Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Euler problem #...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 4021 of 4053
Post > Topic >>

Euler problem #20

by mhx@[EMAIL PROTECTED] (Marcel Hendrix) Apr 27, 2008 at 07:24 AM

Apparently, there is a rather uncomplicated way of generating and printing 
very large numbers. The 20th Euler problem is supposed to be rather easy.

Of course most Forth will have bignum libraries, but it seems overkill
for this problem.

There is another one where they want the sum of digits of 2^1000. 

Ideas?

-marcel
-- ----------------------------------
	INCLUDE ../bignum/bignum.frt

(*
	( Collection at http://projecteuler.net/index.php?section=problems
)

	n! means n * (n - 1) * ... * 3 * 2 * 1

	Find the sum of the digits in the number 100!

	Example output:

	FORTH> euler20
	100! = 93,326,215,443,944,152,681,699,238,856,266,700,490,715,968,
	264,381,621,468,592,963,895,217,599,993,229,915,608,941,463,976,
	156,518,286,253,697,920,827,223,758,251,185,210,916,864,000,000,
	000,000,000,000,000,000
	The sum of the digits of the number 100! = 648
	0.002 seconds elapsed. ok
*)

MAX.DIGITS BIGNUM n!

: Euler20 ( -- ) 
	1 n! V!  #101 2 DO  n! I VS*  LOOP  
	CR ." 100! = " n! .Vnum
	CR ." The sum of the digits of the number 100! = " 
	0 BEGIN
	   n! #10 VS/MOD + 
	   n! VS0=
	  UNTIL 
	0 D. ;

: .ABOUT CR ." Euler20  -- Finds the sum of the digits in the number 100!"
;

	.ABOUT




 3 Posts in Topic:
Euler problem #20
mhx@[EMAIL PROTECTED] (M  2008-04-27 07:24:33 
Re: Euler problem #20
William James <w_a_x_m  2008-04-27 12:16:20 
Re: Euler problem #20
mhx@[EMAIL PROTECTED] (M  2008-04-27 22:34:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu May 15 0:57:43 CDT 2008.