11
3
Pi times e (or Pie if you like ambiguous notation) to 100 decimal places is:
8.5397342226735670654635508695465744950348885357651149618796011301792286111573308075725638697104739439...
(OIES A019609) (argument for possible irrationality)
Your task is to write a program that takes in a positive integer N, and outputs Pi*e truncated to N decimal places. e.g. if N = 2, then the output should be 8.53
.
This is an optimization problem, so the submission that can give the correct output for the highest value of N will win.
To ensure all submissions are judged using the same computing power, your code must be run on ideone, using any language they support. According to the ideone faq, there is a 5 second run time limit for not logged in users. This 5 second limit is the one you must use, not the 15 second limit for logged in users. (See faq for other limits like memory, code size, etc.)
Specifically, anyone not logged into ideone should be able to run your program on ideone for all values of N from 1 to some maximum Nmax, and see correct output nearly all of the time. without any Time limit exceeded
or Memory limit exceeded
, etc. errors. The submission with the largest Nmax wins.
(Whether the actual time taken is a smidge over 5 seconds doesn't matter as long as ideone doesn't give errors. "Nearly all of the time" is defined as more than 95% of the time for any particular N.)
Details
- You may use any mathematical method you like to calculate Pi*e, but you may not hardcode the output beyond the first dozen digits of Pi, e or Pi*e.
- Your program should be able to work for any N, given unlimited resources.
- You may use built in Pi or e constants if your language happens to have them.
- You may not access websites or resources external to your code (if ideone even allows this).
- Beyond hardcoding and accessing external resources, anything that ideone allows is almost certainly fine.
- Your input and output must (obviously) work with whatever ideone provides for i/o (stdin/stdout only it seems). It's fine if you need quotes around the input N or the output is something like
ans = ...
, etc. - Please include a link to an ideone snippet of your code with your Nmax as input.
- If there happens to be a tie (only likely if multiple submissions hit the 64kB output character limit) the highest votes answer wins.
3Mmm... ambiguous pie. – Dennis – 2014-09-23T04:16:00.630
This can very easily be a code-golf and would rather be more fun if it is. – Optimizer – 2014-09-23T06:53:25.513
2@Optimizer It could be code-golf but then it would be pretty much like every other digit generation code-golf. I wanted to try a time based contest that could be verified online. (Though a more computationally complex problem might have been better.) – Calvin's Hobbies – 2014-09-23T07:07:17.943
if this is code golf APL would probably win (minus the arbitrary precision part) – TwiNight – 2014-09-23T07:24:30.490
Just to make sure, you want truncated to N d.p. not rounded to N d.p.? – TwiNight – 2014-09-23T07:30:49.830
@TwiNight Yes, that's why I said truncated. – Calvin's Hobbies – 2014-09-23T07:38:34.533
@TwiNight Or Mathematica:
N[Pi*E,n]
– Martin Ender – 2014-09-23T10:18:41.9001I suspect that these programs will be entirely IO bound trying to write out the digits to stdout. Five seconds is a long time to something like y-cruncher. – Will – 2014-09-23T13:43:43.083
The restriction for ideone and allowing constants but not hardcoding both make this challenge not so good IMO, -1 – Timtech – 2014-09-23T21:29:12.827
I've done some exploring. Because ideone's Python doesn't have gmpy2, Python is at a shocking disadvantage. A Python recipe to compute pi can do 8000 digits in 5 seconds on my laptop, and 3000000 digits if the python code uses gmpy2. This is an exercise in implementing arbitrary precision math efficiently, and not much more. – Will – 2014-09-25T17:10:46.993
@Will Mind sharing that recipe? The best I've got barely manages 1000000 in 5s.
– primo – 2014-09-26T05:41:57.710