first attempt at ruby code for this problem