Last active
August 29, 2015 14:01
-
-
Save srbaker/b82ff8f170f1c71f30e9 to your computer and use it in GitHub Desktop.
Fizz Buzz in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Feels like there's a shorthand for the duplicated `mod` expressions. | |
fizzBuzz x | |
| (x `mod` 3) == 0 && (x `mod` 5) == 0 = "FizzBuzz" | |
| (x `mod` 3) == 0 = "Fizz" | |
| (x `mod` 5) == 0 = "Buzz" | |
| otherwise = show x | |
-- Extracting the mod expressions in any way I know how (so far) leads to more complication. |
Nice, it looks clear! Dumb q, but can't you do x
mod 15
for FizzBuzz?
Ah yes, I had 15 originally for brevity, but wasn't sure if it applied completely. It does.
I'm not there yet, but I'm pretty sure I can just do a lookup table mapping 3:fizz,5:buzz,15:fizzbuzz
Guard Clauses depend on sequence. Always has been; always will be.
I think this is about as good as mine's going to get: https://gist.github.com/jbrains/2a29465457bddcca0c45
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I also hate that it's damned order dependent.