further progress on the log puzzle.
added the sorting function