diff --git a/go/score-of-a-string.go b/go/score-of-a-string.go new file mode 100644 index 0000000..e4faa2c --- /dev/null +++ b/go/score-of-a-string.go @@ -0,0 +1,15 @@ +package score_of_a_string + +func scoreOfString(s string) int { + abs := func(x int) int { + return max(x, -x) + } + + score := 0 + + for i := 0; i+1 < len(s); i++ { + score += abs(int(s[i]) - int(s[i+1])) + } + + return score +}