8 kyu

Sum of Multiples

12,346 of 25,514m47r1x

Description:

Your Job

Find the sum of all multiples of n below m

Keep in Mind

  • n and m are natural numbers (positive integers)
  • m is excluded from the multiples

Examples

sumMul(2, 9)   ==> 2 + 4 + 6 + 8 = 20
sumMul(3, 13)  ==> 3 + 6 + 9 + 12 = 30
sumMul(4, 123) ==> 4 + 8 + 12 + ... = 1860
sumMul(4, -7)  ==> "INVALID"
Kata.SumMul(2, 9)   => 2 + 4 + 6 + 8 = 20
Kata.SumMul(3, 13)  => 3 + 6 + 9 + 12 = 30
Kata.SumMul(4, 123) => 4 + 8 + 12 + ... = 1860
Kata.SumMul(4, 1)   // throws ArgumentException
Kata.SumMul(0, 20)  // throws ArgumentException
sum_mul(2, 9)   ==> 2 + 4 + 6 + 8 = 20
sum_mul(3, 13)  ==> 3 + 6 + 9 + 12 = 30
sum_mul(4, 123) ==> 4 + 8 + 12 + ... = 1860
sum_mul(4, -7)  ==> "INVALID"
Kata.sumMul(2, 9)   ==> 2 + 4 + 6 + 8 = 20
Kata.sumMul(3, 13)  ==> 3 + 6 + 9 + 12 = 30
Kata.sumMul(4, 123) ==> 4 + 8 + 12 + ... = 1860
Kata.sumMul(4, -7)  // throws IllegalArgumentException
sumMul(2, 9)   // => 2 + 4 + 6 + 8 = Some(20)
sumMul(3, 13)  // => 3 + 6 + 9 + 12 = Some(30)
sumMul(4, 123) // => 4 + 8 + 12 + ... = Some(1860)
sumMul(4, -7)  // => None (m must be greater than 0)
sumMul(-4, 7)  // => None (n must be greater than 0)
sumMul(0, 2)   // => None
sumMul(2, 0)   // => None
      SumMul(2, 9)   => 2 + 4 + 6 + 8 = 20
      SumMul(3, 13)  => 3 + 6 + 9 + 12 = 30
      SumMul(4, 123) => 4 + 8 + 12 + ... = 1860
      SumMul(4, 1)   => -1
      SumMul(0, 20)  => -1
Fundamentals

More By Author:

Check out these other kata created by m47r1x

Stats:

CreatedApr 30, 2016
PublishedApr 30, 2016
Warriors Trained41156
Total Skips1932
Total Code Submissions122598
Total Times Completed25514
JavaScript Completions12346
Ruby Completions652
Python Completions9099
C# Completions1182
R Completions269
Groovy Completions77
Haskell Completions284
Java Completions2220
Scala Completions44
COBOL Completions9
Total Stars333
% of votes with a positive feedback rating87% of 3041
Total "Very Satisfied" Votes2414
Total "Somewhat Satisfied" Votes466
Total "Not Satisfied" Votes161
Ad
Contributors
  • m47r1x Avatar
  • jhoffner Avatar
  • fenring76 Avatar
  • GiacomoSorbi Avatar
  • lancelote Avatar
  • anter69 Avatar
  • donaldsebleung Avatar
  • aweleshetu Avatar
  • Chrono79 Avatar
  • Madjosz Avatar
  • Souzooka Avatar
  • KenKamau Avatar
  • mentalplex Avatar
  • metagn Avatar
  • monadius Avatar
  • hobovsky Avatar
  • kirull Avatar
  • shagie Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • dfhwze Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
  • saudiGuy Avatar
Ad