Problem set 4 of CS50x