How to write this small piece in a functional way (ie. without state variables)?:
test[oldJ_List, newJ_List] := Total[Abs[oldJ - newJ]] > 1;
relax[j_List, x_?NumericQ] := Mean[Nearest[j, x, 4]];
j = Range[100]; (* any numeric list *)
j1 = j/2; (*some initial value for the While[] test to return True*)
While[test[j1, j],
j1 = j;
(j[[#]] = relax[j, j[[#]]]) & /@ Range@Length@j]
test[]can also be defined astest[oldJ_List, newJ_List] := ManhattanDistance[oldJ, newJ] > 1. – J. M.'s missing motivation Sep 30 '12 at 09:52