https://alandroidnet.com/related/triangular algorithm