Given 2 red beads, 2 blue beads, 1 yellow bead, and 1 green bead, how many different necklaces can be made?

5 visualizaciones (últimos 30 días)
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 comentarios
SammyJoe
SammyJoe el 18 de Oct. de 2019
I have since updated the code I had with the circular shifts, and now I cannot find where the problem is
Walter Roberson
Walter Roberson el 18 de Oct. de 2019
It would make more sense to put the updated code and discussion in that other question.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by