Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
45
Task/Pangram-checker/ATS/pangram-checker-1.ats
Normal file
45
Task/Pangram-checker/ATS/pangram-checker-1.ats
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
(* ****** ****** *)
|
||||
//
|
||||
#include
|
||||
"share/atspre_staload.hats"
|
||||
#include
|
||||
"share/HATS/atspre_staload_libats_ML.hats"
|
||||
//
|
||||
(* ****** ****** *)
|
||||
//
|
||||
fun
|
||||
letter_check
|
||||
(
|
||||
cs: string, c0: char
|
||||
) : bool = cs.exists()(lam(c) => c0 = c)
|
||||
//
|
||||
(* ****** ****** *)
|
||||
|
||||
fun
|
||||
Pangram_check
|
||||
(text: string): bool = let
|
||||
//
|
||||
val
|
||||
alphabet = "abcdefghijklmnopqrstuvwxyz"
|
||||
val
|
||||
((*void*)) = assertloc(length(alphabet) = 26)
|
||||
//
|
||||
in
|
||||
alphabet.forall()(lam(c) => letter_check(text, c) || letter_check(text, toupper(c)))
|
||||
end // end of [Pangram_check]
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
implement
|
||||
main0 () =
|
||||
{
|
||||
//
|
||||
val
|
||||
text0 = "The quick brown fox jumps over the lazy dog."
|
||||
//
|
||||
val-true = Pangram_check(text0)
|
||||
val-false = Pangram_check("This is not a pangram sentence.")
|
||||
//
|
||||
} (* end of [main0] *)
|
||||
|
||||
(* ****** ****** *)
|
||||
19
Task/Pangram-checker/ATS/pangram-checker-2.ats
Normal file
19
Task/Pangram-checker/ATS/pangram-checker-2.ats
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
fn is_pangram{n:nat}(s: string(n)): bool = loop(s, i2sz(0)) where {
|
||||
val letters: arrayref(bool, 26) = arrayref_make_elt<bool>(i2sz(26), false)
|
||||
fn check(): bool = loop(0) where {
|
||||
fun loop{i:int | i >= 0 && i <= 26}(i: int(i)) =
|
||||
if i < 26 then
|
||||
if letters[i] then loop(i+1) else
|
||||
false
|
||||
else true
|
||||
}
|
||||
fun add{c:int}(c: char(c)): void =
|
||||
if (c >= 'A') * (c <= 'Z') then letters[char2int1(c) - char2int1('A')] := true else
|
||||
if (c >= 'a') * (c <= 'z') then letters[char2int1(c) - char2int1('a')] := true
|
||||
fun loop{i:nat | i <= n}.<n-i>.(s: string(n), i: size_t(i)): bool =
|
||||
if string_is_atend(s, i) then check() else
|
||||
begin
|
||||
add(s[i]);
|
||||
loop(s, succ(i))
|
||||
end
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue