Triangle problem without Recursion