Thank you to everybody for the comments. I already solved the problem 161 some months ago but I didn't keep my solution. I did it as a dynamic programming solution in C/C++ or Python if I remember correctly.
Some days ago I was looking at the solutions present in the forum and decided to re-implement the C++ solution of stijn263 in Python (it tooks 4.5 secondsin Python) and then in J. I know that J should be used the J-way but was just for fun. :-) I almost never used amended array before. I supposed to have a performance comparable with that of the Python implementation but it seems that the current implementation of amend make the porting of some traditional algorithms to J quite difficult. :-/ MfG Luca Masini ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
