Didn't solve since there was a method in ruby math library.