mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-15 15:10:49 +00:00
39 lines
633 B
Go
39 lines
633 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"log"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
// readlines reads lines from stdin.
|
||
|
// it returns them as an array of strings
|
||
|
func readlines() []string {
|
||
|
lines := []string{}
|
||
|
|
||
|
scanner := bufio.NewScanner(os.Stdin)
|
||
|
for scanner.Scan() {
|
||
|
lines = append(lines, scanner.Text())
|
||
|
}
|
||
|
|
||
|
if err := scanner.Err(); err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
return lines
|
||
|
}
|
||
|
|
||
|
// buildGraph parses lines into costs for graph
|
||
|
func buildGraph(lines []string) [][]int {
|
||
|
graph := make([][]int, len(lines))
|
||
|
|
||
|
for i, line := range lines {
|
||
|
graph[i] = make([]int, len(line))
|
||
|
for j, r := range line {
|
||
|
graph[i][j] = int(r - '0')
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return graph
|
||
|
}
|