Skip to content

Instantly share code, notes, and snippets.

@grahamannett
Last active August 15, 2018 00:55
Show Gist options
  • Save grahamannett/da439bfce398e5819154fc8dcb28c1e0 to your computer and use it in GitHub Desktop.
Save grahamannett/da439bfce398e5819154fc8dcb28c1e0 to your computer and use it in GitHub Desktop.
find most repeating int
package main
import (
"fmt"
"os"
"sort"
)
type kv struct {
Key string
Value int
}
func main() {
b := make(map[string]int)
for _, num := range os.Args[1:] {
if _, ok := b[num]; ok {
b[num]++
} else {
b[num] = 1
}
}
var ss []kv
for k, v := range b {
ss = append(ss, kv{k, v})
}
sort.Slice(ss, func(i, j int) bool {
return ss[i].Value > ss[j].Value
})
fmt.Println(ss[0])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment