move to case sensitive letters

This commit is contained in:
Arnas Udovic 2024-09-20 10:13:21 +03:00
parent 7823443488
commit 240b9cbbe6
3 changed files with 22 additions and 12 deletions

View file

@ -2,4 +2,10 @@
[![Build Status](https://drone.arns.lt/api/badges/zordsdavini/abcex/status.svg)](https://drone.arns.lt/zordsdavini/abcex) [![Build Status](https://drone.arns.lt/api/badges/zordsdavini/abcex/status.svg)](https://drone.arns.lt/zordsdavini/abcex)
Computing system based on the number 36 Computing system based on the number 62
## History
**Version 1** - based on 32: number and case insensitive letters
**Version 2** - based on 62: number and case sensitive letters

View file

@ -7,10 +7,14 @@ import (
var decToAbcex = map[int]string{ var decToAbcex = map[int]string{
0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7",
8: "8", 9: "9", 10: "a", 11: "b", 12: "c", 13: "d", 14: "e", 8: "8", 9: "9", 10: "A", 11: "B", 12: "C", 13: "D", 14: "E",
15: "f", 16: "g", 17: "h", 18: "i", 19: "j", 20: "k", 21: "l", 15: "F", 16: "G", 17: "H", 18: "I", 19: "J", 20: "K", 21: "L",
22: "m", 23: "n", 24: "o", 25: "p", 26: "q", 27: "r", 28: "s", 22: "M", 23: "N", 24: "O", 25: "P", 26: "Q", 27: "R", 28: "S",
29: "t", 30: "u", 31: "v", 32: "w", 33: "x", 34: "y", 35: "z", 29: "T", 30: "U", 31: "V", 32: "W", 33: "X", 34: "Y", 35: "Z",
36: "a", 37: "b", 38: "c", 39: "d", 40: "e", 41: "f", 42: "g",
43: "h", 44: "i", 45: "j", 46: "k", 47: "l", 48: "m", 49: "n",
50: "o", 51: "p", 52: "q", 53: "r", 54: "s", 55: "t", 56: "u",
57: "v", 58: "w", 59: "x", 60: "y", 61: "z",
} }
var abcexToDec = flipMap() var abcexToDec = flipMap()
@ -45,8 +49,8 @@ func Encode(number int64) string {
} }
for number > 0 { for number > 0 {
result = fmt.Sprintf("%s%s", decToAbcex[int(number%36)], result) result = fmt.Sprintf("%s%s", decToAbcex[int(number%62)], result)
number /= 36 number /= 62
} }
if negative { if negative {
@ -68,7 +72,7 @@ func Decode(str string) int64 {
str = reverse(str) str = reverse(str)
for i, c := range str { for i, c := range str {
result = int64(math.Pow(36, float64(i)))*int64(abcexToDec[string(c)]) + result result = int64(math.Pow(62, float64(i)))*int64(abcexToDec[string(c)]) + result
} }
if negative { if negative {

View file

@ -5,13 +5,13 @@ import (
) )
func TestEncode(t *testing.T) { func TestEncode(t *testing.T) {
if Encode(12345) != "9ix" { if Encode(12345) != "3D7" {
t.Fatal("Failed encoding") t.Fatal("Failed encoding")
} }
} }
func TestDecode(t *testing.T) { func TestDecode(t *testing.T) {
if Decode("9ix") != 12345 { if Decode("3D7") != 12345 {
t.Fatal("Failed decoding") t.Fatal("Failed decoding")
} }
} }
@ -27,11 +27,11 @@ func TestZero(t *testing.T) {
} }
func TestNegative(t *testing.T) { func TestNegative(t *testing.T) {
if Encode(-20) != "-k" { if Encode(-20) != "-K" {
t.Fatal("Failed negative encoding:", Encode(-20)) t.Fatal("Failed negative encoding:", Encode(-20))
} }
if Decode("-ab") != -371 { if Decode("-ab") != -2269 {
t.Fatal("Failed negative decoding", Decode("-ab")) t.Fatal("Failed negative decoding", Decode("-ab"))
} }
} }