sympy with creative itertools solution in 3rd party category for Hubspot Amulet by Phil15
from itertools import accumulate, count, product
from sympy import Matrix, solve_linear_system
from sympy.abc import x, y, z
def checkio(rotation, goal = (0, 225, 315)):
rotation = [list(col) for col in zip(*rotation)] # matrix transposition
# numbers: 0,1,-1,2,-2,3,-3,4,-4,... if L==it.count() else n first elements.
numbers = lambda L: accumulate(k*(-1)**(k+1) for k in L)
for n, a in enumerate(numbers(count())):
for b, c in product(numbers(range(n+1)), repeat=2):
# Search solution with first lever doing a turns, second b turns...
system = Matrix([row + [g + 360 * turns]
for row, g, turns in zip(rotation, goal, (a,b,c))])
sol = solve_linear_system(system, x, y, z)
sol = [(sol[k] + 180) % 360 - 180 for k in (x, y, z)]
if all(int(k) == k for k in sol): # solution of integers ?
return [int(k) for k in sol]
Sept. 26, 2018