Re: Challenge



Ahoyhoy wrote:
Was set a starter challenge on a course today.

----------------------------------------------------------------------------------

Rearrange these numbers so that there is one digit between the two
ones, two digits between the two twos, and three digits between the
two threes.

112233

----------------------------------------------------------------------------------

Rearrange these numbers so that there is one digit between the two
ones, two digits between the two twos, three digits between the two
threes, and four digits between the two fours.

11223344

----------------------------------------------------------------------------------

Rearrange these numbers so that there is one digit between the two
ones, two digits between the two twos, three digits between the two
threes, four digits between the two fours, and five digits between the
two fives.

1122334455

----------------------------------------------------------------------------------

I have managed the first two parts, but am struggling with the third.

And, no, they never gave us the answer at the end of the course.

Hi,

Assuming that I have understood correctly the challenge (and made no mistake in the Mathematica code), I have got two numbers for the first and second parts, and none for the last one.

Here is the Mathematica function. Note that I have used a brute force approach (proof by exhaustion) and the pattern matching capabilities of Mathematica. In the following code, three dashes stand for zero, one, or more digits, a digit must be matched exactly, and one dash stand for one and only one digit (any digit).

In[1]:=
ClearAll[f];
f[n_Integer] := Module[{digits, list},
digits = IntegerDigits[n];
list = Permutations[digits];
list = Cases[list, {___, 1, _, 1, ___}];
list = Cases[list, {___, 2, _, _, 2, ___}];
list = Cases[list, {___, 3, _, _, _, 3, ___}];
If[MemberQ[digits, 4], list = Cases[list,
{___, 4, _, _, _, _, 4, ___}]];
If[MemberQ[digits, 5], list = Cases[list,
{___, 5, _, _, _, _, _, 5, ___}]];
FromDigits /@ list]
f /@ {112233, 11223344, 1122334455}

Out[3]=
{{231213, 312132}, {23421314, 41312432}, {}}

HTH,
Jean-Marc
.