6 kyu

Sum of a Sequence [Hard-Core Version]

65 of 1,772GiacomoSorbi

Description:

As the title suggests, this is the hard-core version of another neat kata.

The task is simple to explain: simply sum all the numbers from the first parameter being the beginning to the second parameter being the upper limit (possibly included), going in steps expressed by the third parameter:

sequenceSum(2,2,2) === 2
sequenceSum(2,6,2) === 12 // 2 + 4 + 6
sequenceSum(1,5,1) === 15 // 1 + 2 + 3 + 4 + 5
sequenceSum(1,5,3) === 5 // 1 + 4
sequence_sum(2, 2, 2) # 2
sequence_sum(2, 6, 2) # 12 (= 2 + 4 + 6)
sequence_sum(1, 5, 1) # (= 1 + 2 + 3 + 4 + 5)
sequence_sum(1, 5, 3) # 5 (= 1 + 4)
sequence_sum(2, 2, 2) # 2
sequence_sum(2, 6, 2) # 12 (= 2 + 4 + 6)
sequence_sum(1, 5, 1) # (= 1 + 2 + 3 + 4 + 5)
sequence_sum(1, 5, 3) # 5 (= 1 + 4)
sequence_sum(2, 2, 2) # 2
sequence_sum(2, 6, 2) # 12 (= 2 + 4 + 6)
sequence_sum(1, 5, 1) # (= 1 + 2 + 3 + 4 + 5)
sequence_sum(1, 5, 3) # 5 (= 1 + 4)
SequenceSum(2, 2, 2) # 2
SequenceSum(2, 6, 2) # 12 (= 2 + 4 + 6)
SequenceSum(1, 5, 1) # (= 1 + 2 + 3 + 4 + 5)
SequenceSum(1, 3, 5) # 1

If it is an impossible sequence (with the beginning being larger the end and a positive step or the other way around), just return 0. See the provided test cases for further examples :)

Note: differing from the other base kata, much larger ranges are going to be tested, so you should hope to get your algo optimized and to avoid brute-forcing your way through the solution.

Algorithms

Stats:

CreatedJan 14, 2017
PublishedJan 14, 2017
Warriors Trained5007
Total Skips154
Total Code Submissions13580
Total Times Completed1772
Ruby Completions65
Python Completions582
JavaScript Completions794
Crystal Completions9
C# Completions93
Haskell Completions43
C++ Completions227
COBOL Completions5
C Completions54
Total Stars154
% of votes with a positive feedback rating90% of 349
Total "Very Satisfied" Votes290
Total "Somewhat Satisfied" Votes45
Total "Not Satisfied" Votes14
Total Rank Assessments10
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • GiacomoSorbi Avatar
  • DivyanshBatham Avatar
  • lechevalier Avatar
  • EatYourBeetS Avatar
  • Voile Avatar
  • KataSideKick Avatar
  • hobovsky Avatar
  • cliffstamp Avatar
  • mouloud Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
  • geans Avatar
  • saudiGuy Avatar
Ad