Problem set 5 of CS50x