This file contains hidden or 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
l = ['a','a','b','b','b','c','c'] | |
compress :: [Char] -> [String] | |
compress l = group l >>= (\x -> [take 1 x, show $ length x]) | |
main = do | |
putStrLn . show $ compress l |
This file contains hidden or 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
getHalves :: Int -> [Int] | |
getHalves = takeWhile (/=0) . iterate (\x -> if x `mod` 2 == 0 then x `div` 2 else 0) | |
brokenCalc :: Int -> Int -> Int | |
brokenCalc s t = brokenCalc' 0 s t | |
brokenCalc' :: Int -> Int -> Int -> Int | |
brokenCalc' i s t | |
| s == t = i | |
| s `elem` halves = brokenCalc' i' (s*2) t |
This file contains hidden or 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
pop :: [a] -> [a] | |
pop [] = [] | |
pop (x:xs) = xs | |
compareWithBackspace :: String -> String -> Bool | |
compareWithBackspace xs ys = compare' s1 s2 | |
where s1 = buildStack xs | |
s2 = buildStack ys | |
buildStack :: String -> String |
This file contains hidden or 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 Control.Monad | |
generateParens :: Int -> [String] | |
generateParens n = generateParens' n "" | |
generateParens' :: Int -> String -> [String] | |
generateParens' n xs | |
| n == o = [xs ++ replicate u ')'] | |
| u == 0 = generateParens' n (xs ++ "(") | |
| otherwise = [xs ++ "(", xs ++ ")"] >>= generateParens' n |
This file contains hidden or 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
*Main> maxPointsOnLine [(1,1), (3,2), (5,3), (4,1), (2,3), (1,4)] | |
4 |
This file contains hidden or 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
*Main> oneRow ["candy","doodle","pop","shield","lag","typewriter"] | |
["pop","lag","typewriter"] |
This file contains hidden or 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
/tmp | |
➜ ./a.out | |
0 | |
1 | |
0 | |
1 | |
0 | |
1 |
This file contains hidden or 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
/tmp | |
➜ ./a.out | |
0 | |
1 | |
2 | |
1 | |
8 | |
1 | |
32 |
This file contains hidden or 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 | |
import Data.Ord | |
charNumSort :: [String] -> [String] | |
charNumSort = sortBy ((comparing $ length . nub) `mappend` (comparing $ Down . length)) |
This file contains hidden or 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
*Main> moveZeros [1, 2, 0, 1, 0, 0, 3, 6] | |
[1,2,1,3,6,0,0,0] |