Skip to content

Instantly share code, notes, and snippets.

@alu0100888102
Created February 20, 2020 23:42
Show Gist options
  • Select an option

  • Save alu0100888102/d242dcb61a0c1c83b84d4f290635224d to your computer and use it in GitHub Desktop.

Select an option

Save alu0100888102/d242dcb61a0c1c83b84d4f290635224d 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):
total = len(input)
if total % size != 0:
return False
cards = collections.Counter(input)
cards[max(cards)+1] = cards[1]
#Como el total de cartas no aumenta no hace falta actualizar constantemente el valor max(cards)+1
#los 1 duplicados estaran al final y seran los que sobren cuando acabe el bucle.
c = min(cards)
while total > 0:
if (cards[c] == 0) or (c == 1 and cards[2] == 0):
c += 1
continue
for i in range(c, c+size):
cards[i] -= 1
if cards[i] < 0:
return False
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]
test2 = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]
test3 = [1 ,2, 3, 4, 5, 1]
test4 = [1 ,2, 3, 4, 5, 1, 1, 1, 1]
print(allStraights(test4, 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment