Implemented function to gather the different items
This commit is contained in:
parent
1c7bdb3486
commit
96dfe53951
@ -20,8 +20,24 @@ func PrintAndWait(x ...any) {
|
|||||||
fmt.Scanln()
|
fmt.Scanln()
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMaps(ss [][]string, nn [][]int) {
|
func GetMaps(scanner *bufio.Scanner, re *regexp.Regexp) [][]int {
|
||||||
|
// Scan until there is an empty line
|
||||||
|
var tempNums int = 0
|
||||||
|
tempArray := make([][]int, 0)
|
||||||
|
PrintAndWait(tempArray)
|
||||||
|
for i := 0; scanner.Scan() && scanner.Text() != ""; i++ {
|
||||||
|
tempString := re.FindAllString(scanner.Text(), -1)
|
||||||
|
temp := make([]int, 0)
|
||||||
|
for j := range tempString {
|
||||||
|
tempNums, _ = strconv.Atoi(tempString[j])
|
||||||
|
temp = append(temp, tempNums)
|
||||||
|
}
|
||||||
|
tempArray = append(tempArray, temp)
|
||||||
|
PrintAndWait(tempArray)
|
||||||
|
}
|
||||||
|
// Prepare for next line
|
||||||
|
scanner.Scan()
|
||||||
|
return tempArray
|
||||||
}
|
}
|
||||||
|
|
||||||
func main () {
|
func main () {
|
||||||
@ -33,8 +49,8 @@ func main () {
|
|||||||
renum := regexp.MustCompile("[0-9]+")
|
renum := regexp.MustCompile("[0-9]+")
|
||||||
|
|
||||||
var seeds []int
|
var seeds []int
|
||||||
//var soils, fertilizers, waters, lights, temperatures,
|
var soils, fertilizers, waters, lights, temperatures,
|
||||||
// humidities, locations [][]int
|
humidities, locations [][]int
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
// We know that the seeds only have one row
|
// We know that the seeds only have one row
|
||||||
scanner.Scan()
|
scanner.Scan()
|
||||||
@ -48,5 +64,12 @@ func main () {
|
|||||||
// We know we have an empty string and just a title, skip them
|
// We know we have an empty string and just a title, skip them
|
||||||
scanner.Scan()
|
scanner.Scan()
|
||||||
scanner.Scan()
|
scanner.Scan()
|
||||||
|
// Should be possible to just pass the scanner
|
||||||
|
soils = GetMaps(scanner, renum)
|
||||||
|
fertilizers = GetMaps(scanner, renum)
|
||||||
|
waters = GetMaps(scanner, renum)
|
||||||
|
lights = GetMaps(scanner, renum)
|
||||||
|
temperatures = GetMaps(scanner, renum)
|
||||||
|
humidities = GetMaps(scanner, renum)
|
||||||
|
locations = GetMaps(scanner, renum)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user