Skip to content

Instantly share code, notes, and snippets.

@Rydgel
Last active August 29, 2015 14:06
Show Gist options
  • Save Rydgel/24ca0ddfdf4e6619d7c5 to your computer and use it in GitHub Desktop.
Save Rydgel/24ca0ddfdf4e6619d7c5 to your computer and use it in GitHub Desktop.
-- Homework 3 - http://www.seas.upenn.edu/~cis194/spring13/hw/03-rec-poly.pdf
module Golf where
import Data.List
skips :: [a] -> [[a]]
skips xs = map (\(i,x) -> takeNth i x) $ zipWith (\_ b -> (b, xs)) xs [1..]
takeNth :: Int -> [a] -> [a]
takeNth n xs = [y | (i,y) <- zip [1..] xs, i `mod` n == 0]
localMaxima :: [Integer] -> [Integer]
localMaxima a = [y | (x:y:z:_) <- tails a, x < y && y > z]
writeOneLine :: [Integer] -> String
writeOneLine xs = (map f [0..9]) ++ "\n"
where f x | elem x xs = '*'
| otherwise = ' '
writeLines :: [Integer] -> String
writeLines [] = ""
writeLines xs = writeLines (xs \\ uniques) ++ (writeOneLine uniques)
where uniques = nub xs
histogram :: [Integer] -> String
histogram xs = (writeLines xs) ++
"==========\n" ++
"0123456789\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment