Created
April 17, 2022 18:26
-
-
Save sekaiwish/3668aa210e23a8e5d78432b8e675d7d2 to your computer and use it in GitHub Desktop.
MHF charID to int
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func pwr(a int, b int) int { | |
return int(math.Pow(float64(a), float64(b))) | |
} | |
func calcID(ID string) int { | |
m := make(map[string]int) | |
m["1"] = 0 | |
m["2"] = 1 | |
m["3"] = 2 | |
m["4"] = 3 | |
m["5"] = 4 | |
m["6"] = 5 | |
m["7"] = 6 | |
m["8"] = 7 | |
m["9"] = 8 | |
m["A"] = 9 | |
m["B"] = 10 | |
m["C"] = 11 | |
m["D"] = 12 | |
m["E"] = 13 | |
m["F"] = 14 | |
m["G"] = 15 | |
m["H"] = 16 | |
m["J"] = 17 | |
m["K"] = 18 | |
m["L"] = 19 | |
m["M"] = 20 | |
m["N"] = 21 | |
m["P"] = 22 | |
m["Q"] = 23 | |
m["R"] = 24 | |
m["T"] = 25 | |
m["U"] = 26 | |
m["V"] = 27 | |
m["W"] = 28 | |
m["X"] = 29 | |
m["Y"] = 30 | |
m["Z"] = 31 | |
var r int | |
for i, c := range ID { | |
r += m[string(c)] * pwr(32, i) | |
} | |
return r | |
} | |
func main() { | |
fmt.Println(calcID("112111")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment