MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: combinatoric card problem

  • To: mathgroup at
  • Subject: [mg25854] Re: combinatoric card problem
  • From: Will Self <wself at>
  • Date: Wed, 1 Nov 2000 01:25:39 -0500 (EST)
  • References: <8tdrsn$>
  • Sender: owner-wri-mathgroup at

In article <8tdrsn$61d at>,
  "pw" <pewei at> wrote:
> In China they often play this card game:
> put four card on a table and try, as fast as possible, to arrive to
> 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
> there is some way to determine if a certain quadruple can make the
> result?
> Peter W

Are parentheses allowed in the Chinese game?  I would think if it's a
folk game, the operations would have to be applied in order, like the
old-fashioned hand calculators.  Anyway, assuming you do allow
parentheses, you can solve this in Mathematica by just trying every
possibility.  I wouldn't know of any other way.


(*  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]]]

(* Now 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},
 numbers @@ # &  /@ Permutations[{a, b, c, d}]]], (# /. use -> f) == 24

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


Will Self

Sent via
Before you buy.

  • Prev by Date: Re: combinatoric card problem
  • Next by Date: Re: combinatoric card game
  • Previous by thread: Re: combinatoric card problem
  • Next by thread: Re: combinatoric card problem