Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.Char
- -- Convert pure text to word lists removing symbols
- asWords :: [String] -> [[String]]
- asWords = map $ words . map r where r c | isAlpha c = c
- | otherwise = ' '
- -- Lookup last row indexed word
- jump :: [[String]] -> Int -> Maybe String
- jump [] _ = Nothing
- jump [(x:_)] 0 = Just x
- jump ((x:xs):xss) 0 = jump (xs:xss) (length x)
- jump ([]:xss) n = jump xss n
- jump ((x:xs):xss) n = jump (xs:xss) (n - 1)
- -- With some word check if obey the law
- obey :: String -> [[String]] -> Bool
- obey _ [] = False
- obey w xs@(x:_) = all (Just w ==) $ (jump xs) <$> [1..length x]
- -- Example
- text =
- "In the beginning God created the heaven and the earth.\n\
- \And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.\n\
- \And God said, Let there be light: and there was light"
- main = print $ obey "God" $ asWords $ lines text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement