Find current step in a series of numbers

jbltx

I try to create a simple function in C which permit us to find the current step of a series of number by giving the current line number, the total number of lines, and the number of steps...

Example of numbers series :

line 0  - 0   --
line 1  - 0     |--> STEP 1
line 2  - 0   --
line 3  - 1   --
line 4  - 1     |--> STEP 2
line 5  - 1     |
line 6  - 1   --
line 7  - 2   --
line 8  - 2     |
line 9  - 2     |--> STEP 3
line 10 - 2     |
line 11 - 2   --

Parameters : currentLine = 5; totalLines = 12; steps = 3;

I have three different steps in this case, all steps are incremented by one more line. Each step is represented by the same number, next to line numbers.

In my example, I choose currentLine = 5, which represents the line where we want to find the current step. So in my case I need to find : 2.

My prototype of my function giving the current step of the current line :

int findCurrentStep(int currentLine, int totalLines, int steps);

I just want to know how to calculate it ?

EDIT : Thank you for your answers, I just made another method.

int findCurrentStep(int currentLine, int totalLines, int steps)
{
    int step;
    int trim_lines;

    step = steps;
    trim_lines = totalLines;
    while (currentLine <= trim_lines -1)
    {
        trim_lines = totalLines - 3 + steps - 1;
        step--;
    }
    return step;
}

This works with just one step, but no several ones...

Am_I_Helpful

EDIT : -

This is a 1-step solution.

You need to find that the currentLine is equal or less than which first r-terms of the AP starting with 3. The first term whose sum overall surpasses currentLine would be the currentStep.

Let's suppose that currentLine is less than or equal to sum of first r terms of AP.

So, currentLine <= 3 + ... + 3 + (r-1) * 1.

PSEUDO-CODE :-

initialStep = 3;  // initialStep is 3 in this case.
sum = currentLine;  .
currentStep = 0;
while(sum > initialStep){
   sum -= initialStep;
   initialStep = intialStep + 1;
   currentStep++;
}
requiredAnswer = currentStep + 1;

Your answer would be (currentStep + 1) after the loop as the loop would be terminated when the condition would fail.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

LINQ to find series of consecutive numbers

From Dev

Find ranges from a series of numbers in SQL/Oracle

From Dev

Find ranges from a series of numbers in SQL/Oracle

From Dev

Create a program with php that will find the missing number in the series of numbers

From Dev

Algorithm to find indices of two numbers in Series with difference within a specified range

From Dev

how to find the appropriate math function for series with random numbers in Excel

From Dev

Find sequence gaps within multiple series of sequential numbers

From Dev

find the sum of all the numbers in the Fibonacci series that are smaller or equal to that number

From Java

Step out of current function with GDB

From Dev

In Java how to calculate a series of numbers to find the product, that is passed to a method that uses a variable-length argument list

From Dev

Generate series of numbers in Excel

From Dev

Flatten or Smoothing a Series of Numbers

From Dev

Calling previous step from the current step in the spring batch

From Dev

Pass current step output to next step and write to flatfile

From Dev

Pass current step output to next step and write to flatfile

From Dev

Cucumber: Unable to find step definition

From Dev

Find what step N is in Behat

From Dev

How to get the current executing step information in Specflow

From Dev

How to get the current behave step with Python?

From Dev

How to get the current behave step with Python?

From Dev

sorting series of numbers by swaping adjacent numbers

From Dev

Formula in Excel or Numbers to generate a series of numbers

From Dev

Generation and summation of series of natural numbers for a list of numbers

From Dev

How to change increasing series of numbers?

From Dev

SQL - predicate on an ordered series of numbers

From Dev

Compress series of close numbers in C

From Dev

How to sum a series of numbers in bash

From Dev

Convert series of numbers to array in Python

From Dev

How to add series of numbers in Java

Related Related

  1. 1

    LINQ to find series of consecutive numbers

  2. 2

    Find ranges from a series of numbers in SQL/Oracle

  3. 3

    Find ranges from a series of numbers in SQL/Oracle

  4. 4

    Create a program with php that will find the missing number in the series of numbers

  5. 5

    Algorithm to find indices of two numbers in Series with difference within a specified range

  6. 6

    how to find the appropriate math function for series with random numbers in Excel

  7. 7

    Find sequence gaps within multiple series of sequential numbers

  8. 8

    find the sum of all the numbers in the Fibonacci series that are smaller or equal to that number

  9. 9

    Step out of current function with GDB

  10. 10

    In Java how to calculate a series of numbers to find the product, that is passed to a method that uses a variable-length argument list

  11. 11

    Generate series of numbers in Excel

  12. 12

    Flatten or Smoothing a Series of Numbers

  13. 13

    Calling previous step from the current step in the spring batch

  14. 14

    Pass current step output to next step and write to flatfile

  15. 15

    Pass current step output to next step and write to flatfile

  16. 16

    Cucumber: Unable to find step definition

  17. 17

    Find what step N is in Behat

  18. 18

    How to get the current executing step information in Specflow

  19. 19

    How to get the current behave step with Python?

  20. 20

    How to get the current behave step with Python?

  21. 21

    sorting series of numbers by swaping adjacent numbers

  22. 22

    Formula in Excel or Numbers to generate a series of numbers

  23. 23

    Generation and summation of series of natural numbers for a list of numbers

  24. 24

    How to change increasing series of numbers?

  25. 25

    SQL - predicate on an ordered series of numbers

  26. 26

    Compress series of close numbers in C

  27. 27

    How to sum a series of numbers in bash

  28. 28

    Convert series of numbers to array in Python

  29. 29

    How to add series of numbers in Java

HotTag

Archive