# Thread: Devising an algorithm based on a pattern in a number series.

1. ## Devising an algorithm based on a pattern in a number series.

Hello folks,

My name is Skyliner, I'm a computer science student and I'm making a very small program that performs some calculations based on a series of numbers.
My problem comes from trying to improve the original algorithm used to generate such numbers. I won't go into details, suffice to say that it involves as much as 10 conditional checks modifying values arbitrarily, in order to obtain the desired numbers.

I believe such a rudimentary approach is not only brute and inefficient, it is unnecessary. As you'll see there is a simple pattern in these numbers, a much simpler generation algorithm is bound to exist. My inferior, or rather non-existant mathematical skills, however, do not allow me to find it. Still, by pure stubbornness, I've come close to a correct formula, which sadly is not precise enough.

I was hoping you guys could help me out.
Thank you.

The problem goes like this: for every given seed (level) a number must be generated that corresponds exactly to a specific value. If we increase the seed sequentially, it is easy to identify a pattern in the generated numbers. I'm looking to create a formula, that returns the appropriate value (basePrecision) for whichever level is given.
Here are the numbers:
Spoiler:

Code:
level: 1 basePrecision is: 24
level: 2 basePrecision is: 28
level: 3 basePrecision is: 32
level: 4 basePrecision is: 36
level: 5 basePrecision is: 40
level: 6 basePrecision is: 44
level: 7 basePrecision is: 48
level: 8 basePrecision is: 52
level: 9 basePrecision is: 56
level: 10 basePrecision is: 62
level: 11 basePrecision is: 68
level: 12 basePrecision is: 74
level: 13 basePrecision is: 80
level: 14 basePrecision is: 86
level: 15 basePrecision is: 92
level: 16 basePrecision is: 98
level: 17 basePrecision is: 104
level: 18 basePrecision is: 110
level: 19 basePrecision is: 116
level: 20 basePrecision is: 124
level: 21 basePrecision is: 132
level: 22 basePrecision is: 140
level: 23 basePrecision is: 148
level: 24 basePrecision is: 156
level: 25 basePrecision is: 164
level: 26 basePrecision is: 172
level: 27 basePrecision is: 180
level: 28 basePrecision is: 188
level: 29 basePrecision is: 196
level: 30 basePrecision is: 206
level: 31 basePrecision is: 216
level: 32 basePrecision is: 226
level: 33 basePrecision is: 236
level: 34 basePrecision is: 246
level: 35 basePrecision is: 256
level: 36 basePrecision is: 266
level: 37 basePrecision is: 276
level: 38 basePrecision is: 286
level: 39 basePrecision is: 296
level: 40 basePrecision is: 308
level: 41 basePrecision is: 320
level: 42 basePrecision is: 332
level: 43 basePrecision is: 344
level: 44 basePrecision is: 356
level: 45 basePrecision is: 368
level: 46 basePrecision is: 380
level: 47 basePrecision is: 392
level: 48 basePrecision is: 404
level: 49 basePrecision is: 416
level: 50 basePrecision is: 412
level: 51 basePrecision is: 428
level: 52 basePrecision is: 444
level: 53 basePrecision is: 460
level: 54 basePrecision is: 476
level: 55 basePrecision is: 492
level: 56 basePrecision is: 508
level: 57 basePrecision is: 524
level: 58 basePrecision is: 540
level: 59 basePrecision is: 556
level: 60 basePrecision is: 572
level: 61 basePrecision is: 588
level: 62 basePrecision is: 604
level: 63 basePrecision is: 620
level: 64 basePrecision is: 636
level: 65 basePrecision is: 652
level: 66 basePrecision is: 668
level: 67 basePrecision is: 684
level: 68 basePrecision is: 700
level: 69 basePrecision is: 716
level: 70 basePrecision is: 734
level: 71 basePrecision is: 752
level: 72 basePrecision is: 770
level: 73 basePrecision is: 788
level: 74 basePrecision is: 806
level: 75 basePrecision is: 824
level: 76 basePrecision is: 842
level: 77 basePrecision is: 860
level: 78 basePrecision is: 878
level: 79 basePrecision is: 896
level: 80 basePrecision is: 916

This is the formula I came up with:
(level * .1 + 3.2) * level + 20
It works, but it's completely off in some cases. So much that even playing around with approximation will not yield accurate results.

PS:The seed can only be in the range 1-80.

2. ## Re: Devising an algorithm based on a pattern in a number series.

Here is some pseudo-code that should work:

basePrecision=20

for n = 1 to level

basePrecision = basePrecision + 2*int(n/10)+4

next n

3. ## Re: Devising an algorithm based on a pattern in a number series.

Well that works quite alright.
I was expecting a complicated math algorithm and yet you hit me with this... simple no brainer solution. I feel ashamed.

Thank you!

4. ## Re: Devising an algorithm based on a pattern in a number series.

Someone more knowledgeable about recursions involving the floor function may be able to provide you with a closed-form solution, but that was the best I could do in a reasonable amount of time.