Working ruby code for problem4.