For me the most tricky part in Ocaml is reading the values from stdin so that I dont get NZEC or WA.
At the moment the only safe way I know is a combination of read_line() and Scanf.sscanf.
For example for FENCE1 I read the input like this. The value is stored in u after reading.
let su = read_line() in
let u = Scanf.sscanf su "%d" (fun i -> i) in
For NSTEPS I read the input like this. The values x and y are forwarded to the function nsteps after reading.
let sr = read_line() in
Scanf.sscanf sr "%d %d" nsteps;
Are there any smarter or shorter ways of doing this?
created
last reply
- 1
reply
- 1.2k
views
- 2
users