Reimplementation of PHP solutions to problems 1 and 6.