(My Python Soroban)
- Introduction to Python programming
- Introduction to object oriented programming
- Math training
- Understanding and using the Soroban (or Abacus; The Soroban is a special japanese version of it.)
The goal of this project is to write a console based python program which can visualize numbers as constellations of the tokens of an abstracted Soroban (other Abacus styles may be implemented too). In addition it will create simple mathematical terms using addition, substraction, multiplication and division which can be scaled to different difficulties.
The idea is to document the progress of this project on this page. That includes the thinking processes to solve the tasks you will come across and how the solutions in python look like. This project is supposed to use only the basic python language with its standard library.
If you want to know more about the device itself follow this Link: wikipedia
From the development point of view, we are interested in how the actual Soroban is built (of what parts it consists of) and how it is being used (how to display numbers). A Soroban consists of multiple columns with 5 tokens in each column. The upmost token is seperated from the remaining four. A single column is used to display up to ten values (0 to 9). If you want to set the column to a different value than zero you move the tokens into the correct position. The four lower tokens represent the values 1 to 4. The upper token represents ONLY the number 5! If no token is moved the value of the column is zero. If you want to set a higher value than 5 for the column you must set the token representing the number 5 and an additional amount of lower tokens. Basically you are calculating 5 + 1, 5 + 2 ... 5 + 4. If you wanted to set a higer value than 9 you would need an additional column! So with two columns you could represent value up to 99, with three columns up to 999 and so on.
When we are talking of calculating with a Soroban, we actually mean that we store the values which we receive inbetween calculation steps. The cool thing is that we can do addition an substraction with one column at a time. There are also techniques for muliplication and division but we won't cover them here.
Turning a column into code
We have seen that a Soroban consicts of a number of columns which themselves behave all in the same manner. So the columns are elements of the soroban. Each column looks and behaves the same and we can build different sized Sorobans by adding additional columns. That's what we basically do now in code.
First we have to build a single column which we then duplicate a number of times so it fits the number it should display or our imaination. But because we have a computer screen we have to think about how we can display the column on the screen.
Well here would be some research required but we'll take a shortcut. The computer can not only display characters and numbers. It can also display some other odd signs and we will use one of them as a representation of a token. Because the computer internally stores all characters and numbers as a numerical code we just have to tell him which code exactly we want to use. In this case we want to use character 219 (or in hexadecimal: DB).
It looks like this: █
To test this in python you can start the interpreter and type:
The builtin function chr converts the number into the correspoding character which then is the parameter for the print function and gets printed to the screen.
If you want to play with it: Try writing a loop from value 0 to 255 and pass the active value to the chr function and print the result on the screen.