QB64.org Forum

Active Forums => Programs => Topic started by: STxAxTIC on October 26, 2019, 05:26:57 am

Title: Math challenge: Evaluate 999^999 (and similar)
Post by: STxAxTIC on October 26, 2019, 05:26:57 am
Title says it all. Whoever writes the shortest code to evaluate the number 999^999 and state the result in scientific (power-of-10) notation wins.

(We don't need infinite precision here, I don't intend for anyone to reach for their nearest string math code, we can all do that.)
Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: Ashish on October 26, 2019, 08:06:29 am
I don't know how to do this.... Using Binomial, it will blow my computer. Then I saw scientific notation....
So, here it is - :D
Code: QB64: [Select]
  1. 'For evaulating 999^999.
  2. 'Code by Ashish for STxAxTIC
  3. 'It mention that "We don't need infinite precision."
  4. PRINT "999^999 = 1 * 10^"; _CEIL(999 * (LOG(999) / LOG(10.#))) - 1
  5.  
Is am the winner??
Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: STxAxTIC on October 26, 2019, 10:52:45 am
Ashish you are soooooooo close, I'm amazed.

The order of magnitude is right, but what about the leading coefficient? You can get more precise than 1.

Either way something tells me you're gonna win this...I was hoping to spark the creation of a new set of tools (along the lines of bplus's nCr function in an adjacent thread) that handles large numbers.
Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: bplus on October 26, 2019, 11:15:46 am
Hmm... I think this is about taking (1000 - 1) ^ 999 since we were just talking about Pascal's triangle and finding shorter ways to do the math... which reminded STxAxTIC of something.

The sum of coefficients in a row add to 2^row, does that help?

1000^999 * -1 ^ 0+ 1000^998 * -1^1 + 1000^997* -1^2 + 1000^996*-1^3..... + 1000^0*-1^999 so what is that?

 10^3^999 = 10 ^ 2997
-10^3^998 = 10 ^ 2994 have alternating + and - additions because -1 to even power is 1 and to odd is -1
(coefficients not even considered yet!)

Well there is a trick around here somewhere ;)
Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: bplus on October 26, 2019, 11:41:35 am
Also might consider (1000-1)^(1000-1)

And if Ashish was close with LOG stuff, we might consider Taylor Expansion of LOG.

Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: STxAxTIC on October 26, 2019, 11:44:26 am
I'll try to steer the ship a little - pretend I was asking about 456^789... A good solution works for any problem... can dispense with special triangles and magic numbers and all that.
Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: SMcNeill on October 26, 2019, 11:53:38 am
Code: QB64: [Select]
  1. SHELL _DONTWAIT “https://www.calculatorsoup.com/calculators/algebra/large-exponent-calculator.php?x=999&exponent=999&action=solve”

Do I win?  ;D
Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: STxAxTIC on October 26, 2019, 11:54:56 am
Lol, that line probably applies tens of thousands of lines of code. Let alone the browser...

I would have expected Luke to do something like this...
Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: bplus on October 26, 2019, 12:21:40 pm
I'll try to steer the ship a little - pretend I was asking about 456^789... A good solution works for any problem... can dispense with special triangles and magic numbers and all that.

Oh so this is NOT one of those trick questions that works for special numbers.

OK, I will dig up my binary method of doing power calcs and see if usable...
Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: jack on October 26, 2019, 03:25:20 pm
how about
Code: [Select]
dim x as double, m as double
dim e as integer

x=log(999)*999/log(10)

e=int(x)
m=10^(x-e)
print "999^999 = ";m;"e";e
Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: STxAxTIC on October 26, 2019, 03:47:48 pm
Perfect jack. Ashish almost had it but you did the whole thing.

Here's my write-up of why that works:
Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: SierraKen on October 26, 2019, 08:38:29 pm
Static, I don't know how this works, but awhile back I posted a program I found that can calculate Pi to as far as you want (or as far as you will let your computer work on it without heating it up). I did 100,000 decimals which took around 40 minutes or so. But if you want, you can check out the code, it's on the first post here:

https://www.qb64.org/forum/index.php?topic=1563.0
 (https://www.qb64.org/forum/index.php?topic=1563.0)
Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: luke on October 26, 2019, 08:57:04 pm
Lol, that line probably applies tens of thousands of lines of code. Let alone the browser...

I would have expected Luke to do something like this...
Nonsense, that method wouldn't work on Linux.

I'd have SHELLed out to bc instead.
Title: Re: Math challenge: Evaluate 999^999 (and similar)
Post by: Ashish on October 27, 2019, 01:31:59 am
Aahhh....
Congratulations Jack!