DEV Community

Discussion on: Project Euler #1 - Multiples of 3 and 5

Collapse
 
likelocusts profile image
LikeLocusts

Scala:

def sumOfMultiples(max: Int): Int = {
    if (max <= 0) 0
    else if (max % 3 == 0 || max % 5 == 0) max + sumOfMultiples(max - 1)
    else sumOfMultiples(max - 1)
  }