3

enter image description here

The question is shown below. The handwritten answer is one of the methods of the mark scheme. This method "seemed" ok, but we are not so convinced about the Total of 140 ways.

Also, there is a second method enter image description here

What I want to do is to list all the possible outcomes and verify them.

word2 = {c, r, o, c, o, d, i, l, e}
sub2 = Subsets[word2, {3}] // Sort

** just realized that this IS WRONG ** and should use something like Groupings but still not sure about the answer...

How can I check this using Mathematica efficiently?

codebpr
  • 2,233
  • 1
  • 7
  • 26
CasperYC
  • 1,550
  • 5
  • 13

4 Answers4

6
ch = Characters["CROCODILE"];
alist = Map[Partition[#, 3] &, Permutations[ch, {9}]]

Delete any sublist of three characters with two "C"s. Select each entry that still has three sublists.

blist = Select[(DeleteCases[#
       , {OrderlessPatternSequence["C", "C", _]}
       ] & /@ alist), Length[#] == 3 &];

Delete duplicates after sorting:

clist = DeleteDuplicates@Map[Sort, blist, 2];
Length /@ {alist, blist, clist}

{90720, 68040, 65}

Syed
  • 52,495
  • 4
  • 30
  • 85
5

Too long for a comment, but not a complete answer ...

I think the counting might indeed be incorrect. Let's first convince ourselves that the formula is not working on a smaller example. Let's partition letters "ABBC" into two groups. There are obviosuly only two options:

1 – {A, B}, {B, C}

2 – {A, C}, {B, B}

What should be the result from the formula given in the solutions?

$$\mathrm{\frac{{}^4C_2 \times {}^2C_2}{\underset{BB}{2}\times \underset{order}{2}} = 3/2} \quad (?!)$$

The formula gives an obviously wrong (non-integer) solution, and it is also smaller than the real solution. Where is the problem? When we were dividing by 2 due to BB, we were also removing solutions where BB appears in the second group! But those solutions do not come in pairs, because using combinations for the second group, $\mathrm{{}^2C_2}$, already took care of the repetition!

Right now I don't have time to derive the proper formula, but here is a not very efficient Mathematica code:

word = {c, r, o, c, o, d, i, l, e};

(* All 3-groupings with order ) ( See https://mathematica.stackexchange.com/a/124286/75628 ) p1 = FoldPairList[TakeDrop, #, {3, 3, 3}] & /@ (Ordering /@ Permutations[word]); Length[p1] ( 90720 *)

(* Map indices back to letters, and sort each group ) p2 = Sort /@ Map[Sort /@ Extract[word, Transpose[{#}]] &, p1, 1]; ( Remove duplicated solutions ) p3 = Sort@DeleteDuplicates[p2]; p // Length ( 110 *)

MapThread[{#1, #2} &, {Range[Length@p], p3}] // Grid (* ... list of all possible groupings ... *)

(* Select only those with Cs in separate groups ) p4 = Select[p3, And @@ Thread[Map[Count[c], #] <= 1] &]; Length[p4] ( 65 *)

Domen
  • 23,608
  • 1
  • 27
  • 45
5
word = {c, r, o, c, o, d, i, l, e}; (**)
t = Permutations[word]; (*take all permutations*)
t = Partition[#, {3}] & /@ t;(*partition permutations in 3 sub-lists of 3 characters*)
t = Map[Sort, t, 2]; (*sort partitions and sub-lists of 3 partitions*)
t = Select[t, ! MemberQ[#, {c, c, _}] &];(*delete sub-lists with partitions containing 2 "c"*)
(t = DeleteDuplicates[t]) // Length (*delete duplicate sub-list and count remaining*)

(65)

Daniel Huber
  • 51,463
  • 1
  • 23
  • 57
3

The question arises from a discussion in class. We think we know the "correct" method to work it out as follows:

Consider the four cases:

CO-     CO-     ---
CO-     C--     O--
COO     C--     ---
C--     C--     OO-

each with number of ways

$$ \frac{^5C_1 \times ^4C_1}{2} = 10 $$

and

$$^5C_1 \times ^4C_2 = 30 $$

and

$$^5C_2 = 10 $$

and

$$\frac{^5C_2 \times ^3C_2}{2} = 15 $$

which adds up to

$$ 10 + 30 + 10 + 15 = 65 $$

It was confusing to see the markscheme and hence I was looking for an efficient code to demontrate and verify the problem.

Many Thanks for the codes.

CasperYC
  • 1,550
  • 5
  • 13