Answer to Question #291751 in MatLAB for Shanu

Question #291751

On the first day of the month, 4 customers come to a restaurant. Afterwards, those 4 customers come to the same restaurant once in 2,4,6 and 8 days respectively.

a). On which day of the month, will all the four customers come back to the restaurant together?


1
Expert's answer
2022-01-29T13:02:29-0500
close all,
clear all,
clc,


%{
    On the first day of the month, 4 customers come to a restaurant. 
    Afterwards, those 4 customers come to the same restaurant once in 2,4,6 and 8 days respectively.
    a). On which day of the month, will all the four customers come back to the restaurant together?
%}


NO_of_Days=30;


FirstCustVisits=[];
c=1;
for r=1:2:NO_of_Days
    FirstCustVisits(c) = r;
    c=c+1;
end


SecondCustVisits=[];
c=1;
for r=1:4:NO_of_Days
    SecondCustVisits(c) = r;
    c=c+1;
end


ThirdCustVisits=[];
c=1;
for r=1:6:NO_of_Days
    ThirdCustVisits(c) = r;
    c=c+1;
end


FourthCustVisits=[];
c=1;
for r=1:8:NO_of_Days
    FourthCustVisits(c) = r;
    c=c+1;
end


fprintf('\n1st Customer Visits:\t');
for c=1:length(FirstCustVisits)
    fprintf('%d ',FirstCustVisits(c));
end


fprintf('\n2nd Customer Visits:\t');
for c=1:length(SecondCustVisits)
    fprintf('%d ',SecondCustVisits(c));
end


fprintf('\n3rd Customer Visits:\t');
for c=1:length(ThirdCustVisits)
    fprintf('%d ',ThirdCustVisits(c));
end


fprintf('\n4th Customer Visits:\t');
for c=1:length(FourthCustVisits)
    fprintf('%d ',FourthCustVisits(c));
end


b = intersect(intersect(intersect(FirstCustVisits,SecondCustVisits),ThirdCustVisits),FourthCustVisits);
fprintf('\n\tCommon Dates of Visit of all 4 customers: %d',b);
fprintf('\n\n');


Matlab output:




1st Customer Visits: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 

2nd Customer Visits: 1 5 9 13 17 21 25 29 

3rd Customer Visits: 1 7 13 19 25 

4th Customer Visits: 1 9 17 25 

Common Dates of Visit of all 4 customers: 1

Common Dates of Visit of all 4 customers: 25


>> 


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS