Solution for 006 in ruby