Luhn test of credit card numbers: Difference between revisions
Content added Content deleted
(adding gap) |
|||
Line 580: | Line 580: | ||
! 1234567812345678 is not valid |
! 1234567812345678 is not valid |
||
! 1234567812345670 is valid</lang> |
! 1234567812345670 is valid</lang> |
||
=={{header|GAP}}== |
|||
<lang gap>IsLuhn := function(n) |
|||
local c, d, i, j, r; |
|||
d := "0123456789"; |
|||
j := 1; |
|||
r := 0; |
|||
for c in Reversed(String(n)) do |
|||
i := Position(d, c); |
|||
if i = fail then |
|||
continue; |
|||
fi; |
|||
i := j*(i - 1); |
|||
r := r + QuoInt(i, 10) + RemInt(i, 10); |
|||
j := 3 - j; |
|||
od; |
|||
return RemInt(r, 10) = 0; |
|||
end; |
|||
List([49927398716, 49927398717, 1234567812345678, 1234567812345670], IsLuhn); |
|||
# [ true, false, false, true ]</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |