Compiler.Control.Print.printDepth := 20;

(* Examples for Question 1 *)

val ex1 = Node(Node(Node(Leaf "a","b",Leaf "c"), "d", Leaf "e"),
          "Top", Node(Leaf "f","g",Leaf "h"));
val ex2 = Node(ex1, "Big", ex1);
val ex3 = Leaf true;

inorderlevel ex1;
inorderlevel ex2;
inorderlevel ex3;

(* Examples for Question 2 *)

filter (fn n => (n = 2 * (n div 2))) [0,1,2,3,4,5,6,7,8,9];
filter (fn x => (x > 5.5)) [14.6, 1.2, 3.4, 5.6, 7.8, 9.876];

map2 (fn x => fn y => x + y) [1,2,3,4,5] [6,7,8,9];
map2 (fn x => fn y => (x,y)) ["one","two","three"] [1,2,3];
map2 (fn x => fn y => x @ y) [[1,2,3],[4],[6]] [[],[8,4]];

(* Examples for Question 3 *)

map valid_date 
    [dt(1, Jan,1900), dt(32,Jan,1910), dt(29,Feb,1924), 
     dt(29,Feb,1925), dt(15,Mar,2101)];

days_since_1900 (dt(1,Jan,1900));
days_since_1900 (dt(1,Jan,1901));
days_since_1900 (dt(1,Jan,1902));
days_since_1900 (dt(1,Jan,1903));
days_since_1900 (dt(1,Jan,1904));
days_since_1900 (dt(1,Jan,1905));
				 
days_since_1900 (dt(1,Feb,1900));
days_since_1900 (dt(1,Mar,1900));

days_since_1900 (dt(8,Jul,1999));
days_since_1900 (dt(2,Apr,2002));

(* If you were born on 8 July 1999, you would be alive 1000 days
   on 2 April 2002.  *)

days_since_1900 (dt(2, Apr,2002)) - days_since_1900 (dt(8, Jul,1999)) + 1;
days_since_1900 (dt(12,Apr,2002)) - days_since_1900 (dt(11,Dec,1956)) + 1;

(* Examples for Question 4 *)

val tree1 = Nod(Nod(Lf 1, Lf 2), Lf 3);
val tree2 = Nod(Lf 1, Nod(Lf 2, Lf 3));
val tree3 = Nod(Lf 1, Nod(Lf 2, Lf 4));

eq_frontier (tree1, tree1);
eq_frontier (tree1, tree2);
eq_frontier (tree1, tree3);
eq_frontier (tree2, tree3);