Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Course: ENCMP 100
- % Assignment: 2
- % Name:
- % CCID:
- % U of A ID:
- %
- % Acknowledgements:
- % I refered to the MatLab documentation while writing.
- %
- % Description:
- % This program is meant to decode a secret code according to rules outlined
- % in the project description.
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- clc;
- clear;
- code = int2str(input("Please enter a code to break: "));
- intArr = (1:9);
- if(length(code) == 9) %%Test for correct code length
- sum = 0;
- for x = 1:length(code) %%Put the code into an integer array
- intArr(x) = str2double(code(x));
- end
- for i = 1:length(intArr) %%Sum all digits of the code
- sum = sum + intArr(i);
- end
- if(2*int8(sum / 2) == sum) %% Test for even code
- day = intArr(1)*intArr(3) - intArr(5);
- sDay = '';
- switch day
- case 1
- sDay = 'Monday';
- case 2
- sDay = 'Tuesday';
- case 3
- sDay = 'Wednesday';
- case 4
- sDay = 'Thursday';
- case 5
- sDay = 'Friday';
- case 6
- sDay = 'Saturday';
- case 7
- sDay = 'Sunday';
- otherwise
- disp("Decoy message: Invalid rescue day.");
- return;
- end
- if(rem(intArr(2)*intArr(4)-intArr(6), 3) == 0) %%If divisible by 3
- loc = intArr(7) - intArr(9);
- else
- loc = intArr(8) - intArr(9);
- end
- sLoc = '';
- switch loc
- case 1
- sLoc = 'the bridge.';
- case 2
- sLoc = 'the library.';
- case 3
- sLoc = 'the river crossing.';
- case 4
- sLoc = 'the airport.';
- case 5
- sLoc = 'the bus terminal.';
- case 6
- sLoc = 'the hospital.'
- case 7
- sLoc = 'St. Petes Church.';
- otherwise
- disp("Decoy message: Invalid rendezvous point.");
- return;
- end
- disp("Rescue on " + sDay + " at " + sLoc);
- else
- disp("Decoy message: Sum is odd.");
- end
- else
- disp("Decoy message: Not a nine-digit number.");
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement