Skip to content

Commit

Permalink
Update Decimal calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
slysterous committed Apr 19, 2021
1 parent c8e60f3 commit 42a2496
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions numeral.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ import (
// Numeral represents a numeral that is consisted by its digits
// and digit values.
type Numeral struct {
digits *list.List
digitValues []rune
digitPositions map [rune]int
digits *list.List
digitValues []rune
digitPositions map[rune]int
}

// NewNumeral initializes a numeral by providing the initial number in strings
// along with the possible values that each digit can have.
func NewNumeral(values []rune, initial string) (*Numeral, error) {
// initialise a new number.
number := Numeral{
digits: list.New(),
digitValues: values,
digits: list.New(),
digitValues: values,
digitPositions: valuesToPositions(values),
}
// add digits to the number along with their state.
Expand All @@ -61,10 +61,10 @@ func NewNumeral(values []rune, initial string) (*Numeral, error) {
return &number, nil
}

func valuesToPositions(values []rune) map [rune]int {
var pos=map[rune]int{}
for i := 0; i < len(values) ; i++ {
pos[values[i]]=i
func valuesToPositions(values []rune) map[rune]int {
var pos = map[rune]int{}
for i := 0; i < len(values); i++ {
pos[values[i]] = i
}
return pos
}
Expand Down Expand Up @@ -184,7 +184,6 @@ func (n *Numeral) Decimal() int {
// get current ring.
r := d.Value.(*ring.Ring)
// get the index of the ring.
//i := indexOf(r.Value.(rune), n.digitValues)
i := n.digitPositions[r.Value.(rune)]
// Add digit's decimal counterpart to the decimal sum.
dec = dec + i*powInt(len(n.digitValues), di)
Expand Down

0 comments on commit 42a2496

Please sign in to comment.