Wrote an algorithm that I thought would work, but returns error code.  To fix up later.