while logic reduced to one line using rotate and shift