Last active
June 30, 2024 14:46
-
-
Save trikitrok/f02be0163dbe98d2f2f8 to your computer and use it in GitHub Desktop.
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
| fun fizz_buzz num = | |
| let | |
| val remainders = (num mod 3, num mod 5) | |
| in | |
| case remainders of | |
| (0, 0) => "FizzBuzz" | |
| | (0, _) => "Fizz" | |
| | (_, 0) => "Buzz" | |
| | _ => Int.toString(num) | |
| end | |
| fun fizz_buzz_up_to n = | |
| map fizz_buzz (List.tabulate(n, fn x => x + 1)) | |
| val test_not_multiple_of_three_nor_five = | |
| fizz_buzz(1) = "1" | |
| val test_other_not_multiple_of_three_nor_five = | |
| fizz_buzz(2) = "2" | |
| val test_three = fizz_buzz(3) = "Fizz" | |
| val test_other_multiple_of_three = fizz_buzz(9) = "Fizz" | |
| val test_five = fizz_buzz(5) = "Buzz" | |
| val test_other_multiple_of_five = fizz_buzz(10) = "Buzz" | |
| val test_multiple_of_three_and_five = fizz_buzz(15) = "FizzBuzz" | |
| val test_first_fifteen_numbers = | |
| fizz_buzz_up_to 15 = | |
| ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment