tgpl

The Go Programming Language - Solutions
Log | Files | Refs

commit f7ea670c56c214552b33b32fd1e9a417ece843f6
parent 11bb47c11c60643eed9f8087166bb3b5efaab1e1
Author: zerous Naveen Narayanan <zerous@nocebo.space>
Date:   Fri,  1 Mar 2019 01:22:27 +0100

Add exercise 1.4 solution

Diffstat:
Aexercise-1-4.go | 33+++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+), 0 deletions(-)

diff --git a/exercise-1-4.go b/exercise-1-4.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "io/ioutil" + "os" + "strings" +) + +func main() { + names := "" + counts := make(map[string]int) + for _, filename := range os.Args[1:] { + data, err := ioutil.ReadFile(filename) + if err != nil { + fmt.Fprintf(os.Stderr, "dup3: %v\n", err) + continue + } + for _, line := range strings.Split(string(data), "\n") { + counts[line]++ + + } + for _, n := range counts { + if n > 1 { + names += filename + names += " " + break; + } + } + } + + fmt.Println(names) +}