Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Palindrome-detection/MLite/palindrome-detection.mlite
Normal file
31
Task/Palindrome-detection/MLite/palindrome-detection.mlite
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
fun to_locase s = implode ` map (c_downcase) ` explode s
|
||||
|
||||
fun only_alpha s = implode ` filter (fn x = c_alphabetic x) ` explode s
|
||||
|
||||
fun is_palin
|
||||
( h1 :: t1, h2 :: t2, n = 0 ) = true
|
||||
| ( h1 :: t1, h2 :: t2, n ) where ( h1 eql h2 ) = is_palin( t1, t2, n - 1)
|
||||
| ( h1 :: t1, h2 :: t2, n ) = false
|
||||
| (str s) =
|
||||
let
|
||||
val es = explode ` to_locase ` only_alpha s;
|
||||
val res = rev es;
|
||||
val k = (len es) div 2
|
||||
in
|
||||
is_palin (es, res, k)
|
||||
end
|
||||
|
||||
fun test_is_palin s =
|
||||
(print "\""; print s; print "\" is a palindrome: "; print ` is_palin s; println "")
|
||||
|
||||
fun test (f, arg, res, ok, notok) = if (f arg eql res) then ("'" @ arg @ "' " @ ok) else ("'" @ arg @ "' " @ notok)
|
||||
|
||||
;
|
||||
|
||||
println ` test (is_palin, "In girum imus nocte, et consumimur igni", true, "is a palindrome", "is NOT a palindrome");
|
||||
println ` test (is_palin, "Madam, I'm Adam.", true, "is a palindrome", "is NOT a palindrome");
|
||||
println ` test (is_palin, "salàlas", true, "is a palindrome", "is NOT a palindrome");
|
||||
println ` test (is_palin, "radar", true, "is a palindrome", "is NOT a palindrome");
|
||||
println ` test (is_palin, "Lagerregal", true, "is a palindrome", "is NOT a palindrome");
|
||||
println ` test (is_palin, "Ein Neger mit Gazelle zagt im Regen nie.", true, "is a palindrome", "is NOT a palindrome");
|
||||
println ` test (is_palin, "something wrong", true, "is a palindrome", "is NOT a palindrome");
|
||||
Loading…
Add table
Add a link
Reference in a new issue