Author Topic: Math challenge: Evaluate 999^999 (and similar)  (Read 5113 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Math challenge: Evaluate 999^999 (and similar)
« 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.)
« Last Edit: October 26, 2019, 05:47:53 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #1 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??
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #2 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.
« Last Edit: October 26, 2019, 11:03:42 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #3 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 ;)
« Last Edit: October 26, 2019, 11:18:02 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #4 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.


Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #5 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.
You're not done when it works, you're done when it's right.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #6 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
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #7 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...
« Last Edit: October 26, 2019, 11:56:00 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #8 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...

Marked as best answer by STxAxTIC on October 26, 2019, 11:49:45 am

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #9 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

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #10 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:
9996999.png
* 9996999.png (Filesize: 69.47 KB, Dimensions: 612x657, Views: 186)
You're not done when it works, you're done when it's right.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #11 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

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #12 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.

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Math challenge: Evaluate 999^999 (and similar)
« Reply #13 on: October 27, 2019, 01:31:59 am »
Aahhh....
Congratulations Jack!
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials