Skip to content

Instantly share code, notes, and snippets.

@erdman
Created February 10, 2012 22:57
Show Gist options
  • Save erdman/1793804 to your computer and use it in GitHub Desktop.
Save erdman/1793804 to your computer and use it in GitHub Desktop.
embedly challenge
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