[thechat] Programming Problem

Paul Cowan paul at wishlist.com.au
Thu Nov 8 23:12:35 CST 2001


rudy wrote:
> if you disregard suits, there are fewer combos, but i can't 
> be bothered
> counting them -- you can't just divide 6,497,400 by 4, 
> because there's only
> one hand with all sevens, but 144 different hands with two 
> sevens and two
> eights....  urggle...

Not sure, rudy, that your calculations are spot on here... seems like a
moderately sizable but not enormous result set to me.

Given there are only 10 numbers to worry about (treat all picture cards as
the same), surely the number
becomes:
	10 x 10 x 10 x 10 = 1000
take brute forcing operands into account:
	10 x 4 x 10 x 4 x 10 x 4 x 10 = 64000

add in the number of possible bracket combos, by my count 11 (where each #
represents an operand):
	a # b # c # d
	(a # b) # c # d
	a # (b # c) # d
	a # b # (c # d)
	(a # b) # (c # d)
	(a # b # c) # d
	a # (b # c # d)
	((a # b) # c) # d
	(a # (b # c)) # d
	a # ((b # c) # d)
	a # (b # (c # d))

and you're looking at 
	10 x 4 x 10 x 4 x 10 x 4 x 10 x 11 = 704000

eminently calculatable, in my book. The parentheses are a killer, but it
would be easy enough to loop, pseudocode:
  for a in 1 to 10
    for b in 1 to 10
      for c in 1 to 10
        for d in 1 to 10
          for op1 in + to /
            for op2 in + to /
              for op3 in + to /
                work out (a op1 b op2 c op3 d)
                work out (a op1 b) op2 c op3 d
                work out a op1 (b op2 c) op3 d
                .. 8 more times ..

Rather ugly, but would work. Might try doing it over the weekend..
interesting idea.

Redundancy factor quite high, as you point out. More efficient coding could
probably eliminate the fact that many of the 1000 combos are duplicates of
each other. Not too much in the way of CPU time though, I would think...

Paul




More information about the thechat mailing list