Last active
February 6, 2017 20:46
-
-
Save munk/8f861e6e97a36838f2976f02bb17f25c 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
import itertools as it | |
import random | |
def cards(n, t): | |
nt = n*t | |
images = range(nt) | |
return [[j for j in images[i:i + t]] for i in range(0, n*t, t)] | |
def edges(cards, link_count): | |
ct = min(len(cards), link_count) # we can't have more edges than cards for prop4 | |
pairs = it.combinations(range(len(cards)), 2) | |
population = list(pairs) | |
return random.sample(population, ct) | |
def copy(a, b): | |
i = random.randint(0, len(a) - 1) | |
b[i] = a[i] | |
c = cards(7, 10) | |
edges = edges(c, 3) | |
for i,j in edges: | |
copy(c[i], c[j]) | |
for i, cc in enumerate(c): | |
print(i, cc) | |
print("") | |
print(edges) |
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
#!/usr/bin/env python | |
import itertools as it | |
import random | |
def cards(n, t): | |
nt = n*t | |
images = range(nt) | |
return [[j for j in images[i:i + t]] for i in range(0, n*t, t)] | |
def edges(cards, link_count): | |
ct = min(len(cards), link_count) # we can't have more edges than cards for prop4 | |
pairs = it.combinations(range(len(cards)), 2) | |
population = list(pairs) | |
return random.sample(population, ct) | |
def copy(a, b): | |
i = random.randint(0, len(a) - 1) | |
b[i] = a[i] | |
if __name__ == '__main__': | |
for n in range(2, 1000): | |
try: | |
t = random.randint(5, 50) | |
link_count = random.randint(1, n * t) | |
print("Generating deck: ", n, t) | |
c = cards(n, t) | |
links = edges(c, link_count) | |
for i,j in links: | |
copy(c[i], c[j]) | |
print("Cards:") | |
for i, cc in enumerate(c): | |
print(i, cc) | |
print("\nLinks:") | |
print(links) | |
print("**********") | |
except ValueError as e: | |
print("Unable to generate: ", t, c, link_count, e) |
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
#!/usr/bin/env python | |
import itertools as it | |
import random | |
def cards(n, t): | |
nt = n*t | |
images = range(nt) | |
return [[j for j in images[i:i + t]] for i in range(0, n*t, t)] | |
def edges(cards, link_count): | |
ct = min(len(cards), link_count) # we can't have more edges than cards for prop4 | |
pairs = it.combinations(range(len(cards)), 2) | |
population = list(pairs) | |
return random.sample(population, ct) | |
def bad_edges(cards, link_count): | |
e = edges(cards, link_count) | |
i = random.randint(0, len(e) - 1) | |
return e + [e[i]] | |
def copy(a, b): | |
i = random.randint(0, len(a) - 1) | |
b[i] = a[i] | |
if __name__ == '__main__': | |
for n in range(2, 1000): | |
try: | |
t = random.randint(5, 50) | |
link_count = random.randint(1, n * t) | |
print("Generating deck: ", n, t) | |
c = cards(n, t) | |
coin = random.randint(0, 1) | |
if coin == 0: | |
f = edges | |
else: | |
f = bad_edges | |
links = f(c, link_count) | |
for i,j in links: | |
copy(c[i], c[j]) | |
print("Cards:") | |
for i, cc in enumerate(c): | |
print(i, cc) | |
print("\nLinks:") | |
print(links) | |
print("**********") | |
except ValueError as e: | |
print("Unable to generate: ", t, c, link_count, e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment