Now, I want to write a function for some kind of list. The input list includes many integers. Take a simple example for f[x],
lst = {3, 6, 13};
f[x_ /; (x <= lst[[1]] && x >= 1 )] := 1;
f[x_ /; (x <= (lst[[1]] + lst[[2]]) && x >= (lst[[1]] + 1) )] := 2;
f[x_ /; (x <= (lst[[1]]+lst[[2]] + lst[[3]])&& x >= (lst[[1]] + lst[[2]] + 1))] := 3;
How to write a simple and general function f[x] for a arbitrary list ?
Accumulate[]might be useful. – J. M.'s missing motivation Jul 29 '16 at 13:11