From fd8572d34aa7c94b7221f923564fe9c1d13584f1 Mon Sep 17 00:00:00 2001 From: Phil Harvey Date: Tue, 27 Feb 2018 19:53:33 -0600 Subject: [PATCH] Fix a bug and tidy up my initial version of FizzBuzz in Idris --- philharvey+idris/fizzbuzz.ibc | Bin 0 -> 4674 bytes philharvey+idris/fizzbuzz.idr | 23 ++++++++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) create mode 100644 philharvey+idris/fizzbuzz.ibc diff --git a/philharvey+idris/fizzbuzz.ibc b/philharvey+idris/fizzbuzz.ibc new file mode 100644 index 0000000000000000000000000000000000000000..cc97452a9d03403ae69fb50c76bdb4689637f9dd GIT binary patch literal 4674 zcmai%2{_dGAIE1L<;s0$Q-o$3w}es}N$y!vk<2h=7=(;MT06-tsxfZKU5*s8A!#DV zXxuq+tYhRVLTV-I{~NKh``c&#`mRD1?oR3j%@cfvA_( zjc5SBLV?BuG=ei0?S#eRh(s&~!j3<&Z6AhaL8o6Ya|%J!8mNZ~|336GTi*!u2rCjK*TaO2!wkxvY)q~lP5E~OKWDx&!j1An6tbF3wK^aQmP^QzTq(F}2I3B!{tgnSP*D$vb?6;K8Q ztdUXcF8!v_W@DDv>=Ony@{dOKHir`Bt1r*}`9(t6gq)|63qmLk3L2T4Uc2o>b_j&3 z1c5MDfjMUv9G*C5cg}l2O|-26YMMj{O1}IBI&7F{*`4vVi+^u!*J=2m2SwQM!DJm$ z<8<)4jPRkxi)k*Qlmp4z>t0OFGCuy)M1Cxticm20r@v`_m-BWB;h-WS_eFxwVxn;6 z*q-h~;p&FrGgdfrYwn-NSN4AD;v*X?n7O0BcJM3rD|VyrUQNO9dX;i2H7|+G9?G<- zN-LD>#?5l?F)(T{Bo|OsQg6&>4wg^disx-R+&;;{{!6T#t{$8!S}J%`^2}0S2;DO) zP%G9>ayBkfT({ZAW_`flElt2L1hL2%t#dfCrZp#cq?Et-?%-$r4D0d_2HQyiR_}{Z z0i1R#=zLL;(}Ge9WysZ`6rRF%YsG9#@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f1oi)MOnGEI=D>;F;Fw|w#=z3Y!tQNiTS5pX!4k$Ir2q|OcDN~MU=XZKEHG#j z{8OjEC|D9$s6L=^%syEH0cOED%wn7W#{Of8z-h|@`2ksCB{8c*<{SS^Sr%ssa6kg1 V%s83W1|kG}o&!mJfvIwk{{fpAz})}< literal 0 HcmV?d00001 diff --git a/philharvey+idris/fizzbuzz.idr b/philharvey+idris/fizzbuzz.idr index 3b4ffc3..25532fa 100644 --- a/philharvey+idris/fizzbuzz.idr +++ b/philharvey+idris/fizzbuzz.idr @@ -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]