You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

package main
import (
"io/ioutil"
"strconv"
"strings"
)
func readDataset(path string, lineSeparation string, valueSeparation string) [][][]int {
var dataset [][][]int
b, err := ioutil.ReadFile(path)
check(err)
str := string(b)
str = strings.Replace(str, "\r", "", -1)
lines := strings.Split(str, lineSeparation)
for _, v1 := range lines {
params := strings.Split(v1, valueSeparation)
var datasetLine [][]int
var datasetLineEntry []int
var lastLineValue []int
for k2, v2 := range params {
value, err := strconv.Atoi(v2)
check(err)
if k2 < len(params)-1 {
datasetLineEntry = append(datasetLineEntry, value)
} else {
lastLineValue = append(lastLineValue, value)
}
}
datasetLine = append(datasetLine, datasetLineEntry)
datasetLine = append(datasetLine, lastLineValue)
dataset = append(dataset, datasetLine)
}
return dataset
}
func readInputs(path string, lineSeparation string, valueSeparation string) [][]int {
var dataset [][]int
b, err := ioutil.ReadFile(path)
check(err)
str := string(b)
str = strings.Replace(str, "\r", "", -1)
lines := strings.Split(str, lineSeparation)
for _, v1 := range lines {
params := strings.Split(v1, valueSeparation)
//var datasetLine [][]int
var datasetLineEntry []int
for _, v2 := range params {
value, err := strconv.Atoi(v2)
check(err)
datasetLineEntry = append(datasetLineEntry, value)
}
//datasetLine = append(datasetLine, datasetLineEntry)
dataset = append(dataset, datasetLineEntry)
}
return dataset
}