I am trying to use the following computation: 232582656(232582657-1)
n = (232582656) * (232582657 - 1)
I am getting the msg:
perf.rb:5: warning: in a**b, b may be too big Infinity
Any help will be appreciated.
Thank you
Victor
I am trying to use the following computation: 232582656(232582657-1)
n = (232582656) * (232582657 - 1)
I am getting the msg:
perf.rb:5: warning: in a**b, b may be too big Infinity
Any help will be appreciated.
Thank you
Victor
You do realize the magnitude of number you’re trying to calculate? There
IS
a limit to how big even BigNum can go before deciding to crap out. I’d
like
to see someone try this in Lisp. If that interpreter can’t handle it,
then
no language can.
Jason
On Sat, May 05, 2007 at 02:10:58AM +0900, Victor R. wrote:
I am trying to use the following computation: 232582656(232582657-1)
n = (232582656) * (232582657 - 1)
Homework question? Brute force probably isn’t the way
Brian,
Actually, NO. This is not a homework questions. It is, however and
unfortunately, an issue of my deficiency and lack of knowledge of the
language.
For pure and simple intellectual curiosity, I am attempting to write a
ruby
pgm to find perfect numbers.
The largest perfect number found to this date, if I believe website
http://amicable.homepage.dk/perfect.htm is: (232582656) *
(232582657 -
1).
Been the neophyte that I am, I thought about picking it up from there
and
play with it, since I have at my disposal a very large IBM
multiprocessor
environment.
I know that Brute force is not the way, but I don’t have a nice
algorithm to
use.
Thank you
Victor
On May 4, 2007, at 10:36 AM, Jason R. wrote:
You do realize the magnitude of number you’re trying to calculate?
There IS
a limit to how big even BigNum can go before deciding to crap out.
I’d like
to see someone try this in Lisp. If that interpreter can’t handle
it, then
no language can.
Python 2.5 appears to have handled the expression easily enough (3-4
seconds on my iMac Intel Core Duo). Converting it to a string for
display seems to be taking quite a long time, which isn’t too
surprising since it should have nearly 2 million decimal digits
(according to log10(n)).
-Mark
For the record, I am running ruby 1.86 under AIX 5.3.
If the answer is that it can be done on Ruby, that’s an OK answer also.
If
this is the case, I start playing with Python, at least for this
problem.
Thanks
Victor
On Sat, May 05, 2007 at 04:34:01AM +0900, Victor R. wrote:
The largest perfect number found to this date, if I believe website
http://amicable.homepage.dk/perfect.htm is: (232582656) * (232582657 -
1).
Then that’s the number, represented in a compact form.
I know that Brute force is not the way, but I don’t have a nice algorithm to
use.
But what are you trying to achieve? Simply to display this number in its
direct decimal form?
If my rusty maths is correct, that number is a little under
2**(32582656 + 32582657)
which is roughly 10 ** ( (32582656 + 32582657) * log(2)/log(10) )
~= 10 ** 19616713
So there are nearly 20 million digits in the answer…
— Victor R. [email protected] wrote:
For the record, I am running ruby 1.86 under AIX
5.3.
If the answer is that it can be done on Ruby, that’s
an OK answer also. If
this is the case, I start playing with Python, at
least for this problem.Thanks
Victor
p 2048 ** 31819 - 1024 ** 31819
or
a = 1
32582656.times { a *= 2 }
b = a
32582656.times { b *= 2 }
p b - a
Todd, thank you for the example. I truly appreciate it. I’ll give it a
try.
Victor
I said:
p 2048 ** 31819 - 1024 ** 31819
Oops. Ignore this one. I don’t know what I was
thinking
— Todd B. [email protected] wrote:
— Victor R. [email protected] wrote:
Todd, thank you for the example. I truly
appreciate
it. I’ll give it a try.Don’t get too excited. On my system (2.4GHz Intel),
it looks like it would take about 2.5 hours to
compute
minute on my system:
a = 2 ** (2**10 * 9)
b = 1
3541.times { b*=a }
s = b.to_s
— Victor R. [email protected] wrote:
Todd, thank you for the example. I truly appreciate
it. I’ll give it a try.
Don’t get too excited. On my system (2.4GHz Intel),
it looks like it would take about 2.5 hours to compute
(I didn’t test it to see if it would even work).
Also, it is most likely faster to multiply by larger
numbers than 2.
232582656 == 416291328 == 168145664 ==
2564072832 == 65536**2036416 and so on
Broken down, it’s:
232582656 == 2(210 * 32 * 3541) ==
( (2**(210))) ** (32) ) ** 3541
I’m guessing now matter how you cut it up, you will
get the same error, though Maybe ruby chokes at
around a million digits.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs