Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def minMoves(avg):
- # distance = 0
- # position = 1
- # hold = avg.pop()
- # for number in avg:
- # if number != hold:
- # distance += position
- # else:
- # position += 1
- # return distance
- return min(zero(avg), ones(avg))
- def zero(avg):
- total = 0
- ones = 0
- for item in avg:
- if item:
- ones += 1
- else:
- total += ones
- return total
- def ones(avg):
- total = 0
- ones = 0
- for item in avg:
- if not item:
- ones += 1
- else:
- total += ones
- return total
- avg = [1,0,1,0,0,0,0,1]
- avg1 = [0,0,0,0,1]
- print(minMoves(avg))
- print(minMoves(avg1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement