Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

35 lines (28 sloc) 0.549 kb
package main
import (
"fmt"
"io/ioutil"
"sort"
"strings"
)
func CountLetterNumbers(word string) (sum int64) {
for _, c := range word {
if c >= 'A' && c <= 'Z' {
sum += int64(c - 'A' + 1)
}
}
return
}
func main() {
totalScore := int64(0)
if bytes, err := ioutil.ReadFile("names.txt"); err == nil {
names := strings.Split(string(bytes), ",")
sort.Strings(names)
for i, name := range names {
wordScore := CountLetterNumbers(name)
wordScore *= int64(i + 1)
totalScore += wordScore
}
}
fmt.Println(totalScore)
}
Jump to Line
Something went wrong with that request. Please try again.