-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.go
43 lines (38 loc) · 827 Bytes
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
var characterCountMap map[rune]float32
func findAlphabetsFrequency() {
characterCountMap = make(map[rune]float32)
for _, val := range currentWords {
addWordToFreq(val)
}
}
func addWordToFreq(s string) {
// if a word contains the same character twice, I am counting it only once
mapCheck := make(map[rune]bool)
for _, c := range s {
if !mapCheck[c] {
characterCountMap[c] += 1
mapCheck[c] = true
}
}
}
func getWordPower(s string) float32 {
power := float32(0)
mapCheck := make(map[rune]bool)
for _, c := range s {
if !mapCheck[c] {
power += characterCountMap[c]
mapCheck[c] = true
}
}
return power
}
// checks whether the word exists or not in our wordList
func wordExists(s string) bool {
for _, val := range wordList {
if s == val {
return true
}
}
return false
}