solution to Homework 3 Code golf