Pied Piper algorithm