Browse Source

Able to build graph

Piotr Czajkowski 1 year ago
parent
commit
b02de82823
1 changed files with 18 additions and 1 deletions
  1. 18 1
      16/code.go

+ 18 - 1
16/code.go

@@ -53,6 +53,22 @@ func readInput(file *os.File) map[string]valve {
 	return valves
 }
 
+type path struct {
+	from string
+	to   string
+}
+
+func buildGraph(valves map[string]valve) []path {
+	var graph []path
+	for key, value := range valves {
+		for i := range value.connections {
+			graph = append(graph, path{key, value.connections[i]})
+		}
+	}
+
+	return graph
+}
+
 func main() {
 	if len(os.Args) < 2 {
 		log.Fatal("You need to specify a file!")
@@ -66,5 +82,6 @@ func main() {
 	}
 
 	valves := readInput(file)
-	fmt.Println(valves)
+	graph := buildGraph(valves)
+	fmt.Println(graph)
 }