|
@@ -0,0 +1,45 @@
|
|
|
|
|
+package main
|
|
|
|
|
+
|
|
|
|
|
+import (
|
|
|
|
|
+ "bufio"
|
|
|
|
|
+ "fmt"
|
|
|
|
|
+ "log"
|
|
|
|
|
+ "os"
|
|
|
|
|
+ "strconv"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+func readInput(file *os.File) map[int]int {
|
|
|
|
|
+ scanner := bufio.NewScanner(file)
|
|
|
|
|
+ frequencies := make(map[int]int)
|
|
|
|
|
+
|
|
|
|
|
+ for scanner.Scan() {
|
|
|
|
|
+ line := scanner.Text()
|
|
|
|
|
+ if line == "" {
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ i, err := strconv.Atoi(line)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ log.Fatal(err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ frequencies[i]++
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return frequencies
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+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)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ frequencies := readInput(file)
|
|
|
|
|
+ fmt.Println(frequencies)
|
|
|
|
|
+}
|