Compare commits

6 Commits

4 changed files with 82 additions and 58 deletions

1
.gitignore vendored
View File

@@ -8,6 +8,7 @@
*.dll
*.so
*.dylib
*.zip
# Test binary, built with `go test -c`
*.test

View File

@@ -14,32 +14,33 @@ UPC
2.0006670732e+11
2.0006955667e+11
2.0007279122e+11
0075849385857
2.0007279132e+11
2.0007279138e+11
2.0007279147e+11
2.0007295014e+11
2.0007918627e+11
2.0007934374e+11
2.0008145164e+11
2.0008163031e+11
2.0010695322e+11
2.0015648868e+11
2.0015705634e+11
2.0016809582e+11
2.0016897944e+11
2.0017249002e+11
2.0017733455e+11
2.001777807e+11
2.0017778823e+11
3.2758280554e+11
3.3758288992e+11
3.5758284014e+11
3.5758284353e+11
3.5758285003e+11
4.7703952221e+11
4.770395222e+11
4.8200007703e+11
4.8200007704e+11
4.8200007709e+11
6.4758280292e+11
6.475828047e+11
2.0007279138E+11
2.0007279147E+11
2.0007295014E+11
2.0007918627E+11
2.0007934374E+11
2.0008145164E+11
2.0008163031E+11
2.0010695322E+11
2.0015648868E+11
2.0015705634E+11
2.0016809582E+11
2.0016897944E+11
2.0017249002E+11
2.0017733455E+11
2.001777807E+11
2.0017778823E+11
3.2758280554E+11
3.3758288992E+11
3.5758284014E+11
3.5758284353E+11
3.5758285003E+11
4.7703952221E+11
4.770395222E+11
4.8200007703E+11
4.8200007704E+11
4.8200007709E+11
6.4758280292E+11
6.475828047E+11

10
isNumeric.go Normal file
View File

@@ -0,0 +1,10 @@
package main
import (
"regexp"
)
func isNumeric(s string) bool {
match, _ := regexp.MatchString("^[0-9]+$", s)
return match
}

72
main.go
View File

@@ -71,39 +71,51 @@ func main() {
}))
for _, upc := range upcs {
checkForNonStartingNumber := regex.MatchString(upc)
if len(upc) > 0 {
checkForNonStartingNumber := regex.MatchString(upc)
if checkForNonStartingNumber {
gtins = append(gtins, upc)
continue
}
if isNumeric(upc) {
gtins = append(gtins, upc)
continue
}
// Lower case the E
upc = strings.ToLower(upc)
// Split scientific notation at the e+ point
upcArray := strings.Split(upc, "e+")
fmt.Println(upcArray)
// Create separate variables for the split values
workingUpc := upcArray[0]
upcENumber := upcArray[1]
// At one to the scientific notation length to allow for the decimal point to be removed
upcLength, err := strconv.Atoi(upcENumber)
Error(err)
upcLength = upcLength + 1
// Remove the decimal point
workingUpc = strings.ReplaceAll(workingUpc, ".", "")
// Append 0 to UPC to match notation length
for len(workingUpc) < upcLength {
workingUpc = workingUpc + "0"
}
upc = workingUpc
if checkForNonStartingNumber {
gtins = append(gtins, upc)
continue
checkBar.Add(1)
} else {
gtins = append(gtins, "")
checkBar.Add(1)
}
// Split scientific notation at the e+ point
upcArray := strings.Split(upc, "e+")
fmt.Println(upcArray)
// Create separate variables for the split values
workingUpc := upcArray[0]
upcENumber := upcArray[1]
// At one to the scientific notation length to allow for the decimal point to be removed
upcLength, err := strconv.Atoi(upcENumber)
Error(err)
upcLength = upcLength + 1
// Remove the decimal point
workingUpc = strings.ReplaceAll(workingUpc, ".", "")
// Append 0 to UPC to match notation length
for len(workingUpc) < upcLength {
workingUpc = workingUpc + "0"
}
upc = workingUpc
gtins = append(gtins, upc)
checkBar.Add(1)
}
answerBar := progressbar.NewOptions(len(gtins),