fork download
  1. from itertools import permutations
  2.  
  3. L1, L2 = [], []
  4. S1, S2 = set(), set()
  5.  
  6. for p in permutations(range(1,8)):
  7. if sum(p[:3])==10 and sum(p[-3:])==12:
  8. if p[-1]==5:
  9. L1.append(p)
  10. if p[-1]==p[0]+1:
  11. L2.append(p)
  12.  
  13. print 1
  14. for i in L1:
  15. index = i.index(3)+1
  16. S1.add(index)
  17. print sum(j*10**k for k,j in enumerate(i[::-1])), index
  18. print 'answer1 :', list(S1)
  19. print
  20.  
  21. print 2
  22. for i in L2:
  23. index = i.index(2)+1
  24. S2.add(index)
  25. print sum(j*10**k for k,j in enumerate(i[::-1])), index
  26. print 'answer2 :', list(S2)
Success #stdin #stdout 0.01s 7852KB
stdin
Standard input is empty
stdout
1
1276345 5
1276435 6
1726345 5
1726435 6
2176345 5
2176435 6
2716345 5
2716435 6
7126345 5
7126435 6
7216345 5
7216435 6
answer1 : [5, 6]

2
1456372 7
1456732 7
1546372 7
1546732 7
2176453 1
2176543 1
2716453 1
2716543 1
3256174 2
3256714 2
3526174 3
3526714 3
answer2 : [1, 2, 3, 7]