working implementation of triangle