Skip to content

Instantly share code, notes, and snippets.

@Angehl
Created February 21, 2020 16:08
Show Gist options
  • Select an option

  • Save Angehl/903e8d7ccd452be4b3d335ae46fb3aae to your computer and use it in GitHub Desktop.

Select an option

Save Angehl/903e8d7ccd452be4b3d335ae46fb3aae to your computer and use it in GitHub Desktop.
import random
import collections
def generateHand(size, maxcard):
r = []
for i in range(size):
r.append(random.randint(1, maxcard))
return r
def allStraights(input, size, maxcard):
total = len(input)
if total % size != 0:
return False
cards = collections.Counter(input)
cards[maxcard+1] = cards[1]
c = 0
s = maxcard
l = 0
while total > 0:
c = (c % maxcard) +1
cards[1] = min([cards[1], cards[maxcard+1]])
cards[maxcard+1] = cards[1]
if s == c:
if l >= 1:
return False
l += 1
if (cards[c] == 0):
continue
straight = True;
for i in range(c, c+size):
if cards[i] <= 0:
straight = False
break
if straight:
s = c
l = 0
for i in range(c, c+size):
cards[i] -= 1
total -= 1
return True
#Tests done with cards 1-5 and straight size 3,for simplicity
#It should scale perfeclty to any size
test1 = [5, 2, 2, 3, 2, 4, 2, 3, 3, 5, 3, 3, 4, 4, 2, 2, 5, 3, 2, 4, 1] #false
test2 = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3] #true
test3 = [1 ,2, 3, 4, 5, 1] #true
test4 = [1 ,2, 3, 4, 5, 1, 1, 1, 1]#false
inp = [
[1,2,3,4,5],
[1,2,3],
[1,1,2,2,3,3,4,4,5,5],
[1,1,2,2,5,5,4,4,3,3],
[9,8,10,7,11,9,12,10,13,11],
[1,3,4,5,6],
[9,8,10,7,11,2,12,10,13,11],
[9,8,10,7,11,1,12,10,13,11],
[5,4,3,2,1,1,13,12,11,10],
[9,10,10,11,11,12,12,13,13,1,1,2,2,3,3,4,4,5,5,6],
[9,10,10,11,11,12,12,13,13,1,1,2,2,3,3,4,4,5,5,6,6,7,8,9,10],
[13,1,2,3,4]
]
testr = [
True,
False,
True,
True,
True,
False,
False,
True,
True,
True,
True,
False
]
print("---------------------------")
for i in range(len(inp)):
print(str(testr[i]) + ": " + str(allStraights(inp[i], 5, 13)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment