clc disp('Pick any number at random from the first row of the following'); disp('matrix. Whatever number you choose, count to the right that '); disp('many spaces. If you get to the end of a row, continue counting '); disp('from the first column in the next row. Keep doing this until '); disp('you get to a number that makes you count beyond the end of the '); disp('last row. Remember this last number and see if the computer''s '); fprintf('psychic powers can figure out which number it is.\n\n'); a = randint(10,10,[1 9]); aVector = a'; aVector = aVector(:) ; i = 1; disp(a); while true if (i + aVector(i) > length(aVector)) fprintf('\n\nI read your mind while you were working.\n\n'); fprintf('Press any key for the answer.'); pause; fprintf('\nAnswer: %d\n\n',aVector(i)); break; else i = i + aVector(i); end end