Skip to content

Instantly share code, notes, and snippets.

@srbaker
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save srbaker/b82ff8f170f1c71f30e9 to your computer and use it in GitHub Desktop.
Save srbaker/b82ff8f170f1c71f30e9 to your computer and use it in GitHub Desktop.
Fizz Buzz in Haskell
-- 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.
@srbaker
Copy link
Author

srbaker commented May 7, 2014

I also hate that it's damned order dependent.

@ukd1
Copy link

ukd1 commented May 7, 2014

Nice, it looks clear! Dumb q, but can't you do x mod 15 for FizzBuzz?

@srbaker
Copy link
Author

srbaker commented May 7, 2014

Ah yes, I had 15 originally for brevity, but wasn't sure if it applied completely. It does.

@srbaker
Copy link
Author

srbaker commented May 7, 2014

I'm not there yet, but I'm pretty sure I can just do a lookup table mapping 3:fizz,5:buzz,15:fizzbuzz

@jbrains
Copy link

jbrains commented May 7, 2014

Guard Clauses depend on sequence. Always has been; always will be.

@jbrains
Copy link

jbrains commented May 7, 2014

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