-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.go
More file actions
57 lines (47 loc) · 805 Bytes
/
common.go
File metadata and controls
57 lines (47 loc) · 805 Bytes
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
package main
import (
"os"
"strconv"
s "strings"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func Abs(x int) int {
if x < 0 {
return -x
}
return x
}
func StringToInt(input string) int {
var result, _ = strconv.Atoi(input)
return result
}
func IsSameSign(x int, y int) bool {
return (x >= 0) == (y >= 0)
}
func RemoveIndex(s []string, index int) []string {
ret := make([]string, 0, len(s)-1)
ret = append(ret, s[:index]...)
ret = append(ret, s[index+1:]...)
return ret
}
func GetInputData(path string) []string {
var input, err = os.ReadFile(path)
check(err)
var lines = s.Split(string(input), "\n")
return lines
}
func IsEqual(a, b []int) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}