Today… I played with Codility
Posted on January 13th, 2010 in Fun, Programming, Ruby | 2 Comments »
Well this seems pretty cool, http://codility.com
Although, it seems to just quiz you about basic asymptotic growth and does not seem to look at things like programming style etc. Still, I'm please my Ruby answer for the demo test got 100%, which, as the histogram shows... Not many people get. I suspect that the reason is, many people probably submit an O(n^2) answer, which fails for very large data sets. Here is what I submitted
And here is what I submitted:
And Here's the analysis it gave back to me:
Although, it seems to just quiz you about basic asymptotic growth and does not seem to look at things like programming style etc. Still, I'm please my Ruby answer for the demo test got 100%, which, as the histogram shows... Not many people get. I suspect that the reason is, many people probably submit an O(n^2) answer, which fails for very large data sets. Here is what I submitted
And here is what I submitted:
def equi(arr)
lhs = 0
tmp = 0
rhs = arr.inject(0) { |a,b| a + b }
arr.each_index do |i|
lhs += tmp
rhs -= arr[i]
tmp = arr[i]
return i if lhs == rhs
end
return -1
end
And Here's the analysis it gave back to me:
| test | time | result |
|---|---|---|
|
example
Test from the task description |
0.012 s. | OK |
|
extreme_empty
Empty array |
0.020 s. | OK |
| extreme_first | 0.008 s. | OK |
|
extreme_large_numbers
Sequence with extremly large numbers testing arithmetic overflow. |
0.020 s. | OK |
| extreme_last | 0.012 s. | OK |
| extreme_single_zero | 0.020 s. | OK |
|
extreme_sum_0
sequence with sum=0 |
0.020 s. | OK |
| simple | 0.016 s. | OK |
| single_non_zero | 0.012 s. | OK |
|
combinations_of_two
multiple runs, all combinations of {-1,0,1}^2 |
0.008 s. | OK |
|
combinations_of_three
multiple runs, all combinations of {-1,0,1}^3 |
0.012 s. | OK |
| small_pyramid | 0.072 s. | OK |
| large_long_sequence_of_ones | 13.349 s. | OK |
| large_long_sequence_of_minus_ones | 10.781 s. | OK |
| medium_pyramid | 4.336 s. | OK |
|
large_pyramid
Large performance test, O(n^2) solutions should fail. |
21.369 s. | OK |