From 00e0063e1eab6e2d39dda6d427d883a5ac322856 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sat, 1 Jun 2024 21:49:14 +0200 Subject: [PATCH] =?UTF-8?q?go:=20add=20=C2=AB3110.=20Score=20of=20a=20Stri?= =?UTF-8?q?ng=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- go/score-of-a-string.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 go/score-of-a-string.go 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 +}