Last active
November 16, 2016 17:26
-
-
Save ehermes/6c13dda206ad93b17d390bbcbc2b9924 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
from __future__ import division, print_function | |
from random import shuffle | |
ncards = 60 | |
deck = range(ncards) | |
shuffle(deck) | |
def inorder(deck): | |
for i, j in enumerate(deck): | |
if i != j: | |
return False | |
return True | |
n = 0 | |
lookingfor = 1 | |
while True: | |
n += 1 | |
toptwo = deck[:2] | |
rest = deck[2:] | |
if lookingfor == len(deck) and toptwo == [0, 1]: | |
assert inorder(deck) | |
print(deck) | |
break | |
toptwo.sort() | |
if lookingfor in toptwo: | |
if toptwo[0] == lookingfor - 1: | |
lookingfor += 1 | |
else: | |
toptwo.remove(lookingfor) | |
deck = [lookingfor] + rest + toptwo | |
continue | |
deck = rest + toptwo | |
print(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment