|
|
@ -32,37 +32,21 @@ func main() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
type letter struct { |
|
|
|
r rune |
|
|
|
count int |
|
|
|
} |
|
|
|
|
|
|
|
func (l letter) String() string { |
|
|
|
return fmt.Sprintf("%v: %d", string(l.r), l.count) |
|
|
|
} |
|
|
|
|
|
|
|
type result struct { |
|
|
|
name string |
|
|
|
h histogram |
|
|
|
} |
|
|
|
|
|
|
|
type results []result |
|
|
|
|
|
|
|
func (r results) Len() int { return len(r) } |
|
|
|
func (r results) Swap(i, j int) { r[i], r[j] = r[j], r[i] } |
|
|
|
func (r results) Less(i, j int) bool { |
|
|
|
if len(r[i].h) == 0 || len(r[j].h) == 0 { |
|
|
|
return false |
|
|
|
} |
|
|
|
return r[i].h[0].count > r[j].h[0].count |
|
|
|
} |
|
|
|
|
|
|
|
type histogram []letter |
|
|
|
|
|
|
|
func (n histogram) Len() int { return len(n) } |
|
|
|
func (n histogram) Swap(i, j int) { n[i], n[j] = n[j], n[i] } |
|
|
|
func (n histogram) Less(i, j int) bool { |
|
|
|
return n[i].count > n[j].count |
|
|
|
type letter struct { |
|
|
|
r rune |
|
|
|
count int |
|
|
|
} |
|
|
|
|
|
|
|
func (l letter) String() string { |
|
|
|
return fmt.Sprintf("%v: %d", string(l.r), l.count) |
|
|
|
} |
|
|
|
|
|
|
|
func freq(in string) histogram { |
|
|
|