Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
One line 118 symbols solution in 3rd party category for Hubspot Amulet by CDG.Axel
from itertools import product
from numpy import matmul
def checkio(matrix):
# the weirdest solution in one line with itertools and numpy
return next(vec for vec in product(range(-180, 181, 5), repeat=3)
if list(matmul(vec, matrix) % 360) == [0, 225, 315])
"""
def checkio(matrix):
# slightly weird solution in one line with itertools
return next(vec for vec in product(range(-180, 181, 5), repeat=3)
if [sum(matrix[col][row] * vec[col] for col in range(3)) % 360
for row in range(3)] == [0, 225, 315])
def checkio(matrix):
# 3-line solution without product
for vec in [(i, j, k) for i in range(-180, 181, 5) for j in range(-180, 181, 5) for k in range(-180, 181, 5)]:
if [sum(matrix[col][row] * vec[col] for col in range(3)) % 360 for row in range(3)] == [0, 225, 315]:
return vec
"""
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
def check_it(func, matrix):
result = func(matrix)
if not all(-180 <= el <= 180 for el in result):
print("The angles must be in range from -180 to 180 inclusively.")
return False
f, s, t = result
temp = [0, 0, 0]
temp[0] += f
temp[1] += matrix[0][1] * f
temp[2] += matrix[0][2] * f
temp[0] += matrix[1][0] * s
temp[1] += s
temp[2] += matrix[1][2] * s
temp[0] += matrix[2][0] * t
temp[1] += matrix[2][1] * t
temp[2] += t
temp = [n % 360 for n in temp]
if temp == [0, 225, 315]:
return True
else:
print("This is the wrong final position {0}.".format(temp))
return False
assert check_it(checkio,
[[1, 2, 3],
[3, 1, 2],
[2, 3, 1]]), "1st example"
assert check_it(checkio,
[[1, 4, 2],
[2, 1, 2],
[2, 2, 1]]), "2nd example"
assert check_it(checkio,
[[1, 2, 5],
[2, 1, 1],
[2, 5, 1]]), "3rd example"
Sept. 20, 2021
Comments: