KhayyamTriangle solution nonrecursive