Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidying up my first FizzBuzz program in Idris #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added philharvey+idris/fizzbuzz.ibc
Binary file not shown.
23 changes: 10 additions & 13 deletions philharvey+idris/fizzbuzz.idr
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
module Main

isFizz : Nat -> Bool
isFizz n = modNat n 3 == 0
mapToFizzBuzz : Nat -> String
mapToFizzBuzz n = if isFizz n && isBuzz n then "FizzBuzz" else
if isFizz n then "Fizz" else
if isBuzz n then "Buzz" else show n
where isFizz n = modNat n 3 == 0
isBuzz n = modNat n 5 == 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 ++ ", "))
reduceFizzBuzz : String -> Nat -> String
reduceFizzBuzz s n = s ++ mapToFizzBuzz n ++ "\n"

main : IO ()
main = putStrLn $ foldl fizzbuzz "" [1..100]
main = do
putStrLn $ foldl reduceFizzBuzz "" [1..100]