Execute SNUSP/OCaml: Difference between revisions
Content added Content deleted
m (→{{header|OCaml}}: added bounds) |
|||
Line 27: | Line 27: | ||
let ruld (x,y) = (y,x) |
let ruld (x,y) = (y,x) |
||
let lurd (x,y) = (-y,-x) |
let lurd (x,y) = (-y,-x) |
||
⚫ | |||
let incr (l,v,r) = (l,v+1,r) |
let incr (l,v,r) = (l,v+1,r) |
||
Line 45: | Line 43: | ||
let zero = function (_,0,_) -> true | _ -> false |
let zero = function (_,0,_) -> true | _ -> false |
||
⚫ | |||
⚫ | |||
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) = |
let get_char code (x,y) = |
||
if x < 0 || y < 0 || x > max_x || y > max_y then raise Exit; |
|||
try code.(y).[x] |
try code.(y).[x] |
||
with _ -> '\000' |
with _ -> '\000' |
||
let () = |
let () = |
||
⚫ | |||
let rec loop pos dir cells stk = |
let rec loop pos dir cells stk = |
||
match (get_char code pos) with |
match (get_char code pos) with |