algorithn for 2.2 completed