Guest User

Avoiding the boxed permutation 123

a guest
Apr 27th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import itertools
  2.  
  3. def has_box_123(n,p):
  4.     for a in range(n):
  5.         for c in range(a+1,n):
  6.             A, C = p[a], p[c]
  7.             if A > C:
  8.                 continue
  9.             found = False
  10.             for b in range(a+1,c):
  11.                 if A < p[b] < C:
  12.                     if found:
  13.                         break
  14.                     else:
  15.                         found = True
  16.             else:
  17.                 if found:
  18.                     return True
  19.     return False
  20.  
  21. for n in range(11):
  22.     count = 0
  23.     for p in itertools.permutations(range(n)):
  24.         if not has_box_123(n,p):
  25.             count += 1
  26.     print(n,count)
Advertisement
Add Comment
Please, Sign In to add comment