Live data from Hacker News

Can you solve it? The Greplin programming challenge

challenge.greplin.com

161–167 of 167 posts

Re: Can you solve it? The Greplin programming challenge

#161
post #81

solutions in python http://gist.github.com/617686 about 30 lines of code in the tersest style, 40ish in the readability-obsesssive style I prefer

I see that you did brute force primality testing, too. Am I the only one who at least only divided by odd numbers (and two) in their brute-force is_prime function? Technically, you only need to test divide by all primes less than or equal to sqrt(n), after all.

I guess I could have used a faster primality test, but I didn't feel like writing anything that complex. I know there's a website out there that has a test that works for anything under about 10 billion, if memory serves, by using the probabalistic tests and doing a special check for the only exception. Heck, it even gives you the factors for the largest number in its range...

Re: Can you solve it? The Greplin programming challenge

#162
post #76

Earlier quoted context omitted.

Clojure here.

Mind posting your solution as a Gist? I want to see how to do level 1 without explicit loops or variables.

Sure, sorry about the delay.

http://gist.github.com/621130

I can't take credit for the solution I posted though.

I originally wrote a naive O(N^2) complexity solution (which was much shorter and was fine for the length of the input) I had this palindrome code in my 'toolbox' of code I've come across though, I'm afraid I don't know the orig author.

I just tweaked it as this is more in line with the type of example you're looking for.

Re: Can you solve it? The Greplin programming challenge

#164

I think this would've been a better filter for hiring if the magnitude were larger (e.g. huge string, more numbers for the combination, etc) or if there was a strict time limit. As it is right now, I don't think the hardcore hackers you're looking for will be that enticed.

I think that you'd be surprised at the sheer number of applicants a very basic programming challenge can weed out. The company that I work at has a simple test to parse a csv file and a surprising amount of people who appear to be good candidates bomb it.

Re: Can you solve it? The Greplin programming challenge

#165
post #23

So what languages did everyone use? I decided to try a different one on each level, so I used Python, bash (letting GNU coreutils 'factor' do the hard work), and Haskell, respectively.

I know I'm late to the party, :) I used Ruby 1.9.2. It's funny that it's the first time I used the combination generation method built in Ruby Array. The whole three questions took me about a bit more than 20 minutes, a bit longer than I thought tho.

Re: Can you solve it? The Greplin programming challenge

#166
post #161
post #81

solutions in python http://gist.github.com/617686 about 30 lines of code in the tersest style, 40ish in the readability-obsesssive style I prefer

I see that you did brute force primality testing, too. Am I the only one who at least only divided by odd numbers (and two) in their brute-force is_prime function? Technically, you only need to test divide by all primes less than or equal to sqrt(n), after all. I guess I could have used a faster primality test, but I didn't feel like writing anything that complex. I know there's a website out there that has a test th…

this code solved the problem in under 1 second.

I would say for code that is executed one time ever, even including the sqrt(n) part is premature optimization (though I did include it)

Re: Can you solve it? The Greplin programming challenge

#167
post #76

Earlier quoted context omitted.

Mind posting your solution as a Gist? I want to see how to do level 1 without explicit loops or variables.

Sure, sorry about the delay. http://gist.github.com/621130 I can't take credit for the solution I posted though. I originally wrote a naive O(N^2) complexity solution (which was much shorter and was fine for the length of the input) I had this palindrome code in my 'toolbox' of code I've come across though, I'm afraid I don't know the orig author. I just tweaked it as this is more in line with the type of example you…

Interesting, I'll have to go over your code fairly carefully, as I'm not familiar with every technique you're using here for performance.

I've since learned a good deal about Clojure and implemented an idiomatic (but probably less performant) version, for anyone interested in how short this can be:

http://gist.github.com/635674

Post reply on HN