have lib function take map instead of list
This commit is contained in:
@@ -28,21 +28,37 @@ import (
|
||||
var modulus string
|
||||
var tpf []string
|
||||
|
||||
func count(tpf []string) map[string]*big.Int {
|
||||
counter := make(map[string]*big.Int)
|
||||
for _, s := range tpf {
|
||||
count, ok := counter[s]
|
||||
if ok {
|
||||
count.Add(count, big.NewInt(1))
|
||||
} else {
|
||||
counter[s] = big.NewInt(1)
|
||||
}
|
||||
}
|
||||
|
||||
return counter
|
||||
}
|
||||
|
||||
func primitiveRoot(cmd *cobra.Command, args []string) {
|
||||
m, ok := new(big.Int).SetString(modulus, 10)
|
||||
if !ok {
|
||||
log.Fatal("invalid input " + modulus)
|
||||
}
|
||||
|
||||
factors := count(tpf)
|
||||
|
||||
root := new(big.Int)
|
||||
var err error
|
||||
if len(tpf) == 0 {
|
||||
if len(factors) == 0 {
|
||||
root, err = lib.PrimitiveRoot(m)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
root, err = lib.PrimitiveRootFast(m, tpf)
|
||||
root, err = lib.PrimitiveRootFast(m, factors)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user