News for hackers. Stuff that matters.
Re:Can you solve it? The Greplin programming challenge by cperciva on Friday October 08, 2010 @05:32PM (#1773483)
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).
Re:Can you solve it? The Greplin programming challenge by Timothee on Friday October 08, 2010 @07:38PM (#1773863)
How 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.

Re:Can you solve it? The Greplin programming challenge by baddox on Friday October 08, 2010 @10:10PM (#1774139)
You 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). ;)
Re:Can you solve it? The Greplin programming challenge by Timothee on Friday October 08, 2010 @11:10PM (#1774226)
It 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.

Re:Can you solve it? The Greplin programming challenge by btilly on Friday October 08, 2010 @11:53PM (#1774306)
You 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.

Re:Can you solve it? The Greplin programming challenge by Timothee on Saturday October 09, 2010 @12:48AM (#1774358)
Fair enough. Though I'd argue on "entirely solvable by pencil and paper", since the answer is an educated guess in that case and the proof that it's correct resides in checking with the webpage. ;-)

To be honest, in the same amount of time, one could also estimate the range where the answer should be and plug it one by one in the form until it validates. (which we'll call a less educated guess :))

Re:Can you solve it? The Greplin programming challenge by btilly on Friday October 08, 2010 @05:55PM (#1773581)
I would think that pencil and paper would be slower than writing the programs. But you're right that they are ridiculously easy.
Re:Can you solve it? The Greplin programming challenge by cperciva on Friday October 08, 2010 @06:02PM (#1773603)
For the third problem, yes. But after solving the first two problems without writing code, I didn't feel like starting on the last problem.
Re:Can you solve it? The Greplin programming challenge by Natsu on Sunday October 10, 2010 @04:25PM (#1777865)
I 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.

Re:Can you solve it? The Greplin programming challenge by btilly on Monday October 11, 2010 @02:01AM (#1778954)
Here is a hint. Look at 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.

Re:Can you solve it? The Greplin programming challenge by cosgroveb on Friday October 08, 2010 @05:35PM (#1773495)
Ah. Well I'm an even worse hacker than I thought!
Re:Can you solve it? The Greplin programming challenge by bd on Friday October 08, 2010 @06:12PM (#1773633)
Don't feel bad, it's just how cperciva rolls :)

http://news.ycombinator.com/item?id=35083

Re:Can you solve it? The Greplin programming challenge by jackowayed on Friday October 08, 2010 @07:39PM (#1773866)
Wow, I strongly recommend reading this (or, better yet, the full back-and-forth leading up to it: http://news.ycombinator.com/item?id=35068 ).

I wish I had discovered HN back then.