Pure function with static variables

Anonymous Coward 2018-04-14 15:59:10.562352 UTC

1int f(int l, int r) {
2 static int l0 = 0;
3 static int r0 = -1;
4 static int s = 0;
5 while(r0 < r) s += ++r0;
6 while(r0 > r) s -= r0--;
7 while(l0 < l) s -= l0++;
8 while(l0 > l) s += --l0;
9 return s;
10}