Add #40 Ruby solution