.com.unity Forums
  The Official e-Store of Shrapnel Games

This Month's Specials

Raging Tiger- Save $9.00
winSPMBT: Main Battle Tank- Save $5.00

   







Go Back   .com.unity Forums > Shrapnel Community > Space Empires: IV & V

Reply
 
Thread Tools Display Modes
  #1  
Old August 6th, 2003, 09:55 PM
LGM's Avatar

LGM LGM is offline
Sergeant
 
Join Date: Apr 2001
Location: Minneapolis, MN, USA
Posts: 222
Thanks: 0
Thanked 0 Times in 0 Posts
LGM is on a distinguished road
Default Re: Math problem

Here is the code. Crudely done by brute force in a rather esoteric flavor of basic:

PRIMES = '2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61 ,67,71,73,79,83,89,97,101,103,109,113,127,131,137'
SWAP ',' WITH @AM IN PRIMES
ILIMIT = DCOUNT(PRIMES,@AM)
PRINT ILIMIT
FOR I = 4 TO ILIMIT
NBR = I
COMBOS = ''
COMBOX = ''
IDX = 1
FOR J = 1 TO I
FOR K = J+1 TO I
FOR L = K+1 TO I
GOSUB FIND.DUPLICATE
IF NOT(FOUND.DUPLICATE) THEN
COMBOS<-1> = PRIMES*PRIMES*PRIMES
COMBOX<-1> = J:',':K:',':L
END
NEXT L
NEXT K
NEXT J
GOSUB CHECK.SOLUTION
NEXT I
PRINT 'DONE'
STOP
*
SOLVED:*
PRINT '---------------------'
PRINT 'SOLVED'
PRINT NBR
FOR M = DCOUNT(COMBOX,@AM) TO 1 STEP -1
PRINT COMBOX
NEXT M
INPUT CH,1_
RETURN
*
CHECK.SOLUTION: *
FOR J = 1 TO I
FOR K = J + 1 TO I
NBR.MATCHES = 0
FOR M = DCOUNT(COMBOS,@AM) TO 1 STEP -1
A.COMBO = COMBOS
IF MOD(A.COMBO,PRIMES)=0 AND MOD(A.COMBO,PRIMES)=0 THEN
NBR.MATCHES = NBR.MATCHES + 1
IF NBR.MATCHES > 1 THEN RETURN
END
NEXT M
IF NBR.MATCHES = 0 THEN RETURN
NEXT K
NEXT J
GOSUB SOLVED
RETURN
*
FIND.DUPLICATE: *
FOUND.DUPLICATE = 0
FOR M = DCOUNT(COMBOS,@AM) TO 1 STEP -1
A.COMBO = COMBOS
J.MOD = MOD(A.COMBO,PRIMES)
K.MOD = MOD(A.COMBO,PRIMES)
L.MOD = MOD(A.COMBO,PRIMES)
IF J.MOD = 0 THEN
IF K.MOD=0 OR L.MOD=0 THEN
FOUND.DUPLICATE = 1
END
END ELSE IF K.MOD=0 AND L.MOD=0 THEN
FOUND.DUPLICATE = 1
END
NEXT M
RETURN
Reply With Quote
  #2  
Old August 6th, 2003, 10:01 PM
geoschmo's Avatar

geoschmo geoschmo is offline
National Security Advisor
 
Join Date: Jan 2001
Location: Ohio
Posts: 8,450
Thanks: 0
Thanked 4 Times in 1 Post
geoschmo is on a distinguished road
Default Re: Math problem

Ok, so bascially you are having the couputer run through all the possible options fast and see if a number works. Ok, that does the job but isn't really what I was looking for. Mayeb there is no simple mathematical formula for what I am looking for.

Basically I can take x players and group them into games of three players each and see fairly quickly that 7 players will work, but 5 will not. What I was hoping to find was a formula that I could plug the numbers in and be able to tell if a combination of x and y would work without having to go through all teh grouping by hand.

Geoschmo
__________________
I used to be somebody but now I am somebody else
Who I'll be tomorrow is anybody's guess
Reply With Quote
  #3  
Old August 6th, 2003, 10:06 PM
geoschmo's Avatar

geoschmo geoschmo is offline
National Security Advisor
 
Join Date: Jan 2001
Location: Ohio
Posts: 8,450
Thanks: 0
Thanked 4 Times in 1 Post
geoschmo is on a distinguished road
Default Re: Math problem

By the way LGM, what is the reason for using the prime numbers in the program? I'm not a programmer so I can't really make heads or tails of your code there, not that it wasn't apprecieated.
__________________
I used to be somebody but now I am somebody else
Who I'll be tomorrow is anybody's guess
Reply With Quote
  #4  
Old August 6th, 2003, 10:07 PM
LGM's Avatar

LGM LGM is offline
Sergeant
 
Join Date: Apr 2001
Location: Minneapolis, MN, USA
Posts: 222
Thanks: 0
Thanked 0 Times in 0 Posts
LGM is on a distinguished road
Default Re: Math problem

Try X raised to the Yth power and subtract one. Just a theory. I am not sure if that works for 4 or 5 man games yet. X is Number of players per game minus 1. Incidentally, that does not work for 2 players games as any number works for 'round robin' leagues.
Reply With Quote
  #5  
Old August 6th, 2003, 10:09 PM
LGM's Avatar

LGM LGM is offline
Sergeant
 
Join Date: Apr 2001
Location: Minneapolis, MN, USA
Posts: 222
Thanks: 0
Thanked 0 Times in 0 Posts
LGM is on a distinguished road
Default Re: Math problem

Prime numbers are a nice way to test if something is a member of a set. Products of prime numbers is a common way of encoding sets because you can divide by a given prime. If the remainder is zero, it is an element of the set.
Reply With Quote
  #6  
Old August 6th, 2003, 10:12 PM
LGM's Avatar

LGM LGM is offline
Sergeant
 
Join Date: Apr 2001
Location: Minneapolis, MN, USA
Posts: 222
Thanks: 0
Thanked 0 Times in 0 Posts
LGM is on a distinguished road
Default Re: Math problem

You could use 21 players (3 sets of 7) with a championship game from the winners of each set.

Or you could use 49 players (7 sets of 7) and have a championship round of the top 7 playing each of the top 7.

[ August 06, 2003, 21:13: Message edited by: LGM ]
Reply With Quote
  #7  
Old August 6th, 2003, 10:16 PM
Slick's Avatar

Slick Slick is offline
Brigadier General
 
Join Date: Apr 2002
Location: Kailua, Hawaii
Posts: 1,860
Thanks: 0
Thanked 1 Time in 1 Post
Slick is on a distinguished road
Default Re: Math problem

Quote:
Originally posted by geoschmo:
Sorry slick, this is way over my head.

"The general formula for C(n,r) = n!/[r!(n-r)!]"

What do n and r represent in the formula, and what are the exclamation points for?

And is C(n,r) the total numebr of players needed in the tourney, or the number of games played by each person in the tourney, or something else alltogether?
Sorry, no offense intended...

n are the total number of players in the tourney
r are the number of players in the group (i.e. 3 for your case)

x! (spoken "x factorial") is defined as x! = x(x-1)(x-2)(x-3)...(3)(2)(1)

So 10! = 10x9x8x7x6x5x4x3x2x1

C(n,r) means C is a function of the variables n & r.

Bottom line:

The number of ways to group n people in Groups of r (i.e. the total number of games required to have everyone play everyone else in one and only one game) is C(n,r) = n!/[r!(n-r)!]

I seriously recommend you think up a better tourney. For 10 people, you need 120 games.

Slick.
__________________
Slick.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 10:49 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.