Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Zig-zag-matrix/OCaml/zig-zag-matrix.ocaml
Normal file
19
Task/Zig-zag-matrix/OCaml/zig-zag-matrix.ocaml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
let zigzag n =
|
||||
(* move takes references and modifies them directly *)
|
||||
let move i j =
|
||||
if !j < n - 1 then begin
|
||||
i := max 0 (!i - 1);
|
||||
incr j
|
||||
end else
|
||||
incr i
|
||||
in
|
||||
let a = Array.make_matrix n n 0
|
||||
and x = ref 0 and y = ref 0 in
|
||||
for v = 0 to n * n - 1 do
|
||||
a.(!x).(!y) <- v;
|
||||
if (!x + !y) mod 2 = 0 then
|
||||
move x y
|
||||
else
|
||||
move y x
|
||||
done;
|
||||
a
|
||||
Loading…
Add table
Add a link
Reference in a new issue