Skip to content

Commit fd8572d

Browse files
committed
Fix a bug and tidy up my initial version of FizzBuzz in Idris
1 parent a1f268b commit fd8572d

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

philharvey+idris/fizzbuzz.ibc

4.56 KB
Binary file not shown.

philharvey+idris/fizzbuzz.idr

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

3-
isFizz : Nat -> Bool
4-
isFizz n = modNat n 3 == 0
3+
mapToFizzBuzz : Nat -> String
4+
mapToFizzBuzz n = if isFizz n && isBuzz n then "FizzBuzz" else
5+
if isFizz n then "Fizz" else
6+
if isBuzz n then "Buzz" else show n
7+
where isFizz n = modNat n 3 == 0
8+
isBuzz n = modNat n 5 == 0
59

6-
isBuzz : Nat -> Bool
7-
isBuzz n = modNat n 5 == 0
8-
9-
isFizzBuzz : Nat -> Bool
10-
isFizzBuzz n = modNat n 15 == 0
11-
12-
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 ++ ", "))
10+
reduceFizzBuzz : String -> Nat -> String
11+
reduceFizzBuzz s n = s ++ mapToFizzBuzz n ++ "\n"
1612

1713
main : IO ()
18-
main = putStrLn $ foldl fizzbuzz "" [1..100]
14+
main = do
15+
putStrLn $ foldl reduceFizzBuzz "" [1..100]

0 commit comments

Comments
 (0)