summaryrefslogtreecommitdiff
path: root/flood.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2019-07-06 17:17:46 +0200
committerDimitri Sokolyuk <demon@dim13.org>2019-07-06 17:17:46 +0200
commit1d2ca509c77cbb2af0475b1319cd840f8ce9a1d0 (patch)
tree05a838baaf4f96fbcce03d06090a2403ee56c878 /flood.go
parent87e820722cf02054225b47a58f97d0824118292f (diff)
Split in packages
Diffstat (limited to 'flood.go')
-rw-r--r--flood.go62
1 files changed, 0 insertions, 62 deletions
diff --git a/flood.go b/flood.go
deleted file mode 100644
index d7fd05d..0000000
--- a/flood.go
+++ /dev/null
@@ -1,62 +0,0 @@
-package main
-
-import (
- "math"
- "sort"
- "strings"
- "unicode"
- "unicode/utf8"
-)
-
-const (
- runes = 6
- words = 6
- black = "\u24B6\u262D\u272F\u262E\u2721\u5350\u534D\u2719\u0FD5\u0FD6\u16CB\u16CB\uA5A6\u0FD7\u0FD8"
-)
-
-func entropy(s string) (e float64) {
- n := make(map[rune]float64)
- for _, r := range s {
- n[r] += 1 / float64(len(s))
- }
- for _, v := range n {
- e -= v * math.Log2(v)
- }
- return e
-}
-
-func isFlood(s string) bool {
- if strings.ContainsAny(s, black) {
- return true
- }
- if utf8.RuneCountInString(s) <= runes {
- return false
- }
- if v := strings.Fields(s); len(v) >= words {
- return commonWord(v) >= len(v)/2
- }
- return entropy(s) <= 1
-}
-
-func commonWord(v []string) int {
- m := make(map[string]int)
- for _, w := range v {
- m[w]++
- }
- l := make([]int, len(m))
- for _, n := range m {
- l = append(l, n)
- }
- sort.Sort(sort.Reverse(sort.IntSlice(l)))
- return l[0]
-}
-
-func noSpaceCompare(a, b string) bool {
- dropSpaces := func(r rune) rune {
- if unicode.IsSpace(r) {
- return -1
- }
- return r
- }
- return strings.Map(dropSpaces, a) == strings.Map(dropSpaces, b)
-}