Home > other >  Brother repast row seat programming problem!!!!!
Brother repast row seat programming problem!!!!!

Time:11-25

Topic: brother 6 people, the relationship between continuous order are not (namely, eldest brother and second, second and third place, old three and old four, and so on), dining row of seats now will not brothers don't sit around in, ask: how many kinds of method, print it out, one day, he and old and noisy up, asking how today's seat row???

CodePudding user response:

Single desk or table,

6 people, the loop and recursive solution,

CodePudding user response:

Sat is a traditional round table

CodePudding user response:

 def f (datas, conds) : 
Return the filter (lambda r: sum ([1 if math.h fabs (r.i ndex (cond [0]) - r.i ndex (cond [1]))==1 else 0 for cond in conds])==0, datas)
The from itertools import permutations
The import math
Result=permutations (' 123456 ', 6)
Conds=[' 12 ', '23', '34', '45', '56]
Result=list (f (result, conds))
Print (' {} line method, as follows: \ n {} '. The format (len (result), the result))
Result=list (f (result, [' 53 ']))
Print (' {} line method, as follows: \ n {} '. The format (len (result), the result))


OutPut:
 there are 90 kinds of method, as follows: 
[('1', '3', '5', '2', '4', '6'), ('1', '3', '5', '2', '6', '4'), ('1', '3', '6', '4', '2', '5'), ('1', '4', '2', '5', '3', '6'), ('1', '4', '2', '6', '3', '5'), ('1', '4', '6', '2', '5', '3'), ('1', '4', '6', '3', '5', '2'), ('1', '5', '2', '4', '6', '3'), ('1', '5', '3', '6', '2', '4'), ('1', '5', '3', '6', '4', '2'), ('1', '6', '3', '5', '2', '4'), ('1', '6', '4', '2', '5', '3'), ('2', '4', '1', '5', '3', '6'), ('2', '4', '1', '6', '3', '5'), ('2', '4', '6', '1', '3', '5'), ('2', '4', '6', '1', '5', '3'), ('2', '4', '6', '3', '1', '5'), ('2', '4', '6', '3', '5', '1'), ('2', '5', '1', '3', '6', '4'), ('2', '5', '1', '4', '6', '3'), ('2', '5', '3', '1', '4', '6'), ('2', '5', '3', '1', '6', '4'), ('2', '5', '3', '6', '1', '4'), ('2', '5', '3', '6', '4', '1'), ('2', '6', '3', '5', '1', '4'), ('2', '6', '4', '1', '3', '5'), ('2', '6', '4', '1', '5', '3'), ('3', '1', '4', '6', '2', '5'), ('3', '1', '5', '2', '4', '6'), ('3', '1', '5', '2', '6', '4'), ('3', '1', '6', '4', '2', '5'), ('3', '5', '1', '4', '2', '6'), ('3', '5', '1', '4', '6', '2'), ('3', '5', '1', '6', '2', '4'), ('3', '5', '1', '6', '4', '2'), ('3', '5', '2', '4', '1', '6'), ('3', '5', '2', '4', '6', '1'), ('3', '5', '2', '6', '1', '4'), ('3', '5', '2', '6', '4', '1'), ('3', '6', '1', '4', '2', '5'), ('3', '6', '1', '5', '2', '4'), ('3', '6', '2', '4', '1', '5'), ('3', '6', '2', '5', '1', '4'), ('3', '6', '4', '1', '5', '2'), ('3', '6', '4', '2', '5', '1'), ('4', '1', '3', '5', '2', '6'), ('4', '1', '3', '6', '2', '5'), ('4', '1', '5', '2', '6', '3'), ('4', '1', '5', '3', '6', '2'), ('4', '1', '6', '2', '5', '3'), ('4', '1', '6', '3', '5', '2'), ('4', '2', '5', '1', '3', '6'), ('4', '2', '5', '1', '6', '3'), ('4', '2', '5', '3', '1', '6'), ('4', '2', '5', '3', '6', '1'), ('4', '2', '6', '1', '3', '5'), ('4', '2', '6', '1', '5', '3'), ('4', '2', '6', '3', '1', '5'), ('4', '2', '6', '3', '5', '1'), ('4', '6', '1', '3', '5', '2'), ('4', '6', '2', '5', '1', '3'), ('4', '6', '2', '5', '3', '1'), ('4', '6', '3', '1', '5', '2'), ('5', '1', '3', '6', '2', '4'), ('5', '1', '3', '6', '4', '2'), ('5', '1', '4', '2', '6', '3'), ('5', '2', '4', '1', '3', '6'), ('5', '2', '4', '1', '6', '3'), ('5', '2', '4', '6', '1', '3'), ('5', '2', '4', '6', '3', '1'), ('5', '2', '6', '3', '1', '4'), ('5', '2', '6', '4', '1', '3'), ('5', '3', '1', '4', '2', '6'), ('5', '3', '1', '4', '6', '2'), ('5', '3', '1', '6', '2', '4'), ('5', '3', '1', '6', '4', '2'), ('5', '3', '6', '1', '4', '2'), ('5', '3', '6', '2', '4', '1'), ('6', '1', '3', '5', '2', '4'), ('6', '1', '4', '2', '5', '3'), ('6', '2', '4', '1', '3', '5'), ('6', '2', '4', '1', '5', '3'), ('6', '2', '5', '3', '1', '4'), ('6', '3', '1', '4', '2', '5'), ('6', '3', '1', '5', '2', '4'), ('6', '3', '5', '1', '4', '2'), ('6', '3', '5', '2', '4', '1'), ('6', '4', '1', '3', '5', '2'), ('6', '4', '2', '5', '1', '3'), ('6', '4', '2', '5', '3', '1')]
There are 34 kinds of method, as follows:
[('1', '3', '6', '4', '2', '5'), ('1', '5', '2', '4', '6', '3'), ('2', '4', '6', '3', '1', '5'), ('2', '5', '1', '3', '6', '4'), ('2', '5', '1', '4', '6', '3'), ('3', '1', '4', '6', '2', '5'), ('3', '1', '5', '2', '4', '6'), ('3', '1', '5', '2', '6', '4'), ('3', '1', '6', '4', '2', '5'), ('3', '6', '1', '4', '2', '5'), ('3', '6', '1', '5', '2', '4'), ('3', '6', '2', '4', '1', '5'), ('3', '6', '2', '5', '1', '4'), ('3', '6', '4', '1', '5', '2'), ('3', '6', '4', '2', '5', '1'), ('4', '1', '3', '6', '2', '5'), ('4', '1', '5', '2', '6', '3'), ('4', '2', '5', '1', '3', '6'), ('4', '2', '5', '1', '6', '3'), ('4', '2', '6', '3', '1', '5'), ('4', '6', '2', '5', '1', '3'), ('4', '6', '3', '1', '5', '2'), ('5', '1', '3', '6', '2', '4'), ('5', '1', '3', '6', '4', '2'), ('5', '1', '4', '2', '6', '3'), ('5', '2', '4', '1', '3', '6'), ('5', '2', '4', '1', '6', '3'), ('5', '2', '4', '6', '1', '3'), ('5', '2', '4', '6', '3', '1'), ('5', '2', '6', '3', '1', '4'), ('5', '2', '6', '4', '1', '3'), ('6', '3', '1', '4', '2', '5'), ('6', '3', '1', '5', '2', '4'), ('6', '4', '2', '5', '1', '3')]

The Process finished with exit code 0
  • Related