-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (45 loc) · 1.04 KB
/
main.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
package main
import (
"strings"
"strconv"
"fmt"
"os"
"io/ioutil"
)
func main() {
//run_kruskals()
sequence := []int{0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15}
fmt.Println(longestIncreasingSub(sequence))
}
func run_kruskals() {
// verify number of command line args
if len(os.Args) < 2 {
os.Exit(1)
}
filename := os.Args[1]
contents, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
data := string(contents)
// extract the n-grid dimension and edges
parts := strings.Split(data, ":")
raw_dim, raw_edges := parts[0], parts[1]
dim64, err := strconv.ParseInt(raw_dim, 10, 32)
dim := int(dim64)
var edges []Edge
for _, x := range strings.Split(strings.Trim(raw_edges, "()"), "),(") {
edge := strings.Split(x, ",")
start, err:= strconv.Atoi(edge[0])
end, err := strconv.Atoi(edge[1])
weight, err := strconv.Atoi(edge[2])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
edges = append(edges, Edge{start, end, weight})
}
mcst := kruskal(edges, dim)
fmt.Println(mcst)
}