Created
October 2, 2022 07:30
-
-
Save shiracamus/6d6874e202d076f90d54829f791ccb3c to your computer and use it in GitHub Desktop.
This file contains 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
def solve(cards, numbers): | |
if not numbers: | |
yield cards[:] | |
return | |
left = cards.index(0) | |
for number in numbers: | |
if (right := left + number + 1) < len(cards) and cards[right] == 0: | |
cards[left] = cards[right] = number | |
yield from solve(cards, numbers - {number}) | |
cards[left] = cards[right] = 0 | |
uniq = [] | |
for cards in solve([0] * 14, set(range(1, 8))): | |
if cards[::-1] not in uniq: | |
uniq.append(cards) | |
for i, cards in enumerate(uniq, 1): | |
print(f'No.{i:2}', cards) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment