-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha3.ml
More file actions
36 lines (30 loc) · 1.02 KB
/
a3.ml
File metadata and controls
36 lines (30 loc) · 1.02 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
let squareSize x =
let rec aux acc n =
if acc * acc > n then acc else aux (acc + 2) n
in aux 1 x;;
let innerSquareSize x =
let size = squareSize x in
((size - 2 ) * (size - 2));;
let diff x = x - innerSquareSize x;;
let rest x =
let diff = diff x in
let squareSize = squareSize x in
Printf.printf "diff : %d\n" diff;
Printf.printf "squareSize : %d\n" squareSize;
diff mod (squareSize - 1);;
let steps x =
let center = ((squareSize x) + 1) / 2 in
let rest = rest x in
Printf.printf "rest : %d\n" rest;
let coord1 = if rest + 1 > center then rest + 1 - center else center - rest - 1 in
let coord2 = center -1 in
Printf.printf "coord1 : %d\n" coord1;
Printf.printf "coord2 : %d\n" coord2;
coord1 + coord2;;
(*
Data from square 1 is carried 0 steps, since it's at the access port.
Data from square 12 is carried 3 steps, such as: down, left, left.
Data from square 23 is carried only 2 steps: up twice.
Data from square 1024 must be carried 31 steps.
*)
Printf.printf "steps : %d\n" (steps 368078);;