Skip to content

Commit a9a9ee1

Browse files
committed
Added new kyu golang
1 parent 29dcf07 commit a9a9ee1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

golang/7_kyu_word_values.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
3+
Given a string "abc" and assuming that each letter in the string has a value equal to its position in the alphabet, our string will have a value of 1 + 2 + 3 = 6.
4+
This means that: a = 1, b = 2, c = 3 ....z = 26.
5+
6+
You will be given a list of strings and your task will be to return the values of the strings as explained above multiplied by the position of that string in the list.
7+
For our purpose, position begins with 1.
8+
9+
nameValue ["abc","abc abc"] should return [6,24] because of [ 6 * 1, 12 * 2 ]. Note how spaces are ignored.
10+
11+
"abc" has a value of 6, while "abc abc" has a value of 12. Now, the value at position 1 is multiplied by 1 while the value at position 2 is multiplied by 2.
12+
13+
Input will only contain lowercase characters and spaces.
14+
15+
*/
16+
17+
package kata
18+
19+
func NameValue(my_list []string) []int {
20+
var result []int
21+
22+
for i, text := range my_list {
23+
count := 0
24+
25+
for _, r := range text {
26+
if r == 32 {
27+
continue
28+
}
29+
count += int(r - 96)
30+
}
31+
32+
result = append(result, count * (i + 1))
33+
}
34+
35+
return result
36+
}

0 commit comments

Comments
 (0)