finished problem 18 and 67 (related) in ruby