-
-
Save enedil/7fca66a9726f499dad332d4d18c290f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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