-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tidying up my FizzBuzz program in Idris
- Loading branch information
1 parent
a1f268b
commit fa8ca4e
Showing
2 changed files
with
6 additions
and
13 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,11 @@ | ||
module Main | ||
|
||
isFizz : Nat -> Bool | ||
isFizz n = modNat n 3 == 0 | ||
|
||
isBuzz : Nat -> Bool | ||
isBuzz n = modNat n 5 == 0 | ||
|
||
isFizzBuzz : Nat -> Bool | ||
isFizzBuzz n = modNat n 15 == 0 | ||
|
||
fizzbuzz : String -> Nat -> String | ||
fizzbuzz s n = if isFizzBuzz n then s ++ "Fizz Buzz, " else | ||
(if isFizz n then s ++ "Fizz, " else | ||
(if isBuzz n then s ++ "Buzz, " else s ++ show n ++ ", ")) | ||
fizzbuzz s n = if isFizz n then s ++ "Fizz\n" else | ||
if isBuzz n then s ++ "Buzz\n" else s ++ show n ++ "\n" | ||
where isFizz n = modNat n 3 == 0 | ||
isBuzz n = modNat n 5 == 0 | ||
|
||
main : IO () | ||
main = putStrLn $ foldl fizzbuzz "" [1..100] | ||
main = do | ||
putStrLn $ foldl fizzbuzz "" [1..100] |