4 ms·
IMHO Project Euler teaches bad programming by asking you to solve specific cases instead of general problems. I've found at least one problem where the straight
by extension 17y ago
IMHO Project Euler teaches bad programming by asking you to solve specific cases instead of general problems. I've found at least one problem where the straightforward correct answer failed in the general case, and the generic solution was significantly more complicated.
Edit: this one http://projecteuler.net/index.php?section=problems&id=13 http://projecteuler.net/index.php?section=problems&id=13
- btilly 17y agoI'm not sure what you mean by "straightforward correct answer". I just used a big integer library, calculated the answer, and then took the first 10 digits. That should work out fine in any reasonable general case that you're likely to be thinking of.
- extension 17y agoWhat I found in example solutions, and is indeed accepted by the site, is truncating each number to 10 digits and then summing. You can do this with just double-precision FP so it's likely to be the most common solution in languages that don't have bignums baked in.
- btilly 17y agoAh, right. There are also a number of problems where it is possible to narrow down the answer fairly easily, then submit a limited number of guesses until you get the right answer without having really shown that it is right. But they try to limit how easy that is to do.
- roundsquare 17y agoThere are also a number of problems where it is possible to narrow down the answer fairly easily, then submit a limited number of guesses until you get the right answer without having really shown that it is right. To some degree, they need to rely on the users to care enough not to "cheat." There is no way to completely avoid people doing things like this.
- eru 17y agoThe later problems get significantly more complicated, that you won't be able to cut corners.