Solves Problem 1 in PHP