a ruby algorithm to calculate the longest path in a directed graph