summaryrefslogtreecommitdiff
path: root/src/wall.ml
diff options
context:
space:
mode:
Diffstat (limited to 'src/wall.ml')
-rw-r--r--src/wall.ml94
1 files changed, 57 insertions, 37 deletions
diff --git a/src/wall.ml b/src/wall.ml
index 6c11939..fd3f69d 100644
--- a/src/wall.ml
+++ b/src/wall.ml
@@ -57,16 +57,20 @@ module Make (A : Algebra) =
let has_value wall ~x ~y =
if x >= 0 && x < x_length wall &&
y >= 0 && y < y_length wall
- then match wall.(x).(y) with
- None -> false
- | Some _ -> true
- else false
+ then
+ match wall.(x).(y) with
+ None -> false
+ | Some _ -> true
+ else
+ false
let get_opt wall ~x ~y =
if x >= 0 && x < x_length wall &&
y >= 0 && y < y_length wall
- then wall.(x).(y)
- else None
+ then
+ wall.(x).(y)
+ else
+ None
@@ -92,11 +96,13 @@ module Make (A : Algebra) =
let next_valid_left wall ~x ~y =
let rec walker x1 =
- if x1 < 0
- then None
- else if Option.is_some (get_opt wall ~x:x1 ~y)
- then Some x1
- else walker (x1-1) in
+ if x1 < 0 then
+ None
+ else
+ if Option.is_some (get_opt wall ~x:x1 ~y) then
+ Some x1
+ else
+ walker (x1-1) in
walker x
@@ -112,9 +118,10 @@ module Make (A : Algebra) =
A.mul a a
let rec power ~base ~num ~denom ~times =
- if times <= 0
- then Some base
- else let*? new_base = safe_div (A.mul base num) denom in
+ if times <= 0 then
+ Some base
+ else
+ let*? new_base = safe_div (A.mul base num) denom in
power ~base:new_base ~num ~denom ~times:(times-1)
@@ -160,9 +167,12 @@ module Make (A : Algebra) =
let*? top = next_nonzero_up wall ~x ~y:(y-1) in
let*? left = next_nonzero_left wall ~x ~y:(top+1) in
let*? right = next_nonzero_right wall ~x ~y:(top+1) in
- if y - 1 > top && right - left > 0 && right - left + 1 > y - 1 - top
- then Some A.zero
- else None
+ if y - 1 > top && right - left > 0 &&
+ right - left + 1 > y - 1 - top
+ then
+ Some A.zero
+ else
+ None
@@ -251,12 +261,14 @@ module Make (A : Algebra) =
let rec attempt_order wall ~x ~y funcs =
- if funcs = []
- then None
- else let r = (List.hd funcs) wall ~x ~y in
- if Option.is_some r
- then r
- else attempt_order wall ~x ~y (List.tl funcs)
+ if funcs = [] then
+ None
+ else
+ let r = (List.hd funcs) wall ~x ~y in
+ if Option.is_some r then
+ r
+ else
+ attempt_order wall ~x ~y (List.tl funcs)
let create ~dimx ~dimy ~init =
let result = Array.make_matrix dimx dimy None in
@@ -273,8 +285,10 @@ module Make (A : Algebra) =
let v = attempt_order result ~x:i ~y:j
[cross_rule; long_cross_rule; zero_window; horseshoe_rule; broken_cross_rule] in
result.(i).(j) <- v;
- if Option.is_some v && Option.get v <> A.zero
- then do_exit := false
+ if Option.is_some v &&
+ Option.get v <> A.zero
+ then
+ do_exit := false
done;
if !do_exit then raise Exit
done;
@@ -292,16 +306,21 @@ module Make (A : Algebra) =
let get wall ~x ~y =
if x >= 0 && x < x_length wall &&
y >= 0 && y < y_length wall
- then match wall.(x).(y) with
- None -> raise Not_found
- | Some v -> v
- else raise Not_found
+ then
+ match wall.(x).(y) with
+ None -> raise Not_found
+ | Some v -> v
+ else
+ raise Not_found
let last_nonzero_row wall =
let rec checker x y =
- if wall.(x).(y) <> Some A.zero && wall.(x).(y) <> None
- then (if y + 1 = y_length wall then y else checker 0 (y + 1))
- else (if x + 1 = x_length wall then y - 1 else checker (x + 1) y)
+ if wall.(x).(y) <> Some A.zero &&
+ wall.(x).(y) <> None
+ then
+ (if y + 1 = y_length wall then y else checker 0 (y + 1))
+ else
+ (if x + 1 = x_length wall then y - 1 else checker (x + 1) y)
in checker 0 0
@@ -310,13 +329,14 @@ module Make (A : Algebra) =
let result = ref "" in
for i = 0 to (x_length wall) - 2 do
let v = wall.(i).(y) in
- if Option.is_some v
- then result := !result ^ (A.to_string (Option.get v)) ^ ","
- else result := !result ^ ","
+ if Option.is_some v then
+ result := !result ^ (A.to_string (Option.get v)) ^ ","
+ else
+ result := !result ^ ","
done;
let v = wall.(x_length wall - 1).(y) in
- if Option.is_some v
- then result := !result ^ (A.to_string (Option.get v));
+ if Option.is_some v then
+ result := !result ^ (A.to_string (Option.get v));
!result
let to_string wall =