Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- disp('I would like to try to guess a number you are thinking of in three questions, 1 through ten.');
- disp('Please answer using yes or no.');
- disp('[Press any key to continue]');
- pause
- yes = 1;
- no = 0;
- prompt = 'Is the number divisible by 3? ';
- x(1) = input(prompt);
- if x(1) == 1;
- n1 = [3 6 9];
- elseif x(1) == 0;
- n1 = [1 2 4 5 7 8 10];
- end
- disp('hmmm...')
- disp('[Press any key to continue]');
- pause
- prompt = 'Is the number even? ';
- x(2) = input(prompt);
- if x(2) == 1;
- n2 = [2 4 6 8 10];
- elseif x(2) == 0;
- n2 = [1 3 5 7 9];
- end
- disp('erm...')
- disp('[Press any key to continue]');
- pause
- prompt = 'Is the number greater than 5? ';
- x(3) = input(prompt);
- if x(3) == 1;
- n3 = [6 7 8 9 10];
- elseif x(3) == 0;
- n3 = [1 2 3 4 5];
- end
- disp('ummm...')
- disp('[Press any key to continue]');
- pause
- m1 = ismember(n1,n2);
- M1 = m1.*n1;
- m2 = ismember(M1,n3);
- M2 = m2.*M1;
- N = M2(M2~=0);
- TF = isempty(N);
- if TF == 1
- disp(' Im pretty sure you are messing with me...')
- else
- disp(N(1));
- prompt = 'Was that your number? ';
- Z = input(prompt);
- if Z == 1;
- disp('Ha! I win!');
- elseif Z == 0;
- disp('Ok, fine, then your number is:')
- disp(N(2))
- end
- end
- pause
- clc
Advertisement
Add Comment
Please, Sign In to add comment