Created
November 23, 2017 12:52
-
-
Save ykon/3fd8fb9743aefe018c8ec4242bb428df to your computer and use it in GitHub Desktop.
FizzBuzz in Elm
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
{-- | |
Copyright (c) 2017 Yuki Ono | |
Licensed under the MIT License. | |
--} | |
import Html exposing (..) | |
import List | |
import String | |
type FizzBuzzType | |
= FizzBuzz Int | |
| Fizz Int | |
| Buzz Int | |
| Number Int | |
toFizzBuzz : Int -> FizzBuzzType | |
toFizzBuzz n = | |
case (n % 3, n % 5) of | |
(0, 0) -> FizzBuzz n | |
(0, _) -> Fizz n | |
(_, 0) -> Buzz n | |
(_, _) -> Number n | |
fizzBuzzToStr : FizzBuzzType -> String | |
fizzBuzzToStr fb = | |
case fb of | |
FizzBuzz _ -> "FizzBuzz" | |
Fizz _ -> "Fizz" | |
Buzz _ -> "Buzz" | |
Number n -> toString n | |
main : Html msg | |
main = | |
List.range 1 100 | |
|> List.map (toFizzBuzz >> fizzBuzzToStr) | |
|> String.join ", " | |
|> text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment