My solution for Nulogy's coding question