Execute SNUSP/OCaml: Difference between revisions

m
m (→‎{{header|OCaml}}: added bounds)
Line 27:
let ruld (x,y) = (y,x)
let lurd (x,y) = (-y,-x)
 
let next_pos ~pos:(x,y) ~dir:(dx,dy) = (x+dx, y+dy)
 
let incr (l,v,r) = (l,v+1,r)
Line 45 ⟶ 43:
 
let zero = function (_,0,_) -> true | _ -> false
 
let next_pos ~pos:(x,y) ~dir:(dx,dy) = (x+dx, y+dy)
 
let code = read Sys.argv.(1) in
let max_x = Array.fold_left (fun v line -> max v (String.length line)) 0 code
let max_y = Array.length code
 
let get_char code (x,y) =
if x < 0 || y < 0 || x > max_x || y > max_y then raise Exit;
try code.(y).[x]
with _ -> '\000'
 
let () =
let code = read Sys.argv.(1) in
let rec loop pos dir cells stk =
match (get_char code pos) with