Code for 4th lecture exercises solutions