|
@@ -0,0 +1,51 @@
|
|
|
|
+package main
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "bufio"
|
|
|
|
+ "fmt"
|
|
|
|
+ "log"
|
|
|
|
+ "os"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+type pair struct {
|
|
|
|
+ first [2]int
|
|
|
|
+ second [2]int
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func readInput(file *os.File) []pair {
|
|
|
|
+ scanner := bufio.NewScanner(file)
|
|
|
|
+ var pairs []pair
|
|
|
|
+
|
|
|
|
+ for scanner.Scan() {
|
|
|
|
+ line := scanner.Text()
|
|
|
|
+ if line == "" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ current := pair{}
|
|
|
|
+ n, err := fmt.Sscanf(line, "%d-%d,%d-%d", ¤t.first[0], ¤t.first[1], ¤t.second[0], ¤t.second[1])
|
|
|
|
+ if n != 4 || err != nil {
|
|
|
|
+ log.Fatal("Problem reading input:", err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pairs = append(pairs, current)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return pairs
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func main() {
|
|
|
|
+ if len(os.Args) < 2 {
|
|
|
|
+ log.Fatal("You need to specify a file!")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ filePath := os.Args[1]
|
|
|
|
+ file, err := os.Open(filePath)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Fatalf("Failed to open %s!\n", filePath)
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pairs := readInput(file)
|
|
|
|
+ fmt.Println(pairs)
|
|
|
|
+}
|