Sum of a repeating pattern of numbers

1.3k Views Asked by At

Consider a pattern, in which 5 repeats 3 times & 4 repeats 1 time. $$5,5,5,4,5,5,5,4,5,5,5,4,...$$

Help me find terms count, when sum of the pattern is at least S.

For example,
if S=29, pattern would be $5+5+5+4+5+5=29$, terms count is 6.
if S=20, pattern would be $5+5+5+4+5=24$, terms count is 5.

2

There are 2 best solutions below

0
On BEST ANSWER

Note that you have cycles of $$5+5+5+4$$ and may be a few extra terms.

We have $$5+5+5+4=19$$ so the first step is to divide your S by 19 and then fit the remainder into your cycle.

For example if you have $S=123$, then $123= 6(19)+9$ so you have 6 cycles and the remainder of 9 indicates that you can fit two $5$ into your string.

Therefore the length of your string is $6(4)+2 = 26$ and the string is $$5+5+5+4 + 5+5+5+4 +5+5+5+4+5+5+5+4+5+5+5+4+5+5+5+4+5+5$$

1
On

Let $S=19\cdot n+k$ where $n,k\in\mathbb{N}_0$ and $k<19$. We choose $19$ because the pattern repeats completely each 4 Digits and they sum up to 19. Hence we have at least $4n=4\lfloor \frac{S}{19}\rfloor$ terms.

So we have determined $n$ and therefore $k$. That is enough to calculate the remaining Terms. You can make a table for the 19 cases ($k=0,\ldots,18$) and if you try some pattern recognition yourself, find an exact formula.