-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpizza.go
More file actions
89 lines (80 loc) · 1.41 KB
/
pizza.go
File metadata and controls
89 lines (80 loc) · 1.41 KB
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
78
79
80
81
82
83
84
85
86
87
package pizza
import (
"os"
"github.com/sirupsen/logrus"
"bufio"
"strings"
"strconv"
)
func check(e error) {
if e != nil {
logrus.Error(e.Error())
panic(e)
}
}
type Pizza struct{
R int8 //number of row
C int8 //number of column
L int8 //minimun number of each cell in slice
H int8 //max slice cell size
Cells []Cell
}
func New(path string) (p Pizza,err error) {
inFile, err := os.Open(path)
if err!=nil {
return p, err
}
defer inFile.Close()
scanner := bufio.NewScanner(inFile)
scanner.Split(bufio.ScanLines)
lineindex := 0
for scanner.Scan() {
if lineindex==0 {
line := strings.Split(scanner.Text(), " ")
i, err := strconv.ParseInt(line[0],10,8)
if err != nil {
return p, err
}
p.R = int8(i)
i, err = strconv.ParseInt(line[1],10,8)
if err != nil {
return p, err
}
p.C = int8(i)
i, err = strconv.ParseInt(line[2],10,8)
if err != nil {
return p, err
}
p.L = int8(i)
i, err = strconv.ParseInt(line[3],10,8)
if err != nil {
return p, err
}
p.H = int8(i)
lineindex+=1
continue
}
line := scanner.Text()
for index:=0; index< len(line); index++ {
c:=Cell{
x: lineindex-1,
y: index,
taken:false,
}
if string(line[index]) == "T"{
c.val=false
}else{
c.val=true
}
p.Cells = append(p.Cells,c)
}
lineindex+=1
}
return p,nil
}
type Cell struct {
x int
y int
taken bool
val bool //T=false M=true
}