Created
July 21, 2010 03:57
-
-
Save elucid/484036 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
| 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