Skip to content

Instantly share code, notes, and snippets.

@orb
Created February 8, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orb/95073654cef2d4a04e2a to your computer and use it in GitHub Desktop.
Save orb/95073654cef2d4a04e2a to your computer and use it in GitHub Desktop.
sml stuff
(* SML playing a *)
fun fac 0 = 1
| fac n = n * fac (n - 1);
fun div_by n x =
x mod n = 0;
val div_3 = div_by 3;
val div_5 = div_by 5;
val div_15 = div_by 15;
fun fizzbuzz n =
case (div_3 n, div_5 n) of
(true, true) => "FizzBuzz"
| (true, false) => "Fizz"
| (false,true) => "Buzz"
| _ => Int.toString n
datatype suit = Clubs | Diamonds | Hearts | Spades
datatype rank = Jack | Queen | King | Ace | Num of int
type card = suit * rank
datatype color = Red | Black
fun card_color (Diamonds,_) = Red
| card_color (Hearts ,_) = Red
| card_color _ = Black
fun card_color2 (a_card) =
case a_card of (Diamonds,_) => Red
| (Hearts ,_) => Red
| _ => Black
fun card_value (_,Num(n)) = n
| card_value (_,Ace) = 11
| card_value _ = 10
fun card_value2 (a_card) =
case a_card of (_,Num(n)) => n
| (_,Ace) => 11
| _ => 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment