Skip to content

Instantly share code, notes, and snippets.

@fardinshikhiyev
Created October 8, 2018 20:20
Show Gist options
  • Save fardinshikhiyev/266af30ade0deaf7908c708d5f230bc8 to your computer and use it in GitHub Desktop.
Save fardinshikhiyev/266af30ade0deaf7908c708d5f230bc8 to your computer and use it in GitHub Desktop.
module hw7
import StdEnv
occurences :: [Int] Int -> [[Int]]
occurences [] i = []
occurences x i = [[hd x] ++ [count] ++ [freq] ] ++ occurences ( filter ( (<>) (hd x) ) (tl x) ) i
where
count = length( filter( (==) (hd x) ) x )
freq = count * 100 / i
MakeFrequenceTable :: [Int] -> [[Int]]
MakeFrequenceTable [] = []
MakeFrequenceTable x = occurences x (length x)
Start = MakeFrequenceTable [1,3,2,3,2] // [[1,1,20],[3,2,40],[2,2,40]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment