#Generate all possible cards sides = [1,2,3,4] combinations = [] for a in sides: for b in sides: for c in sides: for d in sides: combinations.append([a,b,c,d]) # Remove all dupes dupes = [] for combo in combinations: for side in sides: if combo.count(side) >= 3: dupes.append(combo) break for dupe in dupes: combinations.remove(dupe) # Remove cards with rotation symmetry unique = [] checked = [] def is_symmetrical(a,b): for i in range(4): _tmp = b[0] b[0] = b[1] b[1] = b[2] b[2] = b[3] b[3] = _tmp if a==b: return True return False for i in range(len(combinations)): _cursor = combinations[i] if _cursor in checked: continue else: unique.append(_cursor) if i == len(combinations) - 1: break for j in range(i+1, len(combinations)): if is_symmetrical(_cursor, combinations[j]): checked.append(combinations[j]) with open('cards.txt', 'w') as f: for combo in unique: f.write(str(combo)) f.write('\n') # [1, 1, 2, 2] # [1, 1, 2, 3] # [1, 1, 2, 4] # [1, 1, 3, 2] # [1, 1, 3, 3] # [1, 1, 3, 4] # [1, 1, 4, 2] # [1, 1, 4, 3] # [1, 1, 4, 4] # [1, 2, 1, 2] # [1, 2, 1, 3] # [1, 2, 1, 4] # [1, 2, 2, 3] # [1, 2, 2, 4] # [1, 2, 3, 2] # [1, 2, 3, 3] # [1, 2, 3, 4] # [1, 2, 4, 2] # [1, 2, 4, 3] # [1, 2, 4, 4] # [1, 3, 1, 3] # [1, 3, 1, 4] # [1, 3, 2, 2] # [1, 3, 2, 3] # [1, 3, 2, 4] # [1, 3, 3, 2] # [1, 3, 3, 4] # [1, 3, 4, 2] # [1, 3, 4, 3] # [1, 3, 4, 4] # [1, 4, 1, 4] # [1, 4, 2, 2] # [1, 4, 2, 3] # [1, 4, 2, 4] # [1, 4, 3, 2] # [1, 4, 3, 3] # [1, 4, 3, 4] # [1, 4, 4, 2] # [1, 4, 4, 3] # [2, 2, 3, 3] # [2, 2, 3, 4] # [2, 2, 4, 3] # [2, 2, 4, 4] # [2, 3, 2, 3] # [2, 3, 2, 4] # [2, 3, 3, 4] # [2, 3, 4, 3] # [2, 3, 4, 4] # [2, 4, 2, 4] # [2, 4, 3, 3] # [2, 4, 3, 4] # [2, 4, 4, 3] # [3, 3, 4, 4] # [3, 4, 3, 4]
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question