:ok_hand: Problem 40

ruby p40.rb  0.56s user 0.10s system 98% cpu 0.669 total