Jump to content

Verhoeff algorithm: Difference between revisions

→‎{{header|Raku}}: Oops, order of operations, make a little more concise
(→‎{{header|Raku}}: Add a Raku example)
(→‎{{header|Raku}}: Oops, order of operations, make a little more concise)
Line 274:
}
say "Checkdigit: {@i[$c]}";
+($int ~ @i[$c]);
}
 
Line 292 ⟶ 293:
## TESTING
 
for 236, 2363, 123451, 12345, 123456789012, 1234567890120 -> $int, $check {
my $check = checksum $int, :verbose( $int.chars < 8 );
validate $check, :verbose( $int.chars < 8 );
validate +($check.chop ~ 9), :verbose( $int.chars < 8 );</lang>
}</lang>
{{out}}
<pre>Checkdigit calculation for 236:
Line 321 ⟶ 323:
Checkdigit: incorrect
 
Checkdigit calculation for 12345112345:
i ni p(i, ni) c
0 0 0 0
1 15 58 58
2 54 97 1
3 43 06 17
4 32 35 42
5 21 82 74
Checkdigit: 01
6 1 7 0
Checkdigit: 0
 
Validation calculation for 12345123451:
i ni p(i, ni) c
0 51 51 51
1 45 28 89
2 34 37 52
3 23 16 98
4 12 45 53
65 1 72 0
Checkdigit: incorrectcorrect
 
Validation calculation for 12349123459:
i ni p(i, ni) c
0 9 9 9
1 45 28 71
2 34 37 98
3 23 16 82
4 12 45 97
5 1 2 5
Checkdigit: incorrect
 
10,327

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.