mirror of
https://github.com/Noratrieb/idris-learning.git
synced 2026-01-15 21:45:01 +01:00
move and change
This commit is contained in:
parent
80aa1a2be7
commit
1330cb05e9
10 changed files with 161 additions and 142 deletions
17
Average.idr
17
Average.idr
|
|
@ -1,17 +0,0 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue