Created
February 20, 2020 23:42
-
-
Save alu0100888102/c54c6d6a5856a678ecda2f332b0e8af2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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