-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
71 lines (57 loc) · 1.24 KB
/
utils.go
File metadata and controls
71 lines (57 loc) · 1.24 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
package bbchallenge
import (
"strings"
uuid "github.com/nu7hatch/gouuid"
)
func GetRunName() string {
id, _ := uuid.NewV4()
split := strings.Split(id.String(), "-")
return "run-" + split[len(split)-1]
}
func MaxI(a int, b int) int {
if a > b {
return a
}
return b
}
func MinI(a int, b int) int {
if a < b {
return a
}
return b
}
// Following 3 functions are used by heuristics deciders
// Equivalent of l[beginIndex::sampleStep] in python
func SampleList(l []int, beginIndex int, sampleStep int) (toReturn []int) {
for i := beginIndex; i < len(l); i += sampleStep {
toReturn = append(toReturn, l[i])
}
return toReturn
}
func AllZero(l []int) bool {
for i := range l {
if l[i] != 0 {
return false
}
}
return true
}
// Discrete difference is computing sequence ofl[i+1]-l[i]
func discreteDifferenceOperator(l []int) (toReturn []int) {
if len(l) < 2 {
return toReturn
}
for i := 1; i < len(l); i += 1 {
toReturn = append(toReturn, l[i]-l[i-1])
}
return toReturn
}
// Return the nth discrete difference of l
func DiscreteDifference(l []int, n int) (toReturn []int) {
toReturn = make([]int, len(l))
copy(toReturn, l)
for i := 0; i < n; i += 1 {
toReturn = discreteDifferenceOperator(toReturn)
}
return toReturn
}