sicp problems 1.22 and 1.23 in ruby