thewitchking

Untitled

Apr 12th, 2026
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. from itertools import permutations, product
  2.  
  3. def solution(A):
  4.     # Step 1: Convert into domino pairs
  5.     dominoes = [(A[i], A[i+1]) for i in range(0, len(A), 2)]
  6.    
  7.     # Step 2: Try all permutations
  8.     for perm in permutations(dominoes):
  9.        
  10.         # Step 3: Try all rotations (0 = original, 1 = flipped)
  11.         for flips in product([0, 1], repeat=6):
  12.            
  13.             # Apply flips
  14.             d = []
  15.             for i in range(6):
  16.                 if flips[i] == 0:
  17.                     d.append(perm[i])
  18.                 else:
  19.                     d.append((perm[i][1], perm[i][0]))
  20.            
  21.             # Pyramid layout:
  22.             # Bottom: d[0], d[1], d[2]
  23.             # Middle: d[3], d[4]
  24.             # Top: d[5]
  25.            
  26.             # Check conditions:
  27.             if (
  28.                 # Middle over bottom
  29.                 d[3][0] == d[0][1] and d[3][1] == d[1][0] and
  30.                 d[4][0] == d[1][1] and d[4][1] == d[2][0] and
  31.                
  32.                 # Top over middle
  33.                 d[5][0] == d[3][1] and d[5][1] == d[4][0]
  34.             ):
  35.                 return "YES"
  36.    
  37.     return "NO"
Advertisement
Add Comment
Please, Sign In to add comment