Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
package luhn
func IsValid(digits []int) bool {
sum := 0
alt := false
for i := len(digits) - 1; 0 <= i; i-- {
d := digits[i]
if alt {
d *= 2
if d > 9 {
d -= 9
}
}
sum += d
alt = !alt
}
return sum%10 == 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment