permutations of 4 numbers in 7 positions IF the sum of the numbers is 600

3 vues (au cours des 30 derniers jours)
jaber Pour
jaber Pour le 11 Mai 2022
Commenté : the cyclist le 12 Mai 2022
I want to generate all permutations of 4 numbers in 7 places, but we have a condition that the sum of the 7 places should be 600.
my nambers are 100,125,75,50
It is clear that repetition is allowed.
How can i do that?
  1 commentaire
Matt J
Matt J le 11 Mai 2022
Modifié(e) : Matt J le 11 Mai 2022
It is clear that repetition is allowed.
If so, it is not a "permutation".

Connectez-vous pour commenter.

Réponses (2)

the cyclist
the cyclist le 11 Mai 2022
This is a "making change" problem, where the smaller numbers can represent coins, and the large number is the total of the change. You can use the makeChange function from the File Exchange to do this.
Below, I've generate all possible combinations. It wasn't clear to me if you need up to 7 numbers, or exactly 7 numbers, but you should be able to trim the list accordingly.
[count, combos] = makeChange(600,[125,100,75,50])
count = 41
combos = 41×4
4 1 0 0 4 0 0 2 3 1 1 1 3 0 3 0 3 0 1 3 2 2 2 0 2 2 0 3 2 1 2 2 2 1 0 5 2 0 4 1

Matt J
Matt J le 11 Mai 2022
Modifié(e) : Matt J le 11 Mai 2022
See the attached file.
combos = diophantine(ones(1,7),600,[0,100,125,75,50])
combos = 4585×7
125 125 125 125 100 0 0 125 125 125 100 125 0 0 125 125 100 125 125 0 0 125 100 125 125 125 0 0 100 125 125 125 125 0 0 125 125 125 125 0 100 0 100 100 100 100 100 100 0 75 125 100 100 100 100 0 125 75 100 100 100 100 0 75 100 125 100 100 100 0
all(sum(combos,2)==600)
ans = logical
1
  2 commentaires
Matt J
Matt J le 11 Mai 2022
Don't they?
combos = diophantine(ones(1,7),600,[0,100,125,75,50]);
all(sum(combos,2)==600)
ans = logical
1
the cyclist
the cyclist le 12 Mai 2022
(I realized my mistake and deleted my comment before I saw you replied!)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by