Skip to content

Commit

Permalink
Tidying up my FizzBuzz program in Idris
Browse files Browse the repository at this point in the history
  • Loading branch information
philharvey committed Feb 28, 2018
1 parent a1f268b commit fa8ca4e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
Binary file added philharvey+idris/fizzbuzz.ibc
Binary file not shown.
19 changes: 6 additions & 13 deletions philharvey+idris/fizzbuzz.idr
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]

0 comments on commit fa8ca4e

Please sign in to comment.