Re:Codility - Automated tests of programming skills
by moconnor on Friday January 08, 2010 @08:26AM
(#1039451)
Pasties are a good idea, but results pages are more interesting. Here's my sad effort after 8 mins in python: http://codility.com/demo/results/?id=demoXFXD64-GCZ
The site's very slick. My only feedback is the histogram on the results page could be more prominent - it's cool, useful information but I ended up inspecting the html elements to work out what it was.
Also the results page seemed to keep refreshing for me while waiting for results (Safari 3). Surely that should've been AJAX'd?
Re:Codility - Automated tests of programming skills
by lincolnq on Friday January 08, 2010 @09:26AM
(#1039551)
regarding your python code: do you know about 'enumerate'? It returns an iterable of (index, value) pairs of a sequence. :)
Re:Codility - Automated tests of programming skills
by moconnor on Tuesday January 12, 2010 @03:08AM
(#1047099)
+1! Thanks for the reminder. I'm fairly new to python and couldn't remember the keyword. I guess this is a reasonable argument for the time deadline - to get it done quickly I didn't look it up, instead doing the simplest thing I knew would work and thus exposing the pitiful state of my python experience :-)
Re:Codility - Automated tests of programming skills
by almost on Friday January 08, 2010 @11:16AM
(#1039798)
enumerate is very useful, here's mine:
def equi ( A ):
right = sum(A)
left = 0
for i,x in enumerate(A):
right -= x
if right == left:
return i
left += x
return -1
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?
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
I'd give people access to their language's output facility for playing around to the solution, but that is a minor nitpick. (And I suppose I could open an irb instance on my machine for exploration and then give you code when I'm good and ready.)
My Ruby solution, in case we've got anybody who is struggling: http://pastie.org/771438 This would be my first cut if you asked me to whiteboard this.