Cleaned up code and added comments to Problem 8 (in ruby)