instargam algorithm