Can you find some relation

Aug 2016
1
0
india
hey everyone , I am writing a computer program but I am stuck somewhere
If you can find any logic or relation between the following data so I can handle of them in one single statement ?

i j

1 2
2 5
3 3
4 1
5 4
 

romsek

Math Team
Sep 2015
2,679
1,481
USA
Even if there is some arcane input output relationship between these two arrays it's fairly poor programming to try and force some sort of mathematical formula to describe it. With hardware resources being a mostly insignificant concern these days clarity is a more important property of good code.

how about this statement... (in C)

j = switch {
case 1 : 2;
case 2 : 5;
case 3 : 3;
case 4 : 1;
case 5 : 4;
default : printf(stderr, "Undefined input\n");
}

or a more typical way of doing this is with an array.

int f = {2,5,3,1,4};

j = f[i+1];
 
Last edited:
Dec 2013
212
72
some subspace
If one really wish to write a formula for it, maybe \(\displaystyle j = \frac{5}{6}i^3 - 7\tfrac{1}{2}i^2 + 19\tfrac{2}{3}i - 11\) works.
 
Aug 2016
273
32
morocco
2+3*(i-1)-5/20*(i-1)(i-2)+5/6*(i-1)(i-2)(i-3).
we use finite differences of Newton method of polynomial interpolation.