-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10 Row Abacus
129 lines (118 loc) · 4.03 KB
/
10 Row Abacus
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#########################################################################
# 10-row School abacus
# by
# Michael H
#########################################################################
# Description partially extracted from from wikipedia
#
# Around the world, abaci have been used in pre-schools and elementary
#
# In Western countries, a bead frame similar to the Russian abacus but
# with straight wires and a vertical frame has been common (see image).
# Helps schools as an aid in teaching the numeral system and arithmetic
#
# |00000***** | row factor 1000000000
# |00000***** | row factor 100000000
# |00000***** | row factor 10000000
# |00000***** | row factor 1000000
# |00000***** | row factor 100000
# |00000***** | row factor 10000
# |00000***** | row factor 1000
# |00000**** *| row factor 100 * 1
# |00000*** **| row factor 10 * 2
# |00000** ***| row factor 1 * 3
# -----------
# Sum 123
#
# Each row represents a different row factor, starting with x1 at the
# bottom, ascending up to x1000000000 at the top row.
######################################################################
# TASK:
# Define a procedure print_abacus(integer) that takes a positive integer
# and prints a visual representation (image) of an abacus setup for a
# given positive integer value.
#
# Ranking
# 1 STAR: solved the problem!
# 2 STARS: 6 < lines <= 9
# 3 STARS: 3 < lines <= 6
# 4 STARS: 0 < lines <= 3
def print_abacus(value):
# Protection against numbers that are too large for an abacus
#if value > 999999999:
# print "Too big!"
# print "============END============="
# return
# Variables for position and length to be used in the loop
# print str(value) + " value before reversing"
value = str(value)#[::-1]
# print value + " value after reversing...if I reveresed"
length = len(value) # Length is now an INT
position = 0
#print (str(length)) + " is the length" # Debugging
# Fill the rest of the abacus lines not used
templength = length
while templength <= 9:
print "|00000***** |"
templength += 1
# Loop to print 0 * each number in the Input value. New line for each.
p1= "|"
p2= "00000*****"
p3= "|"
ball= "*"
while position < length:
## Print the normal line if its zero
#print value[position] #Debugging
if value[position] == "0":
print "|00000***** |" + '\n'
#print str(position) + " is the position" # Debugging
#print value[position] + " is the number in this position" # Debugging
else:
line = "0" * int(value[position]) # The position value in zeros temporarily
#print line # Debugging
#print p2 # Debugging
#print value + " value" # Debugging
#print 10-(10-int(value)) # Debugging
answer = line + " " + p2[10-(10-int(value[position]))::]
print p1 + answer + p3
position += 1
print ""
#print "============END============="
# Now build in a way for it to fill all 10 lines of the abacus.
### TEST CASES
print "Abacus showing 0:"
print_abacus(0)
#|00000***** |
#|00000***** |
#|00000***** |
#|00000***** |
#|00000***** |
#|00000***** |
#|00000***** |
#|00000***** |
#|00000***** |
#|00000***** |
print "Abacus showing 12345678:"
print_abacus(12345678)
#|00000***** |
#|00000***** |
#|00000**** *|
#|00000*** **|
#|00000** ***|
#|00000* ****|
#|00000 *****|
#|0000 0*****|
#|000 00*****|
#|00 000*****|
print "Abacus showing 1337:"
print_abacus(1337)
#|00000***** |
#|00000***** |
#|00000***** |
#|00000***** |
#|00000***** |
#|00000***** |
#|00000**** *|
#|00000** ***|
#|00000** ***|
#|000 00*****|