Skip to content

Instantly share code, notes, and snippets.

@SerkanSipahi
Created February 8, 2017 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SerkanSipahi/35d29020b709ecdd72bc620831965b5a to your computer and use it in GitHub Desktop.
Save SerkanSipahi/35d29020b709ecdd72bc620831965b5a to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"os"
"fmt"
)
func main(){
/**
* Description in the book about whats going on:
* ========================================================
* This prints the text of each line that appears more than
* once in the standard input, preceded by its count
* ========================================================
**/
/**
* Issue: it does not do whats described (see above). What going wrong?
**/
/**
* Code: copy past
**/
counts := make(map[string]int)
input := bufio.NewScanner(os.Stdin)
for input.Scan() {
counts[input.Text()]++
}
for line, n := range counts {
fmt.Printf("%d\t%s\n", n, line)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment