Re:Codility - Automated tests of programming skills
by almost on Friday January 08, 2010 @11:16AM
(#1039798)
enumerate is very useful, here's mine:
What's interesting is that all the versions I've seen so far are pretty much identical apart from very minor things. This would seem to me to be obviously the correct way to do it but I'm interested if it's just a way. Did anyone solve this in a different way of equal or greater elegance?
[ Parent
| on HN ]
Re:Codility - Automated tests of programming skills
by anc2020 on Friday January 08, 2010 @03:32PM
(#1040355)
Mine kept one cumulative list adding left to right and another summing right to left. This is conventionally slower, but conceivably faster if you do it in parallel, leaving the final loop to be something like:
for i in xrange(len(A)):
if right[i] == left[i]:
return i
The final loop here is slightly tighter, so as long as your parallelism didn't add big overheads, this will be faster.Original: http://pastebin.com/m6e742f56 Parallelised: http://pastebin.com/m32a60b1