Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

I had written something similar to Will Will, but the spec I read here says, that FizzBuzz should always cover [1..100], so my implementation was a bit different:

show' :: Int -> String
show' n
 | fizz && buzz = "FizzBuzz" 
 | buzz = "Buzz"
 | fizz = "Fizz"
 | otherwise = show n
 where fizz = mod n 3 == 0
 buzz = mod n 5 == 0
fizzBuzz = [show' x | x <- [1..100]]

Will's idea about using where to cache the mod result was a nice idea IMHO.

I had written something similar to Will, but the spec I read here says, that FizzBuzz should always cover [1..100], so my implementation was a bit different:

show' :: Int -> String
show' n
 | fizz && buzz = "FizzBuzz" 
 | buzz = "Buzz"
 | fizz = "Fizz"
 | otherwise = show n
 where fizz = mod n 3 == 0
 buzz = mod n 5 == 0
fizzBuzz = [show' x | x <- [1..100]]

Will's idea about using where to cache the mod result was a nice idea IMHO.

I had written something similar to Will, but the spec I read here says, that FizzBuzz should always cover [1..100], so my implementation was a bit different:

show' :: Int -> String
show' n
 | fizz && buzz = "FizzBuzz" 
 | buzz = "Buzz"
 | fizz = "Fizz"
 | otherwise = show n
 where fizz = mod n 3 == 0
 buzz = mod n 5 == 0
fizzBuzz = [show' x | x <- [1..100]]

Will's idea about using where to cache the mod result was a nice idea IMHO.

Source Link
jnewman
  • 121
  • 3

I had written something similar to Will, but the spec I read here says, that FizzBuzz should always cover [1..100], so my implementation was a bit different:

show' :: Int -> String
show' n
 | fizz && buzz = "FizzBuzz" 
 | buzz = "Buzz"
 | fizz = "Fizz"
 | otherwise = show n
 where fizz = mod n 3 == 0
 buzz = mod n 5 == 0
fizzBuzz = [show' x | x <- [1..100]]

Will's idea about using where to cache the mod result was a nice idea IMHO.

lang-hs

AltStyle によって変換されたページ (->オリジナル) /