Homework 3

21-06-15–21-06-16
module Golf where 

skips :: [a] -> [[a]]
skips l = map (\x -> map fst (filter (\z -> mod (snd z) x == 0) (zip l [1..]))) [1..length l] 

localMaxima (x:y:z:zs) 
  | x < y && y > z = [y] ++ localMaxima (z:zs) 
  | otherwise      = localMaxima (y:z:zs) 

histogramOld :: [Integer] -> String
histogramOld l = unlines (map (helper 9) l) ++ "\n==========\n0123456789\n"

histogram :: [Integer] -> String 
histogram l = (unlines . reverse . althelp . help3 . help2 $ l) ++ "\n==========\n0123456789\n"

helper :: Integer -> Integer -> String 
helper n2 n1 
  | n2 <= 0   = "" 
  | n1 == (n2 - 1)  = helper (n2 - 1) n1 ++ "*"
  | otherwise = helper (n2 - 1) n1 ++ " "

Go from list of numbers do index corresponding instances and then from there draw.

Returns the amounts of Intances of an integer n in a list l.

instC :: [Integer] -> Integer -> Integer  
instC l n = toInteger (length ((filter (n ==) l))) 

Returns a list of the amounts of instances of every digit in the original list l.

help2 :: [Integer] -> [Integer]
help2 l = map (instC l) [0..9]

Returns a list of the amounts of instances of every digit in the original list decremented by one.

help3 :: [Integer] -> [[Integer]]
help3 l = map (\x -> (map ((+) (-x)) l)) [1..(maximum l)] 
althelp :: [[Integer]] -> [[Char]]
althelp list = map help4 list  
help4 :: [Integer] -> [Char]
help4 l = foldl (++) "" (map help5 l) 

help5 :: Integer -> String 
help5 n 
  | n >= 0 = "*"
  | otherwise = " "

histogram goes like this

find out how many instances of each integer there are. ->