Skip to content

Instantly share code, notes, and snippets.

@jo32
Created May 20, 2014 19:11
Show Gist options
  • Save jo32/117ab5ec0a3746644865 to your computer and use it in GitHub Desktop.
Save jo32/117ab5ec0a3746644865 to your computer and use it in GitHub Desktop.
from collections import deque
from functools import reduce
a = deque([9, 6, 6, 6])
b = deque([7, 1, 5, 3])
c = deque([4, 3, 2, 8])
def is_satisfied(a, b, c):
avg = (sum(a) + sum(b) + sum(c)) / 4
return reduce(lambda x, i: x and avg == (a[i] + b[i] + c[i]), range(0, 4), True)
def find():
for i in range(0, 4):
b.rotate(1)
for j in range(0, 4):
c.rotate(1)
if is_satisfied(a, b, c):
return (i + 1, j + 1)
print(find())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment