2 ms·
I didn't solve the problems using existing code either. All three are entirely solvable by pencil and paper (or just inspection in the first case).
by cperciva 16y ago
I didn't solve the problems using existing code either. All three are entirely solvable by pencil and paper (or just inspection in the first case).
- cosgroveb 16y agoAh. Well I'm an even worse hacker than I thought!
- bd 16y agoDon't feel bad, it's just how cperciva rolls :) http://news.ycombinator.com/item?id=35083 http://news.ycombinator.com/item?id=35083
- jackowayed 16y agoWow, I strongly recommend reading this (or, better yet, the full back-and-forth leading up to it: http://news.ycombinator.com/item?id=35068 http://news.ycombinator.com/item?id=35068 ). I wish I had discovered HN back then.
- btilly 16y agoI would think that pencil and paper would be slower than writing the programs. But you're right that they are ridiculously easy.
- cperciva 16y agoFor the third problem, yes. But after solving the first two problems without writing code, I didn't feel like starting on the last problem.
- Natsu 16y agoI seem to recall that there were 2^22 sets in the power set of that list of numbers, so you obviously had to use some kind of technique to cull the vast majority of the sets. Hmm... now that I think about it, did you do something like starting at the end of the list, then subtracting numbers as you went until you either found a set that added up to your top number, or found it impossible for that number to be in the set? It seems like it would take a lot of paper to do that, but it's more efficient than the simple brute force technique I did. I'm just curious, because I bet there are better ways to do that one and I think the challenge is probably over by now.
- btilly 16y agoHere is a hint. Look at http://en.wikipedia.org/wiki/Pascal%27s_triangle http://en.wikipedia.org/wiki/Pascal%27s_triangle and ask yourself why the 23nd row can be calculated without explicitly enumerating all possible subsets. I'm pretty sure that cperciva used a similar trick, but in each row you're potentially adding another element of the set, and not potentially adding 1. This gives you a mapping telling you how many ways there are to get 0, 1, 2, 3, etc as the sum of some subset of the set. Just sum this over the set, and subtract the size of the set. (Every element in the set is the sum of itself, but you don't want to count those.) And there is your answer.
- Timothee 16y agoHow do you go about solving #2 on pen and paper? Well, calculating the Fibonacci sequence, ok. The sum of prime divisors of X+1, I guess... though it gets slightly harder for me after dividing by 2, 3 and 5. But how do you know for sure that X is prime? Based on bd's link, I'll just assume that you have super powers. (or I'm approaching the problem the wrong way) edit: I was starting to think about what to write for #1, but ended finding the answer by looking at it as well.
- baddox 16y agoYou can use the Sieve of Eratosthenes to generate primes with pen and paper very easily. Or, you could find a roll of paper and evaluate any computable function (assuming unbounded paper). ;)
- Timothee 16y agoIt doesn't seem to make it especially easy: you still have the same problem of having to eliminate the multiples of 61, 79, 89, etc. which are not obvious. Yes, you can count, but it looks very time-consuming. The problem still stands that one needs to go in the 500,000s for that problem (thus 700s for the square root). That's still a long way to go… I'm really curious about how cperciva did it. You're supposed to find the first Fibonacci prime over 227,000. The first Fibonacci number over that is obviously not prime (multiple of 3), but the one after that is not obvious even if you have the list of primes obtained with that method.
- btilly 16y agoYou have less than 30 Fibbonacci numbers to compute. That 317811 is divisible by 3 is obvious upon adding its digits together. Once you've verified that 514229 isn't divisible by a handful of small primes, you don't try to prove primality. Instead factor 514230 and stick it in. After dividing by 2, 3, and 5, you've got 17141. It doesn't take that long to run through 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 and 61. At which point you have an answer you can try plugging in to discover it is correct. Which is a sequence cperciva pretty definitely has memorized. (I do.) Or alternately cperciva may have better factorization techniques memorized. If you already have a routine around for factoring (I do), then this takes longer than coding it. But I could do it with paper and pencil pretty easily.