initial commit

This commit is contained in:
nora 2021-07-08 16:30:07 +02:00
commit 80aa1a2be7
8 changed files with 142 additions and 0 deletions

17
Average.idr Normal file
View file

@ -0,0 +1,17 @@
module Average
import Data.String
||| Calculate the average word length of a string
||| @str a string containing words seperated by whitespace
export
average : (str : String) -> Double
average str = let totalLength = sum (wordLengths str)
wordAmount = wordCount str in
cast totalLength / cast wordAmount
where
wordCount : String -> Nat
wordCount str = length (words str)
wordLengths : String -> List Nat
wordLengths str = map length (words str)