Ad
  • Default User Avatar

    This actually doesn't work... I put a "/ 3" in at the end of the divisible by 15 if variation. Because of this, every number x divisible by 15 that is input will be off by x in the negative direction. To correct this, the first three if loops could be collapsed into one that says (value % 3 == 0 || value % 5 == 0).

    Also, after some testing, it turns out the mathematical solution above is more efficient with larger numbers whereas the solution involving iterating through all of the numbers is faster on smaller numbers.