"Same" algorithm translated into a functions workflow.

It needs some tweaks and finish the join lines step.