summaryrefslogtreecommitdiff
path: root/flood.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-12-20 22:47:43 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-12-20 22:47:43 +0100
commit6cdda9594a16182816a862fb253ec8ccecf763f0 (patch)
tree58ad6e77af36ef93055914f8a2d9565391729ec4 /flood.go
parent579f3c771bcebed3e9b145c1cb0f7d7054a94e37 (diff)
cleanup
Diffstat (limited to 'flood.go')
-rw-r--r--flood.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/flood.go b/flood.go
index c9865ed..c741bd6 100644
--- a/flood.go
+++ b/flood.go
@@ -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