Created
February 10, 2012 22:57
-
-
Save erdman/1793804 to your computer and use it in GitHub Desktop.
embedly challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
fact :: Integer -> Integer | |
fact x = foldl' (*) 1 [1..x] | |
sumdigits :: Integer -> Integer | |
sumdigits x | |
| x < 10 = x | |
| otherwise = let (a,b) = x `divMod` 10 in b + sumdigits a | |
-- convert text to list of number of spaces indented | |
indentsizes :: [String] -> [Int] | |
indentsizes [] = [] | |
indentsizes (x:xs) = (length $ takeWhile (==' ') x) : (indentsizes xs) | |
-- convert list of numbers to increasing or decreasing depth measures | |
depth :: [Int] -> (Int,Int) -> [Int] | |
depth [] _ = [] | |
depth (x:xs) (previndent,prevdepth) = thisdepth : (depth xs (x,thisdepth)) | |
where | |
thisdepth = case compare x previndent of | |
LT -> pred prevdepth | |
EQ -> prevdepth | |
GT -> succ prevdepth | |
ptags :: [String] -> [Bool] | |
ptags [] = [] | |
ptags (x:xs) = (isPrefixOf "<p>" (dropWhile (==' ') x)) : (ptags xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment