Live data from Hacker News

Can you solve it? The Greplin programming challenge

challenge.greplin.com

131–140 of 167 posts

Re: Can you solve it? The Greplin programming challenge

#131
post #118

Earlier quoted context omitted.

I can't read ruby, but here's something a little smarter than brute force in C (on its way to DP, but I couldn't be arsed to work out the recurrence so I just iterated until it stabilized): http://gist.github.com/617854

It looks similar to mine, but you got lucky (or unlucky depending on how you look at it) that the longest palindrome had an odd character count. The confusing bits in the Ruby are actually just the definition of an even and odd palindrome finder, which are the same except for two seed values for where the first comparison is conducted and it's length.

oh whoops nice catch thx

Re: Can you solve it? The Greplin programming challenge

#132
post #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?

Well that depends on your level of expertise :-) I start to have unsolved problems around #60, but found I had to start getting pretty clever long before that. The highest number I've solved is 112, and the one before that is 102. YMMV.

Re: Can you solve it? The Greplin programming challenge

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

Matlab for all three parts.

Quick and dirty solutions here: http://gist.github.com/618006

Re: Can you solve it? The Greplin programming challenge

#135
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

I was at work on a crappy thin client and first tried to run list(itertools.combinations(sequence)), which was crapping out. After I switched it to itertools.combinations(sequence,i) and put that right into my for loop it was fine.

Re: Can you solve it? The Greplin programming challenge

#136
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

Thanks for sharing! Love the style and it's readability. My newbie python code did the trick, but is way harder to read - your code really showed me room for improvement!

Re: Can you solve it? The Greplin programming challenge

#137
post #123

Earlier quoted context omitted.

Easy job for a regex: while ($string =~ /((\w+)\w?(??{reverse $2}))/g) { print "$1\n"; }

fuckin nice. now I feel like a doofus for using ruby, when I thought it was straightforward.

I've done it ruby this way:

    text.scan(/(.)(.)(.)(.)(\3)(\2)(\1)/)

Re: Can you solve it? The Greplin programming challenge

#140
post #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…

If bl2seq gets the longest common subsequence I did exactly the same thing. In haskell it just seems the right thing to do. Actually it would be damn interesting to see if there are patterns in the solutions for every programming language.
Post reply on HN