From 7606ad60f136f6e7f51960135557572b51f43b72 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Sun, 1 Feb 2026 13:37:49 +0000 Subject: [PATCH] [Sync Iteration] go/luhn/1 --- solutions/go/luhn/1/luhn.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 solutions/go/luhn/1/luhn.go diff --git a/solutions/go/luhn/1/luhn.go b/solutions/go/luhn/1/luhn.go new file mode 100644 index 0000000..f1c6a59 --- /dev/null +++ b/solutions/go/luhn/1/luhn.go @@ -0,0 +1,30 @@ +package luhn + +func Valid(id string) bool { + var sum int + double := false + for i := len(id) - 1; i >= 0; i-- { + r := id[i] + + if r == ' ' { + continue + } + + if r < '0' || r > '9' { + return false + } + + n := int(r - '0') + if double { + n *= 2 + if n > 9 { + n -= 9 + } + } + double = !double + + sum += n + } + + return sum%10 == 0 && sum != 0 +}