June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
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
|
||||
}
|
||||
|
|
@ -1,22 +1,21 @@
|
|||
use framework "Foundation" -- ( for case conversion function )
|
||||
|
||||
-- PANGRAM CHECK -------------------------------------------------------------
|
||||
|
||||
-- isPangram :: String -> Bool
|
||||
on isPangram(s)
|
||||
script charUnUsed
|
||||
property lowerCaseString : my toLowerCase(s)
|
||||
|
||||
on lambda(c)
|
||||
property lowerCaseString : my toLower(s)
|
||||
on |λ|(c)
|
||||
lowerCaseString does not contain c
|
||||
end lambda
|
||||
end |λ|
|
||||
end script
|
||||
|
||||
length of filter(charUnUsed, "abcdefghijklmnopqrstuvwxyz") = 0
|
||||
end isPangram
|
||||
|
||||
|
||||
-- TEST
|
||||
|
||||
-- TEST ----------------------------------------------------------------------
|
||||
on run
|
||||
map(isPangram, {¬
|
||||
"is this a pangram", ¬
|
||||
|
|
@ -25,8 +24,7 @@ on run
|
|||
--> {false, true}
|
||||
end run
|
||||
|
||||
|
||||
-- GENERIC HIGHER ORDER FUNCTIONS (FILTER AND MAP)
|
||||
-- GENERIC FUNCTIONS ---------------------------------------------------------
|
||||
|
||||
-- filter :: (a -> Bool) -> [a] -> [a]
|
||||
on filter(f, xs)
|
||||
|
|
@ -35,7 +33,7 @@ on filter(f, xs)
|
|||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to item i of xs
|
||||
if lambda(v, i, xs) then set end of lst to v
|
||||
if |λ|(v, i, xs) then set end of lst to v
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
|
|
@ -47,7 +45,7 @@ on map(f, xs)
|
|||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to lambda(item i of xs, i, xs)
|
||||
set end of lst to |λ|(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
|
|
@ -60,32 +58,14 @@ on mReturn(f)
|
|||
f
|
||||
else
|
||||
script
|
||||
property lambda : f
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
-- OBJC function: lowercaseStringWithLocale
|
||||
|
||||
-- toLowerCase :: String -> String
|
||||
on toLowerCase(str)
|
||||
-- toLower :: String -> String
|
||||
on toLower(str)
|
||||
set ca to current application
|
||||
unwrap(wrap(str)'s ¬
|
||||
lowercaseStringWithLocale:(ca's NSLocale's currentLocale))
|
||||
end toLowerCase
|
||||
|
||||
-- wrap :: AS value -> NSObject
|
||||
on wrap(v)
|
||||
set ca to current application
|
||||
ca's (NSArray's arrayWithObject:v)'s objectAtIndex:0
|
||||
end wrap
|
||||
|
||||
-- unwrap :: NSObject -> AS value
|
||||
on unwrap(objCValue)
|
||||
if objCValue is missing value then
|
||||
return missing value
|
||||
else
|
||||
set ca to current application
|
||||
item 1 of ((ca's NSArray's arrayWithObject:objCValue) as list)
|
||||
end if
|
||||
end unwrap
|
||||
((ca's NSString's stringWithString:(str))'s ¬
|
||||
lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
|
||||
end toLower
|
||||
|
|
|
|||
|
|
@ -1,25 +1,20 @@
|
|||
function makepangramchecker{T<:String}(a::T)
|
||||
abet = sort(unique(split(uppercase(a), "")))
|
||||
alen = length(abet)
|
||||
function ispangram{T<:String}(s::T)
|
||||
alen <= length(s) || return false
|
||||
ps = filter(c->(c in abet), unique(split(uppercase(s), "")))
|
||||
return length(ps) == alen
|
||||
function makepangramchecker(alphabet)
|
||||
alphabet = Set(uppercase.(alphabet))
|
||||
function ispangram(s)
|
||||
lengthcheck = length(s) ≥ length(alphabet)
|
||||
return lengthcheck && all(c in uppercase(s) for c in alphabet)
|
||||
end
|
||||
return ispangram
|
||||
end
|
||||
|
||||
tests = ["Pack my box with five dozen liquor jugs.",
|
||||
"The quick brown fox jumps over a lazy dog.",
|
||||
"The quick brown fox jumps\u2323over the lazy dog.",
|
||||
"The five boxing wizards jump quickly.",
|
||||
"This sentence contains A-Z but not the whole alphabet."]
|
||||
const tests = ["Pack my box with five dozen liquor jugs.",
|
||||
"The quick brown fox jumps over a lazy dog.",
|
||||
"The quick brown fox jumps\u2323over the lazy dog.",
|
||||
"The five boxing wizards jump quickly.",
|
||||
"This sentence contains A-Z but not the whole alphabet."]
|
||||
|
||||
isenglishpang = makepangramchecker("abcdefghijklmnopqrstuvwxyz")
|
||||
is_english_pangram = makepangramchecker('a':'z')
|
||||
|
||||
for s in tests
|
||||
print("The sentence \"", s, "\" is ")
|
||||
if !isenglishpang(s)
|
||||
print("not ")
|
||||
end
|
||||
println("a pangram.")
|
||||
println("The sentence \"", s, "\" is ", is_english_pangram(s) ? "" : "not ", "a pangram.")
|
||||
end
|
||||
|
|
|
|||
7
Task/Pangram-checker/Maple/pangram-checker-1.maple
Normal file
7
Task/Pangram-checker/Maple/pangram-checker-1.maple
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#Used built-in StringTools package
|
||||
is_pangram := proc(str)
|
||||
local present := StringTools:-LowerCase~(select(StringTools:-HasAlpha, StringTools:-Explode(str)));
|
||||
local alphabets := {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
|
||||
present := convert(present, set);
|
||||
return evalb(present = alphabets);
|
||||
end proc;
|
||||
3
Task/Pangram-checker/Maple/pangram-checker-2.maple
Normal file
3
Task/Pangram-checker/Maple/pangram-checker-2.maple
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
is_pangram("The quick brown fox jumps over the lazy dog.");
|
||||
is_pangram("The 2 QUIck brown foxes jumped over the lazy DOG!!");
|
||||
is_pangram(""The quick brown fox jumps over the lay dog.");
|
||||
|
|
@ -1,13 +1,17 @@
|
|||
/*REXX program verifies if an entered/supplied string (sentence) is a pangram. */
|
||||
@abc= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*a list of all (Latin) capital letters*/
|
||||
|
||||
do forever; say /*keep promoting 'til null (or blanks).*/
|
||||
say '──────── Please enter a pangramic sentence (or a blank to quit):'; say
|
||||
do forever /*keep promoting 'til null (or blanks).*/
|
||||
say
|
||||
say '──────── Please enter a pangramic sentence (or a blank to quit):'
|
||||
say
|
||||
pull y /*this also uppercases the Y variable.*/
|
||||
if y='' then leave /*if nothing entered, then we're done.*/
|
||||
?=verify(@abc, y) /*Are all the (Latin) letters present? */
|
||||
if ?==0 then say '──────── Sentence is a pangram.'
|
||||
else say "──────── Sentence isn't a pangram, missing:" substr(@abc, ?, 1)
|
||||
|
||||
absent= space( translate( @abc, , y), 0) /*obtain a list of any absent letters. */
|
||||
|
||||
if absent=='' then say '──────── Sentence is a pangram.'
|
||||
else say "──────── Sentence isn't a pangram, missing: " absent
|
||||
say
|
||||
end /*forever*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue