New Open-Source Project: Abacus Encoder in the C Programming Language

Hello World! In converting today’s date of “1102022” into abacus-style format, here’s the text output: “(0+1+0+0+0)(0+1+0+0+0)(0+0+0+0+0)(0+1+1+0+0)(0+0+0+0+0)(0+1+1+0+0)(0+1+1+0+0)”.

Today, I decided to finish yesterday’s project, written in the C programming language, and publish it here, as open-source! It’s a simple program, using mathematics to encode a whole number into actual rods on an abacus. My original intention was to continue the project into an actual arithmetic project, but decided to make it “open source”, instead. ☺️

The source code was quickly written in the C computer programming language. I wrote this quick program because there are presently no software applications that outputs in text-based format. Here’s my source code:

// Filename: AbacusEncoder.c
// Encodes a whole number up to 15 digits into equivalent abacus rods.
// Output is text-based for console.

// Notice: Compiler errors exist!

#include<stdio.h>

int abacus(long);

int main(){

// For debugging purposes:
int DEBUG = 0;

long number, digit, divider;
int show = 0;

// Number to Encode
number = 1102022;

divider = 10;
for(int z = 1; z < 15; z++) {
divider *= 10;
}

while(divider != 0) {

if(number > divider) {
digit = (int)(number / divider);
number = number - (digit * divider);

if(DEBUG) {
printf("%d, ", (int)digit);
}
else abacus(digit);

show = 1;

}
else if(show) {
digit = 0;

if(DEBUG) {
printf("%d, ", (int)digit);
}
else abacus(digit);

}
divider /= 10;
}

return 0;

}

abacus(long a) {

printf("(");

if(a < 5) printf("0+");
else {
printf("5+");
a = a - 5;
}

switch(a) {
case 0:
printf("0+0+0+0");
break;

case 1:
printf("1+0+0+0");
break;

case 2:
printf("1+1+0+0");
break;

case 3:
printf("1+1+1+0");
break;

case 4:
printf("1+1+1+1");
break;

default:
printf("ERROR!");
break;
}

printf(")");

}

Feel free to use my code for your programming projects. I’ve coded it in C, but can easily be converted into other computer programming languages, provided you have the necessary compilers, etc.

Thanks for reading my latest blog post! Have a Great Day!

🇵🇭🇺🇸👨‍🦯🦽 📱⌨️📻🎧 📚🪀🧮

Leave a Comment