Skip to content

Instantly share code, notes, and snippets.

@enedil

enedil/f.ml Secret

Last active December 16, 2018 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enedil/7fca66a9726f499dad332d4d18c290f7 to your computer and use it in GitHub Desktop.
Save enedil/7fca66a9726f499dad332d4d18c290f7 to your computer and use it in GitHub Desktop.
let update (x, y) (i, j) =
if !y - !x < !j - !i then
(
y := !j;
x := !i;
);
let triangle arr =
if Array.length arr < 3 then arr else
let arr = Array.copy arr in
let i = ref 0 in
let j = ref 2 in
let best = (ref 0, ref 2) in
let (i, j) =
begin
while !j < Array.length arr do
(
(
if arr.(!i) + arr.(!i+1) > arr.(!j) then
j := !j + 1
else
i := !i + 1
);
update best (i, j)
);
done;
best
end
in (i, j)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment