How to solve following task?

3 views (last 30 days)
Vejas
Vejas on 9 May 2023
Commented: Vejas on 9 May 2023
Hello,
I have a problem and can't think of the solution.
Lets say:
I have an paper roll with the width of 60cm. I need to cut the rool in to 3 parts of: 28, 20 and 15cm + left over (if any)
I need to find all the variations of the cuts and the left overs. (from the image (x1,x2,x3,x4,xn..))
I think that I would need to make an equation 28A+20B+15C+D=60 , while D<15 . D=[0:1:14]
But only integers should be used.
Any help would be appreciated.
Thank you.
  2 Comments
Vejas
Vejas on 9 May 2023
Sorry for that, it was a typo. Will fix it right now

Sign in to comment.

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 9 May 2023
Edited: Dyuman Joshi on 9 May 2023
The values you have add up to 60 and not 65.
Total=60;
a=28;
b=20;
c=15;
[A,B,C]=meshgrid(0:floor(Total/a), 0:floor(Total/b), 0:floor(Total/c));
arr = Total-(a*A+b*B+c*C);
%Indices of values which satisfy the condition on D
k = arr>=0 & arr<15;
%Obtain the final output using the indices
out = [A(k) B(k) C(k) abs(arr(k))]'
out = 4×7
0 1 2 0 0 1 0 3 1 0 2 1 0 0 0 0 0 1 2 2 4 0 12 4 5 10 2 0
  1 Comment
Vejas
Vejas on 9 May 2023
Thank you so much, works perfectly

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!