Rowhawn
Rowhawn

Reputation: 1479

Tips for finding patterns in an array

I have an array of 256 values. Those 256 values were calculated in some mysterious way, and range from 0-3 inclusive. To increase the efficiency of my program, I can calculate the results of the array given an index, rather than actually looking up in the array.

Basically, the program gives me an index, which would be looked up in the array, but I know that I can actually calculate what will be in that index using the index number itself.

For example

a[0] = 3, a[1] = 2, a[2] = 1, ... , a[254] = 1, a[255] = 1

I'm not actually asking for the calculation here, but looking at every number in the array, what are some tips on figuring out the pattern? I apologize if this is poorly worded, I'll attempt to clear up any questions.

Upvotes: 0

Views: 350

Answers (1)

Tony Arkles
Tony Arkles

Reputation: 1946

There likely isn't a general approach to solving this problem without having some idea about the function that generated the data. You mentioned "efficiency" — if there really are only 256 values and the function to generate the data has any kind of computational complexity, it's probably more efficient to just keep it as an array.

Upvotes: 1

Related Questions