Home > other >  No problem solving python game, with random function
No problem solving python game, with random function

Time:10-12

Topic is

Small white is his own ideas is the editor, but does not display the running things, would like to ask what is wrong, casually ask bosses solve

CodePudding user response:

 def Pai (list1, list2) : 
If len (list1) & lt;=1: # if incoming list only one element, recursion to the bottom,
# # print (list2 + list1) print out each portfolio list
Yan (y, list2 + list1) # list into the program to validate

The else:
For I in range (len (list1) :
Aa=list1. Copy () a copy of # list for list2, then delete the current sorting as one of the letters, when the rest of the elements of recursion,
Aa. Pop (I)
Pai (aa, list2 + list (list1 [I])) # here pass parameters list2 cannot in the program computing first pass again, * * *

Def Yan (y, list1) : # school verify
For I in y: # divided y list for several people say - dictionary,
Con=0
For k, v in i.i tems () : # splits a dictionary for the key and the value (two pairs)
# print (" says is the first name % d % s, list for % s "% (v, k, list1] [v - 1))
If list1] [v - 1==k: # key is the first value; Take the list of value and the key,
Con=con + 1

If con!=1: if the truth not for # 1, then end
Return

Print (" check: success, "list1)

Y=[{" B ": 2," A ", 3},
{" B ": 2," E ": 4},
{" C ": 1," D ": 2},
{5, "C" : "D" : 3},
{" E ": 4," A ": 1}]

A=[" a ", "B", "C", "D", "E"]
Pai (a, [])

CodePudding user response:

[' B ', 'D', 'A', 'E', 'C']
 the from itertools import permutations 

Ba00 bounds=[' 0 ', '0 b0e0', 'CD000', '00 d0c', 'A00E0]
Candidates=permutations (" ABCDE ", 5)

For the candidate in candidates:
If [len ([1 for I in range (5) if bound [I]==candidate [I]]) for bound in bounds]==[1, 1, 1, 1, 1] :
Print (list (candidate))
  • Related