Its possible with bubble and the trick is about conditionals on the group and use of modulo operator.