Traingle Algorithm Implementation