diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2016-12-20 22:47:43 +0100 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2016-12-20 22:47:43 +0100 |
commit | 6cdda9594a16182816a862fb253ec8ccecf763f0 (patch) | |
tree | 58ad6e77af36ef93055914f8a2d9565391729ec4 /flood.go | |
parent | 579f3c771bcebed3e9b145c1cb0f7d7054a94e37 (diff) |
cleanup
Diffstat (limited to 'flood.go')
-rw-r--r-- | flood.go | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -7,6 +7,11 @@ import ( "unicode/utf8" ) +const ( + runes = 6 + words = 6 +) + func entropy(s string) (e float64) { n := make(map[rune]float64) for _, r := range s { @@ -15,14 +20,14 @@ func entropy(s string) (e float64) { for _, v := range n { e -= v * math.Log2(v) } - return + return e } func isFlood(s string) bool { - if utf8.RuneCountInString(s) <= 6 { + if utf8.RuneCountInString(s) <= runes { return false } - if v := strings.Fields(s); len(v) >= 6 { + if v := strings.Fields(s); len(v) >= words { return commonWord(v) >= len(v)/2 } return entropy(s) <= 1 |