-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathassignment1sub.ml
More file actions
97 lines (69 loc) · 2.99 KB
/
assignment1sub.ml
File metadata and controls
97 lines (69 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(* This is an OCAML comment *)
(*
You should write your functions in this file.
All your functions should have their parameter types specified.
Write your code right below the corresponding comment describing the
function you are asked to write.
*)
(*
Write a function named "fixLastTwo" that takes a triple of integers
(x, y, z) and possibly rearranges the last two so that they are in increasing
order (and just keeps the first in place).
It should have type: int * int * int -> int * int * int
*)
(*
Write a function named "order" that takes a triple of integers and
returns a triple of the same integers but in increasing order.
You may want to use the function from the previous part.
It should have type: int * int * int -> int * int * int
*)
(*
Write a function "distance" that given a pair of integers returns the
distance between them. For instance the distance between 10 and 4 is 6,
as is the distance between 4 and 10.
It should have type: int * int -> int
*)
(*
Write a function "greeting" that given a pair of an integer (age) and
a string (name) creates the string: "Greetings <name>, you are <age> years old!".
You will need to look in the Pervasives module for "string concatenation"
and for how to convert an int to a string (NOT to a char).
It should have type: int * string -> string
You may see "bytes" instead of "string" as a type.
*)
(*
Write a function "greeting2" that is similarly given a pair of an integer (age)
and a string (name) and creates the string: "Greetings <name>, you are ..." where
the dots depend on the age:
- If the age is 0 or less, it should say "not born yet!".
- If the age is 1 to 20, it should say "a youngster!".
- If the age is more than 20, it should say "young at heart!".
It should have type: int * string -> string
You may see "bytes" instead of "string" as a type.
*)
(*
Write a function "tooShort" that is given a pair of an integer and a string
and returns a boolean indicating whether that integer is strictly larger than
the length of the string. The function "String.length" returns the length of
a string.
It should have type: int * string -> bool
*)
(*
Write a function "totalLength" that is given a pair of strings and returns
their total length.
It should have type string * string -> int
*)
(*
Write a function "orderedByLength" that is given a triple of strings and returns
a boolean indicating whether the strings are ordered in increasing length. For a
fully correct solution, your code should not compute the length of a specific
string more than once.
It should have type: string * string * string -> bool
*)
(*
Write a function "prodInRange" that is given a pair of integers, and it returns
a boolean indicating whether their product is strictly between 10 and 20. For a
fully correct solution, your code should not compute the product of the two
integers more than once.
It should have type: int * int -> bool
*)