Re: combinatoric card problem

• To: mathgroup at smc.vnet.net
• Subject: [mg25891] Re: combinatoric card problem
• From: Will Self <wself at msubillings.edu>
• Date: Tue, 7 Nov 2000 02:56:01 -0500 (EST)
• References: <8tdrsn\$61d@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```In article <8tdrsn\$61d at smc.vnet.net>,
"pw" <pewei at nospam.algonet.se> wrote:
> 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 determine how to do this with mathematica, or
maybe
> there is some way to determine if a certain quadruple can make the
required
> result?
>
> Peter W

You can do it by brute force.  Paste the following into Mathematica.

---------------------------------------------------------
(* Trying to use four numbers and the four arithmetic operations to get
24.  For example, (6 + 8)/7*12 = 24.  *)

(*Define a reverse division and subtraction :*)
divR[x_, y_] := Divide [y, x]
subR[x_, y_] := Subtract[y, x]

(*There are now six operations but we only use three in any particular
try.*)

(*Define the function f to show how to apply the operations to
numbers :*)
f[operations[h1_, h2_, h3_], numbers[n1_, n2_, n3_, n4_]] :=
h1[n1, h2[n2, h3[n3, n4]]]

(*Just try every possible combination.  Don't use a slow computer.*)
cardSolution[{a_, b_, c_, d_}] :=
Select[Flatten[
Outer[use,
Flatten[Outer[operations,
Sequence @@
Table[{Plus, Subtract, subR, Times, Divide, divR}, {3}]]],
numbers @@ # & /@
Permutations[{a, b, c, d}]]], (# /. use -> f) == 24 &]

(*Try it :*)
cardSolution[{6, 7, 8, 12}] // ColumnForm

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

Sent via Deja.com http://www.deja.com/