Problem set 2, implemented without CS50 library