Question

In: Computer Science

Chicken McNuggets come in 4, 7, and 10-piece boxes. If you want exactly N nuggets, is...

Chicken McNuggets come in 4, 7, and 10-piece boxes. If you want exactly N nuggets, is there a combination of boxes that you can order to get exactly ? What is a combination that will work?Write a MATLAB function that when you give it N it returns if N is a McNugget number and what combination (of the 4, 7 10 boxes) will give you that number.

Solutions

Expert Solution

I have added the code and comments for step by step explaination

function mcnugget (n) % this is the function, which takes N as input
nug = zeros(n,3); % n X 3 array, to store the combination, number of [10 7 4] boxes required 
mc = zeros(n); % mc(i) stores whether i is a mcnugget number or not 
comb = [10,7,4]; % the combinations
for i = 1:n 
    for j = 1:3
        if i-comb(j) == 0 % check if i is from array [10 7 4] then mark it as a mcnugget number 
            mc(i) = 1;
            nug(i,j) = 1;
        end
    end
    
    if mc(i) == 1 % if already marked then continue
        continue
    end
    
    for j = 1:3
        if i-comb(j) > 0 && mc(i-comb(j)) == 1 % check if adding any unit box to previous mcnugget number gives i
            mc(i) = 1; % if yes then mark it
            for k = 1:3
                nug(i,k) = nug(i-comb(j),k);
            end
            nug(i,j) = nug(i,j) + 1;
        end
        
        if mc(i) == 1 % if already marked then break
            break
        end
    end
end

if mc(n) == 1
    fprintf("%d is a McNugget number \n",n);
    fprintf("A combination of [ %d - 10 boxes] , [ %d - 7 boxes] and [ %d - 4 boxes] \n",nug(n,1),nug(n,2),nug(n,3));
else
    fprintf("%d is not a McNugget number \n",n);
end

end

Output:


Related Solutions

Problem 10. a. Construct of partition of N with exactly 4 elements and describe the equivalence...
Problem 10. a. Construct of partition of N with exactly 4 elements and describe the equivalence relation defined by your partition. Remember the elements of a partition are sets. b. Construct of partition of N with infinitely many elements and describe the equivalence relation defined by your partition. c. Construct a partion of the plane with exactly 4 elements and describe the equivalence relation defined by your partition. d. Construct a partion of the plane with infinitely many elements and...
They have available 10 boxes of honey, 4 boxes of el Duende, 6 boxes of bimbos,...
They have available 10 boxes of honey, 4 boxes of el Duende, 6 boxes of bimbos, 15 boxes of oreos . Each sells for 6$. a) Define your random variable. b) Determine the probability distribution and parameters for the random variable. c)Suppose that, after two hours, ten boxes of them have been purchased. Determine the cumulative distribution function for the number of honey purchased. d)Draw the probability distribution function for the number of honey purchased. Some body please hurry
Suppose that you are planning for retirement. You want to have exactly $4 million dollars when...
Suppose that you are planning for retirement. You want to have exactly $4 million dollars when you retire. You just turned 26 and plan to retire on your 65th birthday. For the next 15 years, you can save $10,000 per year (with the first deposit being made one year from now), and at the end of that time (t=15) you plan to buy a car for your child as a gift that will cost $50,000.   How much will you have...
choose exactly 7 red cards when you pick 10 cards from a deck.
choose exactly 7 red cards when you pick 10 cards from a deck.
In how many ways can we distribute 10 distinct balls into 5 distinct boxes with exactly...
In how many ways can we distribute 10 distinct balls into 5 distinct boxes with exactly 2 boxes empty?
Prove that for every n ∈ N: a) (10^n + 3 * 4^(n+2)) ≡ 4 mod...
Prove that for every n ∈ N: a) (10^n + 3 * 4^(n+2)) ≡ 4 mod 19, [note that 4^3 ≡ 1 mod 9] b) 24 | (2*7^(n) + 3*5^(n) - 5), c) 14 | (3^(4n+2) + 5^(2n+1) [Note that 3^(4n+2) + 5^(2n+1) = 9^(2n)*9 + 5^(2n)*5 ≡ (-5)^(2n) * 9 + 5^(2n) *5 ≡ 0 mod 14]
Prove that 3^n + 7^(n−1) ≡ 4 (mod 12) for all n ∈ N+.
Prove that 3^n + 7^(n−1) ≡ 4 (mod 12) for all n ∈ N+.
Suppose you want have a coin that you think might not be exactly fair, that is...
Suppose you want have a coin that you think might not be exactly fair, that is the probability of a head might be slightly different from 0.5. You would like to produce a 95% confidence interval for p, the true probability of a head. You decide that you would like the margin of error for your interval to be plus or minus 0.001 (that is plus or minus 0.1%). How many times, n, do you need to toss the coin...
You want to come up with a plan to save for retirement. You will contribute to...
You want to come up with a plan to save for retirement. You will contribute to your retirement account monthly for 40 years. One month after your last contribution you will begin monthly withdrawals of $7,500 from that retirement account. You earn 6.6% APR while you’re contributing to your retirement savings and 3.6% APR while you are withdrawing. You want to have enough money to finance 35 years in retirement. (Assume compounding frequencies match the payment frequencies.) What kind of...
In how many ways can you distribute 10 different balls into 4 different boxes, so there's...
In how many ways can you distribute 10 different balls into 4 different boxes, so there's no box with exactly 3 balls? Use inclusion-exclusion
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT