Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
|
|
@ -1,19 +0,0 @@
|
|||
val .isbn13checkdigit = f(var .s) {
|
||||
.s = replace(.s, RE/[\- ]/)
|
||||
var .alt = true
|
||||
matching(re/^[0-9]{13}$/, .s) and
|
||||
for[=0] .d in s2n(.s) { _for += if(not= .alt: .d x 3; .d) } div 10
|
||||
}
|
||||
|
||||
val .tests = h{
|
||||
"978-0596528126": true,
|
||||
"978-0596528120": false,
|
||||
"978-1788399081": true,
|
||||
"978-1788399083": false,
|
||||
}
|
||||
|
||||
for .key of .tests {
|
||||
val .pass = .isbn13checkdigit(.key)
|
||||
write .key, ": ", if(.pass: "good"; "bad")
|
||||
writeln if(.pass == .tests[.key]: ""; " (ISBN-13 CHECK DIGIT TEST FAILED)")
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
val .isbn13checkdigit = f(var .s) {
|
||||
val .isbn13checkdigit = fn(var .s) {
|
||||
.s = replace(.s, RE/[\- ]/)
|
||||
matching(re/^[0-9]{13}$/, .s) and
|
||||
fold(f{+}, map [_, f{x 3}], s2n .s) div 10
|
||||
.s -> re/^[0-9]{13}$/ and
|
||||
fold(fn{+}, map [_, fn{*3}], s2n .s) div 10
|
||||
}
|
||||
|
||||
val .tests = h{
|
||||
25
Task/ISBN13-check-digit/Miranda/isbn13-check-digit.miranda
Normal file
25
Task/ISBN13-check-digit/Miranda/isbn13-check-digit.miranda
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
main :: [sys_message]
|
||||
main = [Stdout (lay (map test tests))]
|
||||
|
||||
test :: [char]->[char]
|
||||
test isbn = isbn ++ ": good", if isbn13 isbn
|
||||
= isbn ++ ": bad", otherwise
|
||||
|
||||
tests :: [[char]]
|
||||
tests = ["978-0596528126",
|
||||
"978-0596528120",
|
||||
"978-1788399081",
|
||||
"978-1788399083"]
|
||||
|
||||
isbn13 :: [char]->bool
|
||||
isbn13 str = False, if #isbn ~= 13 \/ ~and (map digit isbn)
|
||||
= check mod 10 = 0, otherwise
|
||||
where isbn = filter (~= '-') str
|
||||
digits = map (numval.(:[])) isbn
|
||||
check = sum (zipwith (*) digits (concat (repeat [1,3])))
|
||||
|
||||
uncurry :: (*->**->***)->(*,**)->***
|
||||
uncurry f (a,b) = f a b
|
||||
|
||||
zipwith :: (*->**->***)->[*]->[**]->[***]
|
||||
zipwith f a b = map (uncurry f) (zip2 a b)
|
||||
46
Task/ISBN13-check-digit/Refal/isbn13-check-digit.refal
Normal file
46
Task/ISBN13-check-digit/Refal/isbn13-check-digit.refal
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
$ENTRY Go {
|
||||
= <Test '978-0596528126'>
|
||||
<Test '978-0596528120'>
|
||||
<Test '978-1788399081'>
|
||||
<Test '978-1788399083'>
|
||||
};
|
||||
|
||||
Test {
|
||||
e.X = <Prout e.X ': ' <ISBN e.X>>;
|
||||
};
|
||||
|
||||
ISBN {
|
||||
e.X, <Remove '-' e.X>: e.DS,
|
||||
<CheckDigits e.DS>: {
|
||||
False = Bad;
|
||||
True = <ISBN1 e.DS>;
|
||||
};
|
||||
};
|
||||
|
||||
ISBN1 {
|
||||
(13 s.Sum), <Mod s.Sum 10>: 0 = Good;
|
||||
(13 s.Sum) e.X = Bad;
|
||||
(s.N s.Sum) = Bad;
|
||||
|
||||
(s.N s.Sum) s.D e.X,
|
||||
<+ s.N 1>: s.N1,
|
||||
<Numb s.D>: s.V,
|
||||
<Mod s.N 2>: {
|
||||
0 = <ISBN1 (s.N1 <+ s.Sum s.V>) e.X>;
|
||||
1 = <ISBN1 (s.N1 <+ s.Sum <* 3 s.V>>) e.X>;
|
||||
};
|
||||
|
||||
e.X = <ISBN1 (0 0) e.X>;
|
||||
};
|
||||
|
||||
Remove {
|
||||
s.1 = ;
|
||||
s.1 s.1 e.X = <Remove s.1 e.X>;
|
||||
s.1 s.2 e.X = s.2 <Remove s.1 e.X>;
|
||||
};
|
||||
|
||||
CheckDigits {
|
||||
= True;
|
||||
s.D e.X, '0123456789': e.A s.D e.B = <CheckDigits e.X>;
|
||||
e.X = False;
|
||||
};
|
||||
22
Task/ISBN13-check-digit/SETL/isbn13-check-digit.setl
Normal file
22
Task/ISBN13-check-digit/SETL/isbn13-check-digit.setl
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
program isbn13;
|
||||
loop for test in [
|
||||
"978-0596528126", "978-0596528120",
|
||||
"978-1788399081", "978-1788399083"
|
||||
] do
|
||||
print(test + if valid_isbn13 test then ": good" else ": bad" end);
|
||||
end loop;
|
||||
|
||||
op valid_isbn13(isbn);
|
||||
if #isbn /= 14
|
||||
or isbn(4) /= '-'
|
||||
or exists c in isbn | not c in "0123456789-" then
|
||||
return false;
|
||||
end if;
|
||||
|
||||
m := 3;
|
||||
loop for ch in isbn | ch in "0123456789" do
|
||||
s +:= val ch * (m := 4 - m);
|
||||
end loop;
|
||||
return s mod 10 = 0;
|
||||
end op;
|
||||
end program;
|
||||
Loading…
Add table
Add a link
Reference in a new issue