new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
21
Task/Ordered-words/Haskell/ordered-words-1.hs
Normal file
21
Task/Ordered-words/Haskell/ordered-words-1.hs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
-- Words are read from the standard input. We keep in memory only the current
|
||||
-- set of longest, ordered words.
|
||||
--
|
||||
-- Limitation: the locale's collation order is not take into consideration.
|
||||
|
||||
isOrdered wws@(_:ws) = and $ zipWith (<=) wws ws
|
||||
|
||||
keepLongest _ acc [] = acc
|
||||
keepLongest max acc (w:ws) =
|
||||
let len = length w in
|
||||
case compare len max of
|
||||
LT -> keepLongest max acc ws
|
||||
EQ -> keepLongest max (w:acc) ws
|
||||
GT -> keepLongest len [w] ws
|
||||
|
||||
longestOrderedWords = reverse . keepLongest 0 [] . filter isOrdered
|
||||
|
||||
main = do
|
||||
str <- getContents
|
||||
let ws = longestOrderedWords $ words str
|
||||
mapM_ putStrLn ws
|
||||
16
Task/Ordered-words/Haskell/ordered-words-2.hs
Normal file
16
Task/Ordered-words/Haskell/ordered-words-2.hs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
abbott
|
||||
accent
|
||||
accept
|
||||
access
|
||||
accost
|
||||
almost
|
||||
bellow
|
||||
billow
|
||||
biopsy
|
||||
chilly
|
||||
choosy
|
||||
choppy
|
||||
effort
|
||||
floppy
|
||||
glossy
|
||||
knotty
|
||||
11
Task/Ordered-words/Haskell/ordered-words-3.hs
Normal file
11
Task/Ordered-words/Haskell/ordered-words-3.hs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import Control.Monad (liftM)
|
||||
|
||||
isSorted wws@(_ : ws) = and $ zipWith (<=) wws ws
|
||||
|
||||
getLines = liftM lines . readFile
|
||||
|
||||
main = do
|
||||
ls <- getLines "unixdict.txt"
|
||||
let ow = filter isSorted ls
|
||||
let maxl = foldr max 0 (map length ow)
|
||||
print $ filter (\w -> (length w) == maxl) ow
|
||||
Loading…
Add table
Add a link
Reference in a new issue