Created
November 5, 2013 00:19
-
-
Save sshine/7311759 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
local | |
fun fbstr i = | |
case (i mod 3 = 0, i mod 5 = 0) of | |
(true , true ) => "FizzBuzz" | |
| (true , false) => "Fizz" | |
| (false, true ) => "Buzz" | |
| (false, false) => Int.toString i | |
fun fizzbuzz' (n, j) = | |
if n = j then () else (print (fbstr j ^ "\n"); fizzbuzz' (n, j+1)) | |
in | |
fun fizzbuzz n = fizzbuzz' (n, 1) | |
val _ = fizzbuzz 100 | |
end | |
local | |
fun fb i = let val fizz = i mod 3 = 0 andalso (print "Fizz"; true) | |
val buzz = i mod 5 = 0 andalso (print "Buzz"; true) | |
in fizz orelse buzz orelse (print (Int.toString i); true) end | |
in | |
fun fizzbuzz n = (List.tabulate (n, fn i => (fb (i+1); print "\n"))) | |
val _ = fizzbuzz 100 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment