Created
November 23, 2016 11:08
-
-
Save natmchugh/9857a7bf57cbec4a07882ee665e8c761 to your computer and use it in GitHub Desktop.
Script what I wrote to learn to recognise numbers on a soroban
This file contains 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 re, random, operator | |
random.seed() | |
def get_random_int(): | |
return random.randint(1,999) | |
def to_soroban(number): | |
digits = { | |
0: "**** || *", | |
1: "*** *|| *", | |
2: "** **|| *", | |
3: "* ***|| *", | |
4: " ****|| *", | |
5: "**** ||* ", | |
6: "*** *||* ", | |
7: "** **||* ", | |
8: "* ***||* ", | |
9: " ****||* ", | |
} | |
soroban = [] | |
number_string = "{:0>13.4f}".format(number) | |
i = 0 | |
for ch in number_string: | |
if ch == '.': | |
continue | |
digit = digits[int(ch)] | |
if i % 3 == 1: | |
soroban.append(re.sub('\|\|', '.', digit)) | |
else: | |
soroban.append(re.sub('\|\|', '-', digit)) | |
i += 1 | |
return soroban | |
def transform_text(cols): | |
numRows = len(cols[0]) | |
rows = '' | |
for i in range(0, numRows): | |
row = '' | |
for ch in cols: | |
row += ch[numRows - 1 - i] | |
rows += row+"\n" | |
return rows | |
numberOfQs = 10 | |
for i in range(1, numberOfQs+1): | |
a = get_random_int() | |
print "Question %d)" % (i) | |
question = transform_text(to_soroban(a)) | |
while int(raw_input(question)) != int(a): | |
print "Nope\n" | |
print "Correct\n" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment