Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. '''
  2. Входные данные: 0,0,0,2,2,0,0,0,0,6,3,0,0,4,0,0,0,0,4,4,0,3,0,0
  3. Выходные данные: 5,6,1,4,3,2,4,1,3,2,6,5,2,3,6,1,5,4,6,5,4,3,2,1,1,2,5,6,4,3,3,4,2,5,1,6
  4. '''
  5.  
  6. from random import shuffle
  7. from itertools import permutations
  8.  
  9. def check_visibility(data, restrictions):
  10.  
  11. forward_check = sum(all(1 if data[current] > backs else 0 for backs in data[:current]) for current in range(1,len(data)+1))
  12. backprop_check = sum(all(1 if data[current] > forwards else 0 for forwards in data[current+1:]) for current in range(len(data)-2,-1,-1))
  13.  
  14. if (restrictions[0] and restrictions[0] != forward_check + 1) or (restrictions[1] and restrictions[1] != backprop_check + 1):
  15. return False
  16.  
  17. return True
  18.  
  19. in_ = [int(i) for i in '0,0,0,2,2,0,0,0,0,6,3,0,0,4,0,0,0,0,4,4,0,3,0,0'.split(',')]
  20. N, E, S, W = [in_[n:n+6] for n in (0,6,12,18)]
  21.  
  22. muts = list(permutations([1,2,3,4,5,6],6))
  23. field_rows = [muts] * 6
  24. # field_cols = [field_rows[n::6] for n in range(6)]
  25.  
  26. for row_ix in range(6):
  27. print(row_ix)
  28. field_rows[row_ix] = [row for row in field_rows[row_ix] if check_visibility(row, (W[row_ix], E[row_ix]))]
  29. print(len(field_rows[row_ix]))
  30.  
  31. ans = []
  32. for row0 in field_rows[0]:
  33. for row1 in field_rows[1]:
  34. ans = [row0, row1]
  35. ans_cols = [ans[n::6] for n in range(2)]
  36. if not all(1 if check_visibility(col, (N[ix], S[ix])) else 0 for ix, col in enumerate(ans_cols) ):
  37. continue
  38. for row2 in field_rows[2]:
  39. ans = [row0,row1,row2]
  40. ans_cols = [ans[n::6] for n in range(3)]
  41. if not all(1 if check_visibility(col, (N[ix], S[ix])) else 0 for ix, col in enumerate(ans_cols) ):
  42. continue
  43. print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement