简体   繁体   中英

C# Algebra formula to find pattern

I am running some Running Totals functions which need to create a pattern but I am seriously struggling to find the right formula.

It is not a homework, just look at my profile ...

MinRow Represents for me the Row-1 where my Count should start, if MinRow = 3 I should start to count from 4

K is a constant value that I can use to calculate X

Example A:
MinRow = 2, K = 3
Expected
|---Row---|--X--|
|    3    |  2  |
|    4    |  4  |
|    5    |  6  |

Example B:
MinRow = 1, K = 5
Expected
|---Row---|--X--|
|    2    |  4  |
|    3    |  8  |
|    4    | 12  |

Example C:
MinRow = 27, K = 2
Expected
|---Row---|--X--|
|   28    |  1  |
|   29    |  2  |
|   30    |  3  |

Example B can be solved using X = (K * (Row-MinRow)) - (Row-MinRow) but it does not work for Example A or C. Do you think I can address these patterns using a common formula?

As @Evil Tak pointed out, this can be simplified to

X = (K - 1) * (Row - MinRow) 

and works for all three of your examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM