News for hackers. Stuff that matters.
Re:A list of practical projects that anyone can solve in any... by Someone on Wednesday November 21, 2018 @03:18AM (#18501018)
Nice list, but ‘anyone’? The first on the list is ”Find PI to the Nth Digit - Enter a number and have the program generate PI up to that many decimal places. Keep a limit to how far the program will go”

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.
Re:A list of practical projects that anyone can solve in any... by computerphage on Wednesday November 21, 2018 @03:32AM (#18501077)
There are simple math formulas that approximate pi. You can look one up and run it to the right number of digits. It would be hard without Google, but most programmers should be able to do it with Google so that they don't need to figure out any of the math.
Re:A list of practical projects that anyone can solve in any... by leni536 on Wednesday November 21, 2018 @03:52AM (#18501148)
You need to use an arbitrary precision math library, I don't know how hard to use those. Those formulas have a hard limit in precision for standard floating point types.
Re:A list of practical projects that anyone can solve in any... by dhartmei on Wednesday November 21, 2018 @04:00AM (#18501193)
You don't need arbitrary precision, use a spigot https://en.wikipedia.org/wiki/Pi#Spigot_algorithms
Re:A list of practical projects that anyone can solve in any... by leni536 on Wednesday November 21, 2018 @05:15AM (#18501489)
I took a look at a spigot algorithm[1]. I still think it needs arbitrary precision arithmetics but maybe I miss something obvious.

[1] https://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%9...

Re:A list of practical projects that anyone can solve in any... by dhartmei on Wednesday November 21, 2018 @05:21AM (#18501508)
Here's an example if you want to try http://www.benzedrine.ch/pi-spigot.c
Re:A list of practical projects that anyone can solve in any... by leni536 on Wednesday November 21, 2018 @05:33AM (#18501565)
This doesn't look like a spigot algorithm. It has a link in the comments[1], it calculates the digits of PI from the beginning. The code you linked seems to implement the exact same algorithm.

I don't fully comprehend the code still, but the SCALE parameter suggest that it handles the elements of the array as a fixed point representation of real numbers. I wonder if it's correct for large number of digits.

[1] http://www.codecodex.com/wiki/Calculate_digits_of_pi#C

Re:A list of practical projects that anyone can solve in any... by ajuc on Wednesday November 21, 2018 @05:07AM (#18501452)
Wow, this blew my mind. And it's so simple, too.

    def nthHexDigitOfPI(n):
        return 4/(8*n+1) - 2/(8*n+4) - 1/(8*n+5) - 1/(8*n+6)
Re:A list of practical projects that anyone can solve in any... by leni536 on Wednesday November 21, 2018 @05:17AM (#18501492)
What you wrote just returns 0 for a large enough n.
Re:A list of practical projects that anyone can solve in any... by ajuc on Wednesday November 21, 2018 @05:40AM (#18501607)
Serves me right for stopping the reading on the first line :)
Re:A list of practical projects that anyone can solve in any... by dahart on Wednesday November 21, 2018 @10:25AM (#18503325)
> I have my doubts that anyone can write that program

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...

Re:A list of practical projects that anyone can solve in any... by Someone on Thursday November 22, 2018 @03:18AM (#18508621)
Sorry, didn’t realize that “anyone” switched meaning (from “any person or people” to “a person of importance or authority” (https://en.oxforddictionaries.com/definition/anyone)) between the two uses. My second use should have been quoted, too, because it refers to the “that anyone can solve” in the page’s title, which (at least in my reading) can only have the first meaning.
Re:A list of practical projects that anyone can solve in any... by dahart on Thursday November 22, 2018 @11:11AM (#18510777)
I’m not sure I understand what you mean. For me, your comment doesn’t hinge on the meaning of ‘anyone’ at all. You clearly implied the problem wasn’t solvable by any person, important or not, by saying “even with support from Google”. You implied you weren’t aware the solution was available with a Google search. But it was solved, first by Simon Plouffe, and then by others, so now you know.

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.

Re:A list of practical projects that anyone can solve in any... by Someone on Thursday November 22, 2018 @02:30PM (#18511994)
”You implied you weren’t aware the solution was available with a Google search. But it was solved, first by Simon Plouffe, and then by others, so now you know.”

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.

Re:A list of practical projects that anyone can solve in any... by dahart on Thursday November 22, 2018 @08:46PM (#18513804)
> Where did I imply it?

It seems weird you asked that since I just said where, explicitly. This part of the conversation feels tedious and unnecessary. The precise meaning of “anyone” being used by you & the article is pretty irrelevant.

> I’m not that optimistic that anybody can do what you describe.

You’re right, I disagree. I’m sorry for your pessimism. My children can and do lookup formulas on Wikipedia and code them, it’s not hard, if you care to try. I understand if you feel it is too difficult. FWIW, that’s precisely what the post we’re commenting on is aiming to help curious and optimistic people with. Maybe consider how it might be able to help your situation rather than criticize? Everyone can do fizzbuzz too, it’s existence doesn’t prove anything.

Re:A list of practical projects that anyone can solve in any... by montenegrohugo on Wednesday November 21, 2018 @04:28AM (#18501307)
Pi was already being approximated by Archimedes and Co. some time ago, I don't think its outside of the realm of possibility that a modern developer looks up following inequality and just approximates pi to some degree of accuracy with

  P/(2*r) > Pi > P/(2*R)
Once you have approximated it, returning a string with the first x digits is trivial
Re:A list of practical projects that anyone can solve in any... by c22 on Wednesday November 21, 2018 @03:34AM (#18501085)
If you accept only a finite n this seems easily doable. You just may have to wait awhile for execution to complete.
Re:A list of practical projects that anyone can solve in any... by garmaine on Wednesday November 21, 2018 @03:37AM (#18501090)
There are fast algorithms for calculating the Nth digit of pi.
Re:A list of practical projects that anyone can solve in any... by montenegrohugo on Wednesday November 21, 2018 @04:32AM (#18501316)
The entire 'fun' of this is implementing it with as much of your own code as possible. Using existing fast algorithms only leaves you with splitting the output to the nth digit, which is trivial and leaves you without having learned or achieved anything imo.
Re:A list of practical projects that anyone can solve in any... by garmaine on Wednesday November 21, 2018 @11:24AM (#18503774)
You can implement the algorithm yourself.
Re:A list of practical projects that anyone can solve in any... by blattimwind on Wednesday November 21, 2018 @04:32AM (#18501317)
Series for approximating Pi can be found in almost every formulary.