code from algorithms class on PMF in Sarajevo