Skip to content

Instantly share code, notes, and snippets.

@shiracamus
Created October 2, 2022 07:30
Show Gist options
  • Save shiracamus/6d6874e202d076f90d54829f791ccb3c to your computer and use it in GitHub Desktop.
Save shiracamus/6d6874e202d076f90d54829f791ccb3c to your computer and use it in GitHub Desktop.
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