Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB. SOLVE WITHOUT USING CONDITIONALS OR LOOPS. Function Name: fruitLottery I

ID: 3881528 • Letter: M

Question

MATLAB. SOLVE WITHOUT USING CONDITIONALS OR LOOPS.

Function Name: fruitLottery Inputs: 1. 2. 3. (char) vector representing the 6 numbers on your lottery ticket (char) vector representing the 6 numbers on the winning ticket (double) The initial investment required to open a fruit store Outputs: 1. (logical) A logical representing whether you acquired the initial investment Background: do it. Desperate to get rich quick, you decide to buy a lottery ticket to try your luck You want to fulfill your lifetime dream of opening a fruit store, but don't have the cash to Function Description: This function will compare your lottery ticket number (first input) to the winning ticket number (second input) and calculate your winnings. The ticket numbers are composed of 6 positive integers separated only by dashes Rules for determining winnings from lottery ticket numbers 1. 2. 3. Example: Compare the first five integers in both numbers. For every integer in your lottery ticket number that matches any of the first five integers in the winning lottery ticket number, add $100,000 to your total prize If the last number matches, then double the prize amount determined by the first 5 numbers Compare your earnings to the required initial investment, and output a true if your earnings are greater than or equal to the investment, and a false otherwise Bought lottery ticket Winning lottery ticket Maximum prize amount 13-45-33-19-29-8" 29-10-6-13-41-8' 400000 Notes: The first five numbers of the winning ticket can match the first five numbers of the bought ticket in any order Each ticket will contain 6 unique integers (no repeated integers within a single ticket number) . . There will be no extraneous characters in the inputs . The output needs to be a logical to receive full credit. . You can use str2num) on a space separated character vector of numbers to get a vector of doubles Hints: Adding a 1 to a logical will turn trues into 2 and falses into 1 .

Explanation / Answer

PLEASE REFER BELOW CODE

create fruitLottery.m and paste below code

function acq = fruitLottery(bought,Winning,invest)

%spliting string @ '-'

temp = strsplit(bought,'-');

%converting bought string to numeric array

b = str2double(temp);

temp = strsplit(Winning,'-');

%converting winning lottery string to numeric array

w = str2double(temp);

%copying first 5 elements of winning lottery array into another array

win_temp = w(1:5);

%initial prize money is 0

prize = 0;

%comparing first 5 elements of both winning and bought lottery

for i = 1:5

if(ismember(b(i),win_temp))

prize = prize + 100000;

end

end

%checking last element of both winning and bought lottery

if(w(6) == b(6))

prize = prize * 2;

end

%prize is more than investment required then return 1 else return 0

if(prize >= invest)

acq = 1;

else

acq = 0;

end

end

Please refer below output from command window

>> acq = fruitLottery('13-45-33-19-29-8','29-10-6-13-41-8',600000)

acq =

0

>>