Data update

This commit is contained in:
Ingy döt Net 2024-03-06 22:25:12 -08:00
parent ed705008a8
commit 0df55f9f24
2196 changed files with 32999 additions and 3075 deletions

View file

@ -0,0 +1,17 @@
func damm inp$ .
table[][] = [ [ 0 3 1 7 5 9 8 6 4 2 ] [ 7 0 9 2 1 5 4 8 6 3 ] [ 4 2 0 6 8 7 1 3 5 9 ] [ 1 7 5 0 9 8 3 4 2 6 ] [ 6 1 2 3 0 4 5 9 7 8 ] [ 3 6 7 4 2 0 9 5 8 1 ] [ 5 8 6 9 7 2 0 1 3 4 ] [ 8 9 4 5 3 6 2 0 1 7 ] [ 9 4 3 8 6 1 7 2 0 5 ] [ 2 5 8 1 4 3 6 7 9 0 ] ]
inp[] = number strchars inp$
for v in inp[]
inter = table[inter + 1][v + 1]
.
return if inter = 0
.
nums[] = [ 5724 5727 112946 112949 ]
for v in nums[]
write v & " is "
if damm v = 1
print "valid"
else
print "invalid"
.
.

View file

@ -0,0 +1,34 @@
clear all;close all;clc;
% Test the function with the provided numbers
numbers = [5724, 5727, 112946];
for i = 1:length(numbers)
if checkdigit(numbers(i))
fprintf('%d validates as: true\n', numbers(i));
else
fprintf('%d validates as: false\n', numbers(i));
end
end
function isValid = checkdigit(n)
matrix = [
0, 3, 1, 7, 5, 9, 8, 6, 4, 2;
7, 0, 9, 2, 1, 5, 4, 8, 6, 3;
4, 2, 0, 6, 8, 7, 1, 3, 5, 9;
1, 7, 5, 0, 9, 8, 3, 4, 2, 6;
6, 1, 2, 3, 0, 4, 5, 9, 7, 8;
3, 6, 7, 4, 2, 0, 9, 5, 8, 1;
5, 8, 6, 9, 7, 2, 0, 1, 3, 4;
8, 9, 4, 5, 3, 6, 2, 0, 1, 7;
9, 4, 3, 8, 6, 1, 7, 2, 0, 5;
2, 5, 8, 1, 4, 3, 6, 7, 9, 0
];
row = 0;
nString = num2str(n);
for i = 1:length(nString)
d = str2double(nString(i));
row = matrix(row+1, d + 1);
end
isValid = (row == 0);
end

View file

@ -1,12 +1,25 @@
/*REXX pgm uses H. Michael Damm's algorithm to validate numbers with suffixed check sum.*/
@.0= 0317598642; @.1= 7092154863; @.2= 4206871359; @.3= 1750983426; @.4= 6123045978
@.5= 3674209581; @.6= 5869720134; @.7= 8945362017; @.8= 9438617205; @.9= 2581436790
call Damm 5724, 5727, 112946, 112940 /*invoke Damm's algorithm for some #'s.*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Damm: do j=1 for arg(); x= arg(j); $= 0; z= right(x, 1)
do p=1 for length(x); g=$; $= substr(@.$, 1 + substr(x, p, 1), 1)
end /*p*/
if $==0 then say ' valid checksum digit ' z " for " x
else say ' invalid checksum digit ' z " for " x ' (should be' g")"
end /*j*/; return
/*REXX pgm uses H. Michael Damm's algorithm to validate numbers with suffixed check sum. digit*/
a.0= 0317598642; a.1= 7092154863; a.2= 4206871359; a.3= 1750983426; a.4= 6123045978
a.5= 3674209581; a.6= 5869720134; a.7= 8945362017; a.8= 9438617205; a.9= 2581436790
Call Damm 5724, 5727, 112946, 112940 /*invoke Damm's algorithm To some #'s.*/
Exit /*stick a Tok in it, we're all Done. */
/*---------------------------------------------------------------------------------*/
Damm:
Do j=1 To arg() /* loop over numbers */
x=arg(j)
d=0
Do p=1 To length(x)-1 /* compute the checksum digit */
d=substr(a.d,substr(x,p,1)+1,1)
end /*p*/
z=right(x,1) /* the given digit */
If z=d Then Say ' valid checksum digit ' z " for " x
Else Say ' invalid checksum digit ' z " for " x ' (should be' d")"
End /*j*/
Return /syntaxhighlight>
{{out|output|text=  when using the (internal) default inputs:}}
<pre>
valid checksum digit 4 for 5724
invalid checksum digit 7 for 5727 (should be 4)
valid checksum digit 6 for 112946
invalid checksum digit 0 for 112940 (should be 6)
</pre>

View file

@ -0,0 +1,26 @@
proc damm {number} {
set digits [split $number ""]
set tbl {
{0 3 1 7 5 9 8 6 4 2}
{7 0 9 2 1 5 4 8 6 3}
{4 2 0 6 8 7 1 3 5 9}
{1 7 5 0 9 8 3 4 2 6}
{6 1 2 3 0 4 5 9 7 8}
{3 6 7 4 2 0 9 5 8 1}
{5 8 6 9 7 2 0 1 3 4}
{8 9 4 5 3 6 2 0 1 7}
{9 4 3 8 6 1 7 2 0 5}
{2 5 8 1 4 3 6 7 9 0}
}
set row 0
foreach col $digits {
set row [lindex $tbl $row $col]
}
return [expr {$row == 0 ? 1 : 0}]
}
foreach number {5724 5727 112946} {
set correct [damm $number]
puts "$number:\tChecksum digit [expr {$correct ? "" : "in"}]correct."
}