coded second version of the algorithm to generate the sequences, but it needs serious debugging to pass the unit tests