by Someone · 8y ago · 0 comments
Easily solvable if you set that limit low and cheat. Just put a string representation of pi in the program, and chop it off at the requested length:
n = Input “num digits?”
if n between 0 and 8 inclusive
print left(“3.1415927”, n+1)
else
print “number out of supported range”
If you don’t cheat or if ”Keep a limit to how far the program will go” doesn’t mean what I read in it, I have my doubts anyone can write that program, even with support from Google.[1] https://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%9...
def nthHexDigitOfPI(n):
return 4/(8*n+1) - 2/(8*n+4) - 1/(8*n+5) - 1/(8*n+6)Simon Plouffe did it, years ago, with no help from Google.
http://plouffe.fr/Simon%20Plouffe.htm
https://en.m.wikipedia.org/wiki/Bailey–Borwein–Plouffe_formu...
For the lay-programmer, e.g., “any person or people”, everything on that list is an exercise in learning how the problem was solved by someone else, and writing the code for it. The idea is to learn, not to invent the solution from scratch without help. The way to code the spigot algorithm for pi is to lookup the formula, understand it, figure out how to deal with precision and numeric base conversion, and write the code. Pretty much anyone can do that.
Where did I imply it? The site being discussed uses “anyone” in the sense “any person”. I questioned that, but didn’t realize that I used the word in the second meaning the second time I used it.
”The way to code the spigot algorithm for pi is to lookup the formula, understand it, figure out how to deal with precision and numeric base conversion, and write the code. Pretty much anyone can do that.”
That, we disagree about. We live in a world where “Fizz-Buzz” is a thing, so I’m not that optimistic that anybody can do what you describe.
P/(2*r) > Pi > P/(2*R)
Once you have approximated it, returning a string with the first x digits is trivial