Given 2 red beads, 2 blue beads, 1 yellow bead, and 1 green bead, how many different necklaces can be made?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
This is the code I have written, it is giving me an answer of 180, but the answer is supposed to be 16, what needs to be fixed?
% This script will calculate the number of possible arrangements for a
% necklace given a certain number of beads assuming circular shifts and
% flips are the same
%Create a vector with the beads where a number is assigned to each color
v=[1 1 2 2 3 4];
% 1=red
% 2=blue
% 3=yellow
% 4=green
% Determine total number of beads and all possible permutations
n=numel(v);
p=perms(v);
% Take into account colors with >1 beads
p2=unique(perms(v),'rows');
% Generate flips of all permutations
f=fliplr(p2);
% Generate circular shifts for all permutations
for i=0:n
c=circshift(p2,i);
end
% Combine the three matrices into one and remove duplicate rows
combined=[p2;f;c];
final=unique(combined,'rows');
configurations=size(final,1);
fprintf('The number of possible configurations is %d\n',configurations)
3 commentaires
Walter Roberson
le 18 Oct 2019
It would make more sense to put the updated code and discussion in that other question.
Réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!