-
Notifications
You must be signed in to change notification settings - Fork 2
/
fileRader.go
77 lines (70 loc) · 1.25 KB
/
fileRader.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"fmt"
"os"
"bufio"
"io"
)
var m = make(map[string]string)
func getAccountNumbers(path string) string{
file, err := os.Open(path)
var numbers string
if(err != nil){
fmt.Println(err)
}
bufferedReader := bufio.NewReader(file)
count := 0
var lines []string
for{
str, bferror := bufferedReader.ReadString('\n')
if count == 3 {
numbers = numbers+getAccountNumber(lines)+"\n"
lines = []string{}
count = 0
continue
}
if bferror != nil{
if bferror == io.EOF {
break
}
fmt.Println(bferror)
}
lines = append(lines, str)
count = count+1
}
file.Close()
return numbers
}
func getAccountNumber(lines []string) string{
init := 0
ocrNum := ""
accountNo := ""
for i:=0 ; i<9 ; i++{
for _, val := range lines{
ocrNum = ocrNum + val[init:init+3]
}
init = init+3
accountNo = accountNo+getNumber(ocrNum)
ocrNum=""
}
return accountNo
}
func getNumber(key string) string{
return m[key]
}
func initialize(){
m[" _ | ||_|"] = "0"
m[" | |"] = "1"
m[" _ _||_ "] = "2"
m[" _ _| _|"] = "3"
m[" |_| |"] = "4"
m[" _ |_ _|"] = "5"
m[" _ |_ |_|"] = "6"
m[" _ | |"] = "7"
m[" _ |_||_|"] = "8"
m[" _ |_| _|"] = "9"
}
func main(){
initialize()
fmt.Println(getAccountNumbers("ocr.txt"))
}