Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Created June 12, 2017 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ram-N/aec49d46d7eba06cd1f311e993b5cd74 to your computer and use it in GitHub Desktop.
Save Ram-N/aec49d46d7eba06cd1f311e993b5cd74 to your computer and use it in GitHub Desktop.
24_game_puzzle
def common_elements(list1, list2):
return list(set(list1) & set(list2))
import itertools
fileidx = 1
for x,y in itertools.combinations(cards, 2):
match = common_elements(x, y)
print(len(match), match)
if len(match):
for m in range(len(match)):
print("Holding out", match[m], "in", x,y)
singleton = [int(x1) for x1 in str(match[m])]
left = [r for r in x if not r in singleton]
right = [r for r in y if not r in singleton]
fname = "../output/double_var_" + str(fileidx) + "_sol_" + str(match[m]) + ".jpg"
print_to_file(left, right, fname)
fileidx += 1
import matplotlib.pyplot as plt
_DEBUG = False
def print_to_file(list1, list2, fname):
offset=0.25
x = [0,4*offset,4*offset,8*offset,11*offset, 11*offset,14*offset]
x = [e+0.3 for e in x]
y = [2.1,1,3.2,2.1,1,3.2,2.1]
y = [e-0.4 for e in y]
labels = list1 + ["?"] + list2
labels = [str(i) for i in labels]
plt.figure(num=None, figsize=(5,4), dpi=80, facecolor='w', edgecolor='k')
#plt.plot(x,y, 'k.')
for label, x, y in zip(labels, x,y):
plt.annotate(
label,
xy=(x, y), xytext=(0, 0),
textcoords = 'offset points',
size=40)
#plt.axis('off')
circle1 = plt.Circle((7 *offset, 2), 1.5, color='#ffd533', alpha=0.9)
circle2 = plt.Circle((13 *offset, 2), 1.5, color='#ffd533', alpha=0.9)
fig = plt.gcf()
ax = fig.gca()
ax.axes.get_xaxis().set_visible(False) #turn off axes tickmarks
ax.axes.get_yaxis().set_visible(False) #we need the axis for the facecolor
ax.set_facecolor((0, 0, 1))
ax.add_artist(circle1)
ax.add_artist(circle2)
plt.ylim( 0, 4 )
plt.xlim( 0, 5 )
#fig.set_facecolor('blue')
plt.savefig(fname, bbox_inches='tight')
if DEBUG:
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment