Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import permutations, product
- def solution(A):
- # Step 1: Convert into domino pairs
- dominoes = [(A[i], A[i+1]) for i in range(0, len(A), 2)]
- # Step 2: Try all permutations
- for perm in permutations(dominoes):
- # Step 3: Try all rotations (0 = original, 1 = flipped)
- for flips in product([0, 1], repeat=6):
- # Apply flips
- d = []
- for i in range(6):
- if flips[i] == 0:
- d.append(perm[i])
- else:
- d.append((perm[i][1], perm[i][0]))
- # Pyramid layout:
- # Bottom: d[0], d[1], d[2]
- # Middle: d[3], d[4]
- # Top: d[5]
- # Check conditions:
- if (
- # Middle over bottom
- d[3][0] == d[0][1] and d[3][1] == d[1][0] and
- d[4][0] == d[1][1] and d[4][1] == d[2][0] and
- # Top over middle
- d[5][0] == d[3][1] and d[5][1] == d[4][0]
- ):
- return "YES"
- return "NO"
Advertisement
Add Comment
Please, Sign In to add comment