python solution from 31 adapted to euler76.