How to create a numeric system?

Asked

Viewed 1,367 times

2

Situation

I recently received a challenge in college to do :

From the decimal system 0123456789, using only the numbers that mirrored can still be read find the thousandth number of this system.

Example 8 will be the 5th number, 25 the 17th.

Developing

Numbers accepted : 0125689

0   1   2   5   6   8   9
0   1   2   3   4   5   6

10  11  12  15  16  18  19
7   8   9   10  11  12  13

20  21  22  25  26  28  29
14  15  16  17  18  19  20

My proposal

Create a base 7 numeric system with these "characters".

Problem

It does not follow the same pattern of base conversion, would be more for Roman numerals (a more complex tact).
By adding up 1+2 the result is 5, 9+5 = 12

Question

How to computationally manage this system, say I want to add 25+18. Or any other example.

Obs

I extrapolated a little bit the challenge, which would just be to do with a loop removing the numbers not allowed, but I think it’s a good study.

Research

Non-decimal Numbering Systems
Notions of Numbering System

1 answer

2


Analyzing again I found that my idea is in fact about base 7 itself, only with a conversion at the end.

Analogy

If I need to create a basis with 0125689 would be the same as creating a abcdefg.
With this in mind I noticed that the issue, are not with characters involved, but rather how many.

Solution

This way the base conversion logic is maintained.

inserir a descrição da imagem aqui

What is done after this is just a normal character conversion. The same way I would convert :

a => 0, b => 1, c => 2, d => 5, e => 6, f => 8, g => 9

Royal :

0 => 0, 1 => 1, 2 => 2, 3 => 5, 4 => 6, 5 => 8, 6 => 9

Code

var tot = 1000;
var base = 7;
var rest = [];

console.log('Numero',tot,'(10)')

while(tot>base){
	rest.push(tot%base);
	tot = Math.floor(tot/base);
}
var result = tot+rest.reverse().join('')+"";
console.log('normal', result, '(7)');

var convert = {	3 : 5, 4 : 6, 5 : 8, 6 : 9 }
for(var i in convert){
	var r = convert[i];
	result = result.replace(new RegExp(i, 'g'),r);
}
console.log('result', result, '(7) => convertido');

Auxiliary reading

Arithmetic in Non-decimal Bases

Browser other questions tagged

You are not signed in. Login or sign up in order to post.