Live data from Hacker News

Can you solve it? The Greplin programming challenge

challenge.greplin.com

101–110 of 167 posts

Re: Can you solve it? The Greplin programming challenge

#101
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.

Python here - very quick to code in if you have terminal handy.

Re: Can you solve it? The Greplin programming challenge

#102
post #25

"Even if you're not looking for a job, we'd love to hear what you thought about the challenge." I would be curious how many people did you lose because of phonecall requirement (before you changed it). Also CSV for just a list of 22 numbers wasn't really necessary. If you do web puzzle, the best is to keep everything self-contained, no downloads, no using external channels, just copy and paste. FYI another Python che…

I just copied the CSV into the text editor. But I just realized how stupid I was. I wrote

var nums = "3, 4, 9, 14, 15, 19, 28, 37, 47, 50, 54, 56, 59, 61, 70, 73, 78, 81, 92, 95, 97, 99".split(", ");

for(var i = 0;iInstead of just editing the numbers so that it was an array right away. Happens if you code before you think :-)

Re: Can you solve it? The Greplin programming challenge

#105
post #28

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 & use strict in there. 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…

brute force seems to be sufficient

Re: Can you solve it? The Greplin programming challenge

#106
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.

Edit: As others seem to be posting gist/snips etc. so I guess it is OK.

Step 0 - Copied parent string to file: p1.txt

Step 1 - Used python to reverse the entire string and copy to second file: cat p1.txt | python -c "print raw_input()[::-1]" > p2.txt

Step 2 - Formatted the two files, so as to be parsed as FASTA, by adding sequence name headers.

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.

So, in essence, a dynamic programming algo would work.

Re: Can you solve it? The Greplin programming challenge

#108
post #85

Too easy to solve by brute force. I'd suggest looking at Project Euler for inspiration.

I'm a little bored with Project Euler after solving the first 40+ problems with brute force or near-brute force algorithms. If I wasn't using it to learn a new language, I would have quit already. As it is, after solving one problem I usually quit for the day instead of moving on to the next. When do the problems pick up?

Re: Can you solve it? The Greplin programming challenge

#109
post #29
post #26

Earlier quoted context omitted.

I don't think trivializing the combinations with Python's builtins, looking up the fib primes with OEIS, or computing factors with Alpha is cheating. I hope, in fact, it's the whole point of the exercise: choose the right tools for the job. If you're writing code to test primeness or generate Fibonacci numbers, I sure as hell don't want to hire you.

Code to generate fibs is literally one line. Remember eigenvalues :)?

Sorry, couldn't help myself!! That approach is just so damn elegant.

int((1/math.sqrt(5))*(math.pow(((1+math.sqrt(5))/2),fibonacci)-math.pow(((1-math.sqrt(5))/2),fibonacci)))

Reference here: http://mathproofs.blogspot.com/2005/04/nth-term-of-fibonacci...

Re: Can you solve it? The Greplin programming challenge

#110
post #24

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! Fun, made my day. Good idea greplin dudes!

Not sure what you'd need the loads of memory for?

    int[] nums = {...}
    for i = 1 to (2^length(nums) - 1)
        int[] possibility = { nums[x] where (2^x bitand i) > 0 }
        test possibility and perhaps increment hit counter
Post reply on HN