Skip to content

Instantly share code, notes, and snippets.

@elucid
Created July 21, 2010 03:57
Show Gist options
  • Save elucid/484036 to your computer and use it in GitHub Desktop.
Save elucid/484036 to your computer and use it in GitHub Desktop.
def get_value_map(vals):
if len(vals) == 1:
return {vals[0]: str(vals[0])}
else:
eq_map = {}
for i in range(1, len(vals)):
for h, heq in get_value_map(vals[:i]).iteritems():
for t, teq in get_value_map(vals[i:]).iteritems():
eq_map[h + t] = "(" + heq + "+" + teq + ")"
eq_map[h - t] = "(" + heq + "-" + teq + ")"
eq_map[h * t] = "(" + heq + "*" + teq + ")"
if t != 0 and h % t == 0:
eq_map[h / t] = "(" + heq + "/" + teq + ")"
return eq_map
all_vals = get_value_map(range(1, 10))
for i in range(1900, 2101):
print i, all_vals[i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment