Talk About Network

Google


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 > Re: Euler probl...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 4021 of 4136
Post > Topic >>

Re: Euler problem #20

by mhx@[EMAIL PROTECTED] (Marcel Hendrix) Apr 27, 2008 at 10:34 PM

William James <w_a_x_man@[EMAIL PROTECTED]
> writes Re: Euler problem #20
[..]
> Ruby:

> n = 1
> (2..100).each{|i|  n *= i }

> s = n.to_s
> puts s.reverse.gsub( /.../, '\&,' ).reverse

> sum = 0
> s.split('').each{|c| sum += c.to_i }
> puts sum

Thanks, I hadn't realized that printing the number and parsing
the text output was an obvious solution :-(

That is probably how they do the 2^1000 problem. Just use dc to 
print it to stdout.

-marcel
 




 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 Wed Jul 9 6:11:11 CDT 2008.