7 kyu

Sums of consecutive integers

1,120 of 1,798andrewferk

Description:

The sum of x consecutive integers is y. What is the consecutive integer at position n? Given x, y, and n, solve for the integer. Assume the starting position is 0.

For example, if the sum of 4 consecutive integers is 14, what is the consecutive integer at position 3?

We find that the consecutive integers are [2, 3, 4, 5], so the integer at position 3 is 5.

position(4, 14, 3) == 5

Assume there will always be a sum of x consecutive integers that totals to y and n will never be indexed out of bounds.

Mathematics
Algorithms

More By Author:

Check out these other kata created by andrewferk

Stats:

CreatedJul 26, 2015
PublishedJul 26, 2015
Warriors Trained5172
Total Skips537
Total Code Submissions6409
Total Times Completed1798
JavaScript Completions1120
C# Completions335
Python Completions398
Total Stars73
% of votes with a positive feedback rating91% of 293
Total "Very Satisfied" Votes251
Total "Somewhat Satisfied" Votes33
Total "Not Satisfied" Votes9
Ad
Contributors
  • andrewferk Avatar
  • alchemy Avatar
  • Marsroverr Avatar
  • hobovsky Avatar
  • bornForThis Avatar
  • Rud1 Avatar
Ad