Skip to content

Commit fa8ca4e

Browse files
committed
Tidying up my FizzBuzz program in Idris
1 parent a1f268b commit fa8ca4e

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

philharvey+idris/fizzbuzz.ibc

4.19 KB
Binary file not shown.

philharvey+idris/fizzbuzz.idr

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
module Main
22

3-
isFizz : Nat -> Bool
4-
isFizz n = modNat n 3 == 0
5-
6-
isBuzz : Nat -> Bool
7-
isBuzz n = modNat n 5 == 0
8-
9-
isFizzBuzz : Nat -> Bool
10-
isFizzBuzz n = modNat n 15 == 0
11-
123
fizzbuzz : String -> Nat -> String
13-
fizzbuzz s n = if isFizzBuzz n then s ++ "Fizz Buzz, " else
14-
(if isFizz n then s ++ "Fizz, " else
15-
(if isBuzz n then s ++ "Buzz, " else s ++ show n ++ ", "))
4+
fizzbuzz s n = if isFizz n then s ++ "Fizz\n" else
5+
if isBuzz n then s ++ "Buzz\n" else s ++ show n ++ "\n"
6+
where isFizz n = modNat n 3 == 0
7+
isBuzz n = modNat n 5 == 0
168

179
main : IO ()
18-
main = putStrLn $ foldl fizzbuzz "" [1..100]
10+
main = do
11+
putStrLn $ foldl fizzbuzz "" [1..100]

0 commit comments

Comments
 (0)