-
-
Save jbrains/2a29465457bddcca0c45 to your computer and use it in GitHub Desktop.
Revisions
-
jbrains revised this gist
May 7, 2014 . 1 changed file with 4 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,7 @@ -- Thanks to @kimwallmark for teaching me `maybe` and showing me how a single lookup. -- I had the brilliant idea of using `snd`, even though I dislike the name. :) fizzbuzz :: Integer -> String fizzbuzz n = maybe (show n) snd $ classify n where classify n = find (\(m, _) -> n `mod` m == 0) [(15, "Fizzbuzz"), (5, "Buzz"), (3, "Fizz")] -
jbrains revised this gist
May 7, 2014 . 1 changed file with 6 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,9 @@ -- Thanks to @kimwallmark for teaching me `maybe`. -- I'd much rather use something like `lookup` instead of this hand-rolled `matchValue`. -- (Typing this last sentence gave me an idea.) fizzbuzz :: Integer -> String fizzbuzz n = maybe (show n) matchValue $ classify n where matchValue (_, v) = v classify n = find (\(m, _) -> n `mod` m == 0) [(15, "Fizzbuzz"), (5, "Buzz"), (3, "Fizz")] -
jbrains revised this gist
May 7, 2014 . 1 changed file with 8 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,11 @@ -- What trick can I learn to simplify this? fizzbuzz :: Integer -> String fizzbuzz n = case (classifyingDivisor n) of Just divisor -> case (lookup divisor classifications) of Just answer -> answer Nothing -> "error" Nothing -> show n where classifyingDivisor = \n -> (find (\m -> n `mod` m == 0) [15, 5, 3]) classifications = [(15, "Fizzbuzz"), (5, "Buzz"), (3, "Fizz")] -
jbrains revised this gist
May 7, 2014 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,7 @@ fizzbuzz :: Integer -> String fizzbuzz n = case (classifyingDivisor n) of Just 15 -> "Fizzbuzz" Just 5 -> "Buzz" Just 3 -> "Fizz" Nothing -> show n where classifyingDivisor = \n -> (find (\m -> n `mod` m == 0) [15, 5, 3]) -
jbrains revised this gist
May 7, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ -- A little clever, but still easy enough to follow, I think. fizzbuzz :: Integer -> String fizzbuzz n = case (find (\m -> n `mod` m == 0) [15, 5, 3]) of -
jbrains revised this gist
May 7, 2014 . 1 changed file with 7 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,8 @@ -- A little clever, but still easy toenough to follow, I think. fizzbuzz :: Integer -> String fizzbuzz n = case (find (\m -> n `mod` m == 0) [15, 5, 3]) of Just 15 -> "Fizzbuzz" Just 5 -> "Buzz" Just 3 -> "Fizz" Nothing -> show n -
srbaker revised this gist
May 7, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ -- 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 created this gist
May 7, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ -- Feels like there's a shorthand for the duplicated `mod` expressions. fizzBuzz x | (x `mod` 3) == 0 = "Fizz" | (x `mod` 5) == 0 = "Buzz" | (x `mod` 3) == 0 && (x `mod` 5) == 0 = "FizzBuzz" | otherwise = show x -- Extracting the mod expressions in any way I know how (so far) leads to more complication.