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.
Can you solve it? The Greplin programming challenge
101–110 of 167 posts
Re: Can you solve it? The Greplin programming challenge
#102"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…
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
#103[deleted]
Re: Can you solve it? The Greplin programming challenge
#104Re: Can you solve it? The Greplin programming challenge
#105Damn, 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…
Re: Can you solve it? The Greplin programming challenge
#106Edit: 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
#107Oh 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?
Re: Can you solve it? The Greplin programming challenge
#108Too easy to solve by brute force. I'd suggest looking at Project Euler for inspiration.
Re: Can you solve it? The Greplin programming challenge
#109Earlier 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 :)?
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
#110The 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!
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