Skip to content

Instantly share code, notes, and snippets.

@ChlorUpload
Created October 24, 2022 13:42
Show Gist options
  • Save ChlorUpload/8f4dc29cdff32d30e339a6124735a594 to your computer and use it in GitHub Desktop.
Save ChlorUpload/8f4dc29cdff32d30e339a6124735a594 to your computer and use it in GitHub Desktop.
pile
from enum import IntEnum
class Color(IntEnum):
Red = 1,
Yellow = 2,
Blue = 3,
def rule1(pile: list[Color]) -> bool:
"""
Rule 1:
The color of the incident blocks must differ each other.
"""
for i in range(len(pile) - 1):
if pile[i] == pile[i+1]:
return False
return True
def rule2(pile: list[Color]) -> bool:
"""
Rule 2:
The yellow block cannot follow right after the red block.
"""
for i in range(len(pile) - 1):
if pile[i] == Color.Red and pile[i+1] == Color.Yellow:
return False
return True
def pile_generator() -> list[Color]:
gen_list = [0 for _ in range(13)]
while True:
for i in range(1, 14):
last = gen_list[-i]
if last < 2:
gen_list[-i] += 1
break
else:
gen_list[-i] = 0
else:
# overflow
return
yield [Color(x + 1) for x in gen_list]
gen = pile_generator()
count = 0
for pile in gen:
if rule1(pile) and rule2(pile):
print([int(x) for x in pile])
count += 1
print(count)
print(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment