Skip to content

Instantly share code, notes, and snippets.

Created November 4, 2013 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7306048 to your computer and use it in GitHub Desktop.
Save anonymous/7306048 to your computer and use it in GitHub Desktop.
def pool(array):
voda = 0
while sum(array):
array = [x-1 if x > 1 else 0 for x in array]
str_row = ''.join(['1' if x else '0' for x in array])
str_row = str_row[str_row.find('1'):str_row.rfind('1')]
cur_voda = str_row.count('0')
voda += cur_voda
return voda
assert(pool([2,5,1,2,3,4,7,7,6]) == 10)
assert(pool([2,5,1,3,1,2,1,7,7,6]) == 17)
assert(pool([5,1,3,6,1,6,1,3,1,4]) == 18)
assert(pool([1,2,3,4,5,5,4,3,2,1]) == 0)
assert(pool([6,1,1,1,7,1,1,1,1,7]) == 39)
assert(pool([7,1,1,1,7,1,1,1,1,7]) == 42)
assert(pool([1,2,3,4,5,6,7,8]) == 0)
assert(pool([8,7,6,5,4,3,2,1]) == 0)
assert(pool([5,1,3,6,1,5,1,7,6,5]) == 17)
assert(pool([7,1,3,6,1,5,1,7,6,5]) == 25)
assert(pool([3,4,7,3,4,7,6,7,2,4]) == 10)
assert(pool([5,1,4,2,3]) == 4)
assert(pool([6,1,5,2,1,4]) == 9)
assert(pool([4,1,2,5,1,6]) == 9)
assert(pool([7,1,5,2,1,4]) == 9)
assert(pool([7,1,5,2,1,4,2]) == 9)
assert(pool([7,1,5,2,1,4,3,2]) == 9)
assert(pool([7,1,5,1,2,4,3,2]) == 9)
assert(pool([5,1,5,1,5,1,5]) == 12)
assert(pool([1,5,1,5,1,5,1]) == 8)
assert(pool([5,1,3]) == 2)
assert(pool([0,9,8,7,6,5,4,3,2,1,0]) == 0)
Copy link

ghost commented Nov 5, 2013

pool[0,1,1,1,0,1,1,1,1,0] will return "0", while should be "1"
pool[0,2,2,2,0,2,2,2,2,0] return "1", while should be "2" and so on:)

@Torikova
Copy link

Torikova commented Nov 5, 2013

Ok, swap lines 5 and 6 =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment