completed 5 and 6

5 turned out to be too slow, but 6 solved that