Skip to content

Instantly share code, notes, and snippets.

@goakley
Forked from KevinTCoughlin/are-letters-sorted.js
Last active March 23, 2017 17:41
Show Gist options
  • Save goakley/7209d1cda8bfc8b3b73c76fe334c6032 to your computer and use it in GitHub Desktop.
Save goakley/7209d1cda8bfc8b3b73c76fe334c6032 to your computer and use it in GitHub Desktop.
input :: [String]
input = [
"billowy",
"biopsy",
"chinos",
"defaced",
"chintz",
"sponged",
"bijoux",
"abhors",
"fiddle",
"begins",
"chimps",
"wronged"]
isSorted :: (a -> a -> Bool) -> [a] -> Bool
isSorted cmp xs = and $ zipWith cmp xs (tail xs)
solve :: String -> String
solve xs
| isSorted asc xs = xs ++ " IN ORDER"
| isSorted desc xs = xs ++ " REVERSE ORDER"
| otherwise = xs ++ " NOT IN ORDER"
where asc = (<=)
desc = (>=)
main :: IO ()
main = mapM_ (putStrLn . solve) input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment