Solution to coding exercise from bikram - first pass