Created
August 21, 2019 02:14
-
-
Save maipatana/1f5e217b2f1fcedaf38de920b4cf95a3 to your computer and use it in GitHub Desktop.
โจทย์เลข ป.4
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
import random | |
answers = [] | |
def main(): | |
_ = 'AFBF CGHB DAFG AEAB BCDC' | |
temp = {'A':'0', 'B':'0', 'C':'0', 'D':'0', 'E':'0', 'F':'0', 'G':'0', 'H':'0'} | |
pool = ['0','1','2','3','4','5','6','7','8','9'] | |
for i in temp.keys(): | |
temp[i] = random.choice(pool) | |
pool.remove(temp[i]) | |
_ = _.replace(i, temp[i]) | |
actual = sum([int(i) for i in _.split(' ')[:-1]]) | |
expected = int(_.split(' ')[-1]) | |
if expected not in answers: | |
if actual == expected: | |
answers.append(expected) | |
print('Ans#{} --> actual={}, expected={}, {}'.format(len(answers), | |
actual, | |
expected, | |
['{}={}'.format(k,value) for k,value in temp.items()])) | |
if __name__ == "__main__": | |
while len(answers) < 10: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment