Created
March 30, 2016 03:40
-
-
Save tklee1975/4867f6b622b985dd5c7f60aab0a7e839 to your computer and use it in GitHub Desktop.
Solution to Math Quiz (A + B ... + H = PPP)
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
| #!/usr/bin/python | |
| # Reference: | |
| # http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python | |
| import itertools; | |
| def test_permutations(): | |
| print "test permutation"; | |
| result = list(itertools.permutations([1, 2, 3])); | |
| print "result:\n%s" % (result); | |
| def testData(value): | |
| row1 = value[0] * 10 + value[1]; | |
| row2 = value[2] * 10 + value[3]; | |
| row3 = value[4] * 10 + value[5]; | |
| row4 = value[6] * 10 + value[7]; | |
| row5 = value[8] * 111; | |
| return ((row1 - row2) == row3) and ((row3 + row4 == row5)); | |
| def do_math(): | |
| testList = list(itertools.permutations(range(1, 10))); | |
| for value in testList: | |
| #print "%s" % str(value); | |
| if(testData(value)): | |
| print "%s" % str(value); | |
| # Main | |
| #test_permutations(); | |
| do_math(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment