Nov-27-2021, 06:03 AM
(This post was last modified: Nov-27-2021, 06:03 AM by CompleteNewb.)
I have written this code to identify possible straights in a serie of numbers. It works find thanks to the help of the people in this forum, but now I want this function to only identify possible straights with 3 items in the set.
Now I 've written this to check if my logic was okay
So what's the problem?
I have been trying to find the solution for a week now and i can't find it, please help me.
flop = [7, 8, 9]
possiblestraight = []
def check3outof3straightinflop(flop, possiblestraightcheck, possiblenumberofstraight, possiblestraight, possiblestraightgradelist):
possiblestraightgrade = []
possibleplayershand = []
for n in range(len(flop)):
possibleplayershand.append(int(flop[n][0]))
possibleplayershand.sort()
if possibleplayershand[0] == 1:
possibleplayershand.append(14)
cardsset = set(possibleplayershand)
for f in cardsset:
possiblestraightset = cardsset.intersection(range(f,f+5))
possiblestraightlist = list(possiblestraightset)
possiblestraightlist.sort()
if len(possiblestraightlist) > 2:
possiblestraight.append(possiblestraightlist)
print(possiblestraight)
#The if statement above here is where the [8,9] is supposed to be removed
possiblestraightset = []
for s in possiblestraight:
possiblestraightset.append(set(s))
possiblestraight = []
for s in possiblestraightset:
for r in possiblestraight:
if s.issubset(r):
break
else:
possiblestraight.append(s)
for n in possiblestraight:
if n != 0:
possiblestraightgrade = max(n)
possiblestraightgradelist.append(possiblestraightgrade)
possiblestraightgradeset = set(possiblestraightgradelist)
if possiblestraight != []:
possiblestraightcheck = True
possiblenumberofstraight = len(possiblestraight)
return(possiblestraightcheck, possiblestraight, possiblestraightgradeset, possiblenumberofstraight)Output:(True, [{8, 9}, {8, 9, 7}], {9}, 2)So if the flop = [7, 8, 9], i want my funtion to return the list "possiblestraight" as [{8,9,7}] because the set [8,9] is not 3 items long so it should be removed, but the problem is that it's not "possiblestraight = [{8, 9}, {8, 9, 7}]"Now I 've written this to check if my logic was okay
possiblestraight = []
possiblestraightset = []
possiblestraightlist = []
possibleplayershand = [7, 8, 9]
cardsset = set(possibleplayershand)
for f in cardsset:
possiblestraightset = cardsset.intersection(range(f,f+5))
possiblestraightlist = list(possiblestraightset)
possiblestraightlist.sort()
if len(possiblestraightlist) > 2:
possiblestraight.append(possiblestraightlist)
print(possiblestraight)Output:[[7, 8, 9]]and it works, my result is [[7, 8, 9]]So what's the problem?
I have been trying to find the solution for a week now and i can't find it, please help me.
