Re: combinatoric card game

• To: mathgroup at smc.vnet.net
• Subject: [mg25852] Re: [mg25835]combinatoric card game
• From: Roberto Brambilla <rlbrambilla at cesi.it>
• Date: Wed, 1 Nov 2000 01:25:38 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Hello Peter, you asked :

In China they often play this card game:
put four card on a table and try, as fast as possible, to arrive to the
result 24 using only addtion subtraction multiplication and division.
ex. the cards: { hearts_6 ,hearts_7 ,clove_8 ,spades_king } gives the
numbers:{6,7,8,12} and 12*(6+8)/7=24.
Is there some way to do this with Mathematica?

I suggest you this simple and 'natural' (try all) method
(written in a old style)

(*1 - a random card delivery *)

c1=ToString[Random[Integer,{1,13}]];
c2=ToString[Random[Integer,{1,13}]];
c3=ToString[Random[Integer,{1,13}]];
c4=ToString[Random[Integer,{1,13}]];
cards={c1,c2,c3,c4}
q=Permutations[cards];

(*2 -  operation combinations and seven groupings:
e1=abcd, e2=(ab)cd, e3=a(bc)d, e4=ab(cd),
e5=(ab)(cd); e6=(abc)d, e7=a(bcd)         *)

op={"+","-","*","/"};
For[r=1,r<=Length[q],r++,
p=q[[r]];
For[i=1,i<=4,i++,
For[j=1,j<=4,j++,
For[k=1,k<=4,k++,
e1=p[[1]]<>op[[i]]<>p[[2]]<>op[[j]]<>p[[3]]<>op[[k]]<>p[[4]];
If[ToExpression[e1]==24,Print[e1]];
e2="("<>p[[1]]<>op[[i]]<>p[[2]]<>")"<>op[[j]]<>p[[3]]<>op[[k]]
<>p[[4]]; If[ToExpression[e2]==24,Print[e2]];
e3=p[[1]]<>op[[i]]<>"("<>p[[2]]<>op[[j]]<>p[[3]]<>")"
<>op[[k]]<>p[[4]];If[ToExpression[e3]==24,Print[e3]];
e4=p[[1]]<>op[[i]]<>p[[2]]<>op[[j]]<>"("<>p[[3]]<>op[[k]]
<>p[[4]]<>")";If[ToExpression[e4]==24,Print[e4]];
e5="("<>p[[1]]<>op[[i]]<>p[[2]]<>")"<>op[[j]]<>"("<>p[[3]]
<>op[[k]]<>p[[4]]<>")";If[ToExpression[e5]==24,Print[e5]];
e6="("<>p[[1]]<>op[[i]]<>p[[2]]<>op[[j]]<>p[[3]]<>")"<>op[[k]]
<>p[[4]];If[ToExpression[e6]==24,Print[e6]];
e7=p[[1]]<>op[[i]]<>"("<>p[[2]]<>op[[j]]<>p[[3]]<>op[[k]]
<>p[[4]]<>")";If[ToExpression[e7]==24,Print[e7]];
]]];
]

A card delivery is evaluated 4!*4*4*4*7=10752 times!
There are, of course, a lot of redundacies but it works rather quickly.
Also you can interrupt the process at the first occurrence
of the result.
Bye, Rob
Roberto Brambilla
CESI
Via Rubattino 54
20134 Milano
tel +39.2.2125.5875
fax +39.2.2125.610
rlbrambilla at cesi.it

```

• Prev by Date: Re: combinatoric card problem
• Next by Date: Re: NIntegrate v.s. NonlinerFit
• Previous by thread: Re: Is it possible to plot a point a time on the same graph in Mathematica?
• Next by thread: Re: NIntegrate v.s. NonlinerFit