-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogo (1).ml
166 lines (132 loc) · 3.64 KB
/
logo (1).ml
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
(* I pledge my honor that I have abided by the Stevens Honor System-
Aparajita Rana *)
type program = int list
let square : program = [0; 2; 2; 3; 3; 4; 4; 5; 5; 1]
let letter_e : program = [0;2;2;3;3;5;5;4;3;5;4;3;3;5;5;1]
let rec remove_vals: 'a -> 'a list -> 'a list = fun one two ->
match two with
| [] -> []
| x :: xs ->
if one=x
then remove_vals one xs
else x :: remove_vals one xs
let rec dup_remove: 'a list -> 'a list = fun one ->
match one with
| [] -> []
| x :: xs -> x :: dup_remove (remove_vals x xs)
let rec color: int*int -> int list -> int -> (int*int) list = fun init one two ->
match init, one, two with
| _, [], _ -> []
| (a,b), x::xs,1 ->
if x=0
then color (a,b) (x::xs) 0
else if x=2
then color (a,b+1) xs 1
else if x=3
then color (a+1,b) xs 1
else if x=4
then color (a, b-1) xs 1
else if x=5
then color (a-1, b) xs 1
else color (a,b) xs 1
| (a,b), x::xs, 0 ->
if x=0
then (a,b) :: color(a,b) xs 0
else if x=1
then color(a,b) xs 1
else if x=2
then (a,b+1) :: color(a, b+1) xs 0
else if x=3
then (a+1,b) :: color(a+1,b) xs 0
else if x=4
then (a,b-1) :: color(a,b-1) xs 0
else if x=5
then (a-1, b) :: color(a-1,b) xs 0
else color(a,b) xs 0
| _,_,_ -> []
let rec colored : int*int -> program -> (int*int) list = fun one two ->
match two with
| [] -> []
| x::xs -> dup_remove(color one (x:: xs) 1)
let rec eq : (int*int) list -> (int*int) list -> bool = fun one two ->
match one,two with
| [],[] -> true
| x::xs,[] -> false
| [],y::ys -> false
| x::xs,y::ys -> equivalence xs (remove_all x (y::ys))
let equivalent : program -> program -> bool = fun one two ->
eq (colored (0,0) one) (colored (0,0) two)
let rec mirror_image : program -> program = fun one ->
match one with
| [] -> []
| x::xs ->
if x = 0 || x=1
then x :: mirror_image xs
else if x = 2
then 4 :: mirror_image xs
else if x = 3
then 5 :: mirror_image xs
else if x = 4
then 2 :: mirror_image xs
else if x = 5
then 3 :: mirror_image xs
else mirror_image xs
let rec rotate_90 : program -> program = fun one ->
match one with
| [] -> []
| x::xs ->
if x = 0
then x :: rotate_90 xs
else if x = 1
then x :: rotate_90 xs
else if x = 2
then 3 :: rotate_90 xs
else if x = 3
then 4 :: rotate_90 xs
else if x = 4
then 5 :: rotate_90 xs
else if x = 5
then 2 :: rotate_90 xs
else rotate_90 xs
let rec repeat : int -> 'a -> 'a list = fun one two ->
match one with
| 0 -> []
| one -> two :: (repeat (one-1) two)
let rec pantograph : program -> int -> program = fun one two ->
match one,two with
| [],two -> []
| _,0 -> []
| x::xs,two ->
if x = 0 || x = 1
then x :: (pantograph xs two)
else if x > 1 || x < 6
then (repeat two x) @ (pantograph xs two)
else pantograph xs two
let rec delete : 'a list -> int -> 'a list = fun one two ->
match one,two with
| [],_ -> []
| x::xs,0 -> x::xs
| x::xs,two -> delete xs (two-1)
let rec iter: 'a list -> 'a -> int = fun one two ->
match one with
| [] -> 0
| x::xs ->
if x = two
then 1 + (iter xs two)
else 0
let rec compress : program -> (int*int) list = fun one ->
match one with
| [] -> []
| x::xs ->
if x > -1 || x < 6
then (x,(1 + iter xs x)) :: compress (delete xs (iter xs x))
else compress xs
let first_val : int*int -> int = fun (x, y) -> x
let second_val : int*int -> int = fun (x, y) -> y
let rec uncompress : (int*int) list -> program = fun one ->
match one with
| [] -> []
| x::xs ->
if first_val x > -1 && first_val x < 6 && second_val x > 0
then (repeat (second_val x) (first_val x)) @ (uncompress xs)
else uncompress xs