This repository was archived by the owner on Jan 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyse.ml
More file actions
49 lines (45 loc) · 1.33 KB
/
analyse.ml
File metadata and controls
49 lines (45 loc) · 1.33 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
let rec parse_line_1 n cin =
try
let s = input_line cin in
let a, b = Scanf.sscanf s "%s %s" (fun a b -> (a, b)) in
(a, b) :: parse_line_1 (n + 1) cin
with End_of_file -> []
let rec parse_line_2 n cin =
try
let s = input_line cin in
let a, b, c = Scanf.sscanf s "%s %s %d" (fun a b c -> (a, b, c)) in
(a, b, c) :: parse_line_2 (n + 1) cin
with End_of_file -> []
let phase1 filename =
if Array.length Sys.argv <> 2 then
let _ =
Format.fprintf Format.err_formatter "usage : %s <file>@." Sys.argv.(0)
in
assert false
else
let cin = open_in Sys.argv.(1) in
let src = input_line cin in
let dst = input_line cin in
let n = int_of_string (input_line cin) in
let le = parse_line_1 3 cin in
let _ = assert (n = List.length le) in
let _ = close_in cin in
(src, dst, le)
let phase2 () =
if Array.length Sys.argv <> 2 then
let _ =
Format.fprintf Format.err_formatter "usage : %s <file>@." Sys.argv.(0)
in
assert false
else
let cin = open_in Sys.argv.(1) in
let src = input_line cin in
let dst = input_line cin in
let _ = input_line cin in
let le = parse_line_2 3 cin in
let _ = close_in cin in
(src, dst, le)
let _ =
let l = phase1 () in
let start, goal, edges = l in
List.iter (fun (a, b) -> Format.printf "%s %s@." a b) edges