-
Notifications
You must be signed in to change notification settings - Fork 35
/
validateSAID.go
59 lines (49 loc) · 1.02 KB
/
validateSAID.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"strings"
"fmt"
"strconv"
)
func check(id string) int {
id = strings.Replace(id, " ","", -1)
fmt.Println(id)
if _ , err := strconv.Atoi(id); err != nil{
fmt.Println("It's not a number")
return -1
}
if len(id) != 10{
fmt.Println("Length is not equal to 10")
return -1
}
idtype, _ := strconv.Atoi(id[0:1])
if idtype != 1 && idtype != 2 {
fmt.Println("It's not a valid first index")
return -1
}
// Ain't nobody got time for dat, let's make an array!
idarr := make([]int, len(id))
for c := 0; c < 10; c {
idarr[c], _ = strconv.Atoi(id[c:c 1])
}
sum := 0
//Where the real business comes in
for c := 0; c < 10; c {
if c % 2 == 0{
ZF0dd := fmt.Sprintf("d",idarr[c] * 2)
// A work around cuz again ain't nobody got time for dat
fvalue,_ := strconv.Atoi(ZF0dd[0:1])
svalue, _:= strconv.Atoi(ZF0dd[1:2])
sum = fvalue svalue
}else{
sum = idarr[c]
}
}
if sum % 10 !=0 {
fmt.Println("NOPE")
return -1
}
return idtype
}
func main(){
check("1000000000")
}