This is the code I have but I was wondering if there is a more simple and efficient way to implement this. Basically, I am going from 15 to 1 but instead of decrementing with a single value i.e [15 14 13 12 … 2 1] I want to reach the target by different incrementation such as in the screenshot below the code i.e [15 14 18 16 13 12 … 4 1]
i = 1;v = 15;array(i) = 15;while array(i) ~= 1 i = i + 1; v = v - 1; array(i) = v; if array(i) == 1 break; end i = i + 1; v = v + 4; array(i) = v; if array(i) == 1 break; end i = i + 1; v = v - 2; array(i) = v; if array(i) == 1 break; end i = i + 1; v = v - 3; array(i) = v;enddisp(array)
Best Answer