This is not homework, I am a programmer and I encountered this problem in the implementation of an algorithm of mine.
I was wondering if the following can be done without the use of any auxiliary data structure (such as arrays) and without if statements or variable length loops, just by using some smart mathematical approach. I also thought about interpolation, but that seems to beat the purpose for this set of data.
Auxiliary variables can be used, but only such that they can contain an integer at most.
Is there a way to map all the numbers in the sets to the indicated value through the use of some function ? Maybe modulo operations ?
$S_0 = \text{{0, 3,6,27,30,33,54,57,60}} \rightarrow 0$
$S_1 = \text{{1, 4,7,28,31,34,55,58,61}} \rightarrow 1$
$S_2 = \text{{2, 5,8,29,32,35,56,59,62}} \rightarrow 2$
$S_3 =\text{{9, 12,15,36,39,42,63,66,69}} \rightarrow 3$
$S_4 =\text{{10, 13,16,37,40,43,64,67,70}} \rightarrow 4$
$S_5 =\text{{11, 14,17,38,41,44,65,68,71}} \rightarrow 5$
$S_6 =\text{{18, 21,24,45,48,51,72,75,78}} \rightarrow 6$
$S_7 =\text{{19, 22,25,46,49,52,73,76,79}} \rightarrow 7$
$S_8 =\text{{20, 23,26,47,50,53,74,77,80}} \rightarrow 8$
Basically I'm looking for a function $f$ that satisfies $f(s_{ij}) =i $ for any element $s_{ij}$ in the set $S_i$ that does the minimum number of computations.
I've been trying to connect the patterns for almost $3$ hours now, if anyone can help, I would be most grateful.