fast-triangle using tail recursion