DEV Community

Discussion on: How do you calculate 3^3^3^3? (What algo / struct?)

Collapse
 
flyingcakes profile image
Snehit Sah • Edited

You could see this StackOverflow answer : math.stackexchange.com/a/176257

That being said, I suppose that 3^3^3^3 will use about 3639GB memory to store. (if I've got my maths right)

Edit: I certainly got my mathematics wrong I suppose :(

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

I tried, but not to the end, with exponentiation by squaring.

I stopped at

(3.2485963e+6846169)^3 == (3.4283664e+20538506)
Enter fullscreen mode Exit fullscreen mode

And I cached the file storing 6846170 + 20538507 digits, and it takes 27 MB

[0] % du -sh cache/k_cubed/* | sort -h | tail -n 1
27M     cache/k_cubed/32485...48187 (3.248e+6846169)
Enter fullscreen mode Exit fullscreen mode

BTW, the expected result is

12577936...00739387 (1.2577936e+3638334640024)
Enter fullscreen mode Exit fullscreen mode

I may get some of the first digits wrong, though.