TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Can you solve it? The Greplin programming challenge

220 pointsby rwalkerover 14 years ago

46 comments

shivenover 14 years ago
Seems like I may be the only person to have used a bioinformatics approach to the first problem! bl2seq to the rescue!! I'll explain my approach if anyone seems interested... as I am not sure if posting solutions is acceptable here.<p>Edit: As others seem to be posting gist/snips etc. so I guess it is OK.<p>Step 0 - Copied parent string to file: p1.txt<p>Step 1 - Used python to reverse the entire string and copy to second file: cat p1.txt | python -c "print raw_input()[::-1]" &#62; p2.txt<p>Step 2 - Formatted the two files, so as to be parsed as FASTA, by adding sequence name headers.<p>Step 3 - Use bl2seq (blastp) locally or online to align the two "sequences". Final alignment shows only one major chunk of identity, i.e. the answer.<p>So, in essence, a dynamic programming algo would work.
评论 #1775024 未加载
bdover 14 years ago
<i>"Even if you're not looking for a job, we'd love to hear what you thought about the challenge."</i><p>I would be curious how many people did you lose because of phonecall requirement (before you changed it).<p>Also CSV for just a list of 22 numbers wasn't really necessary.<p>If you do web puzzle, the best is to keep everything self-contained, no downloads, no using external channels, just copy and paste.<p>FYI another Python cheater here (+Wolfram Alpha &#38; Wikipedia, I'm lazy :).
评论 #1773962 未加载
评论 #1773164 未加载
csmajorfiveover 14 years ago
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.
评论 #1785281 未加载
cpercivaover 14 years ago
Do I get bonus marks for solving this without writing any code?
评论 #1773475 未加载
评论 #1774428 未加载
评论 #1774307 未加载
评论 #1773320 未加载
评论 #1773883 未加载
评论 #1774896 未加载
gmaster1440over 14 years ago
Nice and short Haskell solution to #3: <a href="http://gist.github.com/617675" rel="nofollow">http://gist.github.com/617675</a><p>Ruby solutions to #1 and #2: <a href="http://gist.github.com/617676" rel="nofollow">http://gist.github.com/617676</a> <a href="http://gist.github.com/617678" rel="nofollow">http://gist.github.com/617678</a>
评论 #1776846 未加载
grogersover 14 years ago
That was fun, good waste of time while my code was compiling. I just used C++ and hacked up a prime seive for #2 and for #3 used a combination generator I had previously used before - <a href="http://photon.poly.edu/~hbr/boost/combinations.html" rel="nofollow">http://photon.poly.edu/~hbr/boost/combinations.html</a>
评论 #1773504 未加载
neneover 14 years ago
I'm usually pretty bad at these kind of challenges (lately I tried registering at one mind-challenges site, but I couldn't even get past the five entry-level questions, which would have allowed me to even register), but this was surprisingly easy. Simple brute-force methods worked for each of the three tasks. I was totally surprised that the first time I entered the answer for each of the tasks, it was indeed the correct one.<p>But then again... these are all pretty standard computer science problems, nothing that I hadn't in some way done before.<p>On a side-note: Interestingly I used recursion for each of the three problems. Well... actually for the primes-problem I got stack overflow and rewrote it to not use recursion, but still, at least in principle :=)
评论 #1773487 未加载
jahover 14 years ago
Uh ... call a phone number? No thanks.<p>Edit: Excellent! Back to hacking.
评论 #1772828 未加载
评论 #1773230 未加载
评论 #1772783 未加载
评论 #1772810 未加载
评论 #1772791 未加载
jewbaccaover 14 years ago
Oh my god, Haskell is so pretty. This is the first time I've used it to solve math problems. Is it kosher to share solutions?
评论 #1773996 未加载
Natsuover 14 years ago
Damn, I have to go in to work early today or I could continue this. The first one only took a minute or two of coding to solve in Perl. The search string was several times longer than my code, even with use warnings &#38; use strict in there.<p>I'd write a bit of code to memoize the function before I'd do the Fibonacci numbers, though, and I just don't have time to continue right now, even though it's pretty easy. Are the rest of the tests like that? Do they force you to use more efficient code, rather than simpler brute force tests so that your code has a decent runtime?
评论 #1773972 未加载
1amzaveover 14 years ago
So what languages did everyone use?<p>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.
评论 #1773507 未加载
评论 #1773936 未加载
评论 #1773855 未加载
评论 #1773228 未加载
评论 #1773375 未加载
评论 #1773348 未加载
评论 #1792256 未加载
评论 #1774640 未加载
评论 #1774284 未加载
评论 #1775364 未加载
评论 #1773344 未加载
评论 #1774418 未加载
评论 #1773958 未加载
评论 #1774916 未加载
评论 #1775170 未加载
评论 #1777808 未加载
评论 #1773580 未加载
triangleman83over 14 years ago
Wow the G. Address was horribly mutilated.<p>Four score and seven years ago our <i>faathers</i> brought forth on this <i>containent</i> a new nation conceived <i>inz</i> Liberty and dedicated to the proposition that all men are created equal Now we are engaged in a <i>greaht</i> civil war testing whether that <i>naption</i> or any <i>nartion</i> so conceived and so dedicated can long endure We are <i>qmet</i> on a great <i>battlefiemld</i> of <i>tzhat</i> war
评论 #1773038 未加载
zmitriover 14 years ago
The last question isn't that difficult if you brute force it and have loads of memory. I tried to do it in python using itertools on my work thinclient and got a memoryerror. If you however break up your combinations.. you're good to go!<p>Fun, made my day. Good idea greplin dudes!
评论 #1774062 未加载
joe_the_userover 14 years ago
I've generally done well on job-interview programming challenges and gotten interviews afterwards. But looking on these quiz things, I'm still frustrated by them.<p>You see, all the "ordinary" question involved in job-fitting still have to be asked and answered so sometimes I've done great in ability part only to have really basic "culture" or requirements issue hit later when they could have been caught immediate.<p>And so, even though I've enjoyed and learned something on these quizzes, the employer who <i>begins</i> a relationship with a quiz seems to be saying they can demand some piece of my time without any investment on their part and this isn't setting a <i>tone</i> reciprocity, something I'd look for in a future employer.
lisperover 14 years ago
Too easy to solve by brute force. I'd suggest looking at Project Euler for inspiration.
评论 #1774004 未加载
评论 #1774620 未加载
tedcover 14 years ago
1-2 hours! Great...now my productivity will be shot for the day.
stelferover 14 years ago
Here's mine: <a href="http://gist.github.com/618459" rel="nofollow">http://gist.github.com/618459</a><p>I didn't see the point in doing this in anything but C. I tried it without cheating, and to make it as interesting to myself as possible. Also did it after a week of writing briefs, so that was a nice way to unwind from that! Pretty Fun.<p>Anyway, if I'm applying for a job (which I wasn't), the last thing I'm going to do is send in a bunch of one-liners.
tylrdotorgover 14 years ago
This really doesn't reflect a programmers skills in anyway. I managed to write ruby to solve the problems, but I approached it to do for fun. Brain teasers aren't going to weed out the good from bad.<p>Also, considering the instructions explicitly say "write code to..." I would say using tools that give you the answers is in fact cheating. It's like math test where you have to show your work.
maceover 14 years ago
IMHO, these contrived puzzles, while fun, are really unrealistic and don't map well to problems you'll encounter on the job which requires knowledge, experience and creativity and do not have just one answer.<p>Of all of the jobs-page challenges, thesixyone's is probably the most practical and I've seen:<p><a href="http://www.thesixtyone.com/static/jobs" rel="nofollow">http://www.thesixtyone.com/static/jobs</a>
koblasover 14 years ago
What about a puzzle system system -- Companies can post/host questions and then review the answers. I've drafted a quick blog post if anybody wants to comment more directly... Maybe I'll make it this weekends projects (since my frid.ge clone was killed by Facebooks new groups).<p><a href="http://bit.ly/b6GC6F" rel="nofollow">http://bit.ly/b6GC6F</a>
temugenover 14 years ago
Python powerset() with max(), list.remove(), and sum() builtins made the last problem's solution ~5 lines long :)
评论 #1773652 未加载
olalondeover 14 years ago
I thought the challenge was to solve everything with "grep" because of the "Greplin" title.
dasil003over 14 years ago
Here's better-than-brute-force solution to Q1 <a href="http://gist.github.com/617715" rel="nofollow">http://gist.github.com/617715</a><p>Is there a better algorithm? Dynamic programming of some sort? I guess we'd need a longer string to tell the difference.
评论 #1774290 未加载
btillyover 14 years ago
Took &#60; 10 minutes. The problems were very, very easy. If they expect people to take 1-2 hours and have trouble with this, then the message that I would take away from this is that their hiring bar is quite low.
评论 #1773940 未加载
g0over 14 years ago
<a href="http://codepad.org/rdSirAkD" rel="nofollow">http://codepad.org/rdSirAkD</a> -- Solution to third problem in 26 lines of ruby _without_ using combinations. It's pretty fast too, gives the answer in 0.020s.
sahillavingiaover 14 years ago
Any points for solving part 1 just scanning the text for something that stood out?<p>Seriously though, this is awesome. I'd love to know how you guys do in terms of # of applicants and the end-result (any hires?).
jiaaroover 14 years ago
solutions in python <a href="http://gist.github.com/617686" rel="nofollow">http://gist.github.com/617686</a><p>about 30 lines of code in the tersest style, 40ish in the readability-obsesssive style I prefer
评论 #1779257 未加载
评论 #1774800 未加载
_prototype_over 14 years ago
I did the naive implementation for problem 1. (double loop, O(n<i></i>2)), in Javascript. Took chrome about 1 minute to compute the comparisons of all strings. I'm so lazy.
lamnkover 14 years ago
Difficult level is about the same as Project Euler's problems 1x
siglesiasover 14 years ago
Anybody else browsing by mobile try to do Level 1 by inspection?
评论 #1772862 未加载
评论 #1773220 未加载
评论 #1772996 未加载
eqdwover 14 years ago
Um, no answer on the phone. I let it ring for over a minute.
评论 #1773383 未加载
riffraffover 14 years ago
damn it had a typo in the fib generation for the second number and lost a lot of time trying to factor a _massive_ number that was obviously the wrong one :)
badsquareover 14 years ago
numbers ="3,4,9,14,15,19,28,37,47,50,54,56,59,61,70,73,78,81,92,95,97].split() numbers = [int(i) for i in numbers]<p>def sum_eq(lst,k): total = sum(lst) if total == k or k==0:return 1 elif total &#60; k or len(lst)==1:return 0 else: n1,nr = lst[0],lst[1:] return sum_eq(nr,k-n1) + sum_eq(nr,k)<p>def sum_all_eq(lst): total = 0 for k in range(1,len(lst)): total += sum_eq(lst[0:k],lst[k]) return total
LordLandonover 14 years ago
My C is terribly rusty, so I decided to not cheat with python: <a href="http://sprunge.us/GiDD" rel="nofollow">http://sprunge.us/GiDD</a><p>How terrible is it?
bradlyover 14 years ago
Spoiler alert.<p>Here is my Part 1 implemented in Ruby. <a href="http://gist.github.com/617566" rel="nofollow">http://gist.github.com/617566</a>
ttaover 14 years ago
Anyone know other 'challenges' like this one?
zaiusover 14 years ago
My solutions, in ruby:<p><a href="http://gist.github.com/617672" rel="nofollow">http://gist.github.com/617672</a><p>Any improvements welcome!<p>(warning - contains the answers!)
hammerdrover 14 years ago
Anyone else read Q2 as (sum of the prime factors of X) + 1? Confused me for a good 10 minutes :(
orangecatover 14 years ago
Done, as usual with these things using Python feels like cheating.
评论 #1772931 未加载
rpbertp13over 14 years ago
35 mins, but in less than 40 lines of ruby
评论 #1773601 未加载
ajstilesover 14 years ago
30 minutes. Would have been less but the IVR response was a little confusing. Took about 40 lines Ruby code to solve.
dannover 14 years ago
what did you put as answer for the first level?
drozover 14 years ago
too easy. about 30mins and 100 lines of C#.
Muzzaover 14 years ago
There are only 31 known Fibonacci primes (plus a handful probable primes)...
hackermomover 14 years ago
Problem 1: 2 minutes for 5 lines of PHP code. Problem 2: 1 minute of Google and Google (why reinvent the wheel?). Problem 3: half a minute of brainwork, 15 minutes worth of tedious PHP snippet.<p>I got the impression that this particular test was not a good one for finding apt programmers. The questions and the solutions were just so very "off".
odyover 14 years ago
suckers ... no really, you are.