fork(1) download
  1. # http://c...content-available-to-author-only...e.com/questions/49700/books-on-a-shelf
  2. # http://r...content-available-to-author-only...l.it/mt7/4
  3.  
  4. from operator import*
  5. from itertools import*
  6. def f(t):
  7. m=1
  8. for l in(sorted(t,key=itemgetter(*o))for o in permutations(range(3))):
  9. c=1
  10. for k in range(len(l)-1):c+=all(i<=j for i,j in zip(l[k],l[k+1]))
  11. m=max(m,c)
  12. print m
  13.  
  14. f([(1, 1, 1)]) #1
  15. f([(5, 2, 5), (1, 3, 5)]) #1
  16. f([(5, 2, 5), (1, 2, 5)]) #2
  17. f([(2, 2, 2), (2, 2, 2), (2, 2, 2), (1, 3, 6)]) #3
  18. f([(1, 2, 5), (1, 3, 5), (1, 2, 8), (1, 2, 5), (7, 7, 7)]) #4
  19.  
  20. # WRONG!
  21.  
  22. #4 but should be 3
  23. f([(5, 19, 3), (9, 4, 16), (15, 16, 13), (7, 4, 16), (1, 13, 14), (20, 1, 15), (9, 8, 19), (4, 11, 1)])
  24. #6 but should be 5
  25. f([(1, 1, 18), (1, 13, 7), (14, 1, 17), (8, 15, 16), (18, 8, 12), (8, 8, 15), (10, 1, 14), (18, 4, 6), (10, 4, 11), (17, 14, 17), (7, 10, 10), (19, 16, 17), (13, 19, 2), (16, 8, 13), (14, 6, 12), (18, 12, 3)])
Success #stdin #stdout 0.01s 7736KB
stdin
Standard input is empty
stdout
1
1
2
3
4
4
6