From f246ed4e80ba1e01d208c3f24f37c45bf76cc85e 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:41:07 +0000 Subject: [PATCH] [Sync Iteration] go/luhn/3 --- solutions/go/luhn/3/luhn.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 solutions/go/luhn/3/luhn.go diff --git a/solutions/go/luhn/3/luhn.go b/solutions/go/luhn/3/luhn.go new file mode 100644 index 0000000..93861c4 --- /dev/null +++ b/solutions/go/luhn/3/luhn.go @@ -0,0 +1,31 @@ +package luhn + +func Valid(id string) bool { + var sum, size 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 + size++ + } + + return sum%10 == 0 && size > 1 +}