Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 18th, 2002, 12:57 AM
hebbs01 hebbs01 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Location: Perth Western Australia
Posts: 3 hebbs01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Algorithm required

I am in the process of developing a website where users can roster their associations sporting schedules or fixtures.

I have been trying to develop a simple algorithm that assists with this process and not being strongly math orientated, I can tell you my head hurts!

My problem is best simplified as follows:

Given say, 4 entities, I need to be able to calculate each entity playing the remaining three others once without any duplications. This needs to repeat until all possible pairings have been exhausted.

E.g. Entities A, B, C, D

First run - AB, CD
Second run - AC, BD
Third run - AD, BC

Of course the amount of entities needs to be variable.

Any help with this would be greatly appreciated.

Regards

Hebbs

Reply With Quote
  #2  
Old February 18th, 2002, 11:19 AM
Jonathon's Avatar
Jonathon Jonathon is offline
T-Shirt Tragic
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2001
Location: Melbourne, Australia
Posts: 874 Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level)Jonathon User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 2 h 13 m 29 sec
Reputation Power: 255
Send a message via Skype to Jonathon
not sure if this what you're after but ...
this is an example in javascript that will take an array of elements (such as the alphabet) and sort it into an array of pairs without any duplicates...
Code:
<html>
<head>
<title>pairs</title>
</head>
<body>

<script language="javascript" type="text/javascript">

// give an array of elems [a...z] sort into pairs without any duplicates. [[a,b],[a,c]...[y,z]]

function pairs(elements) {
    
    pairs = new Array();
    var pointer = 1;
    
    for (k=0;k<elements.length;k++) {
	for (j=pointer;j<elements.length;j++) pairs[pairs.length] = [elements[k],elements[j]];
	pointer++;
    }
    
    for (x=0;x<pairs.length;x++) document.writeln(pairs[x][0]+"-"+pairs[x][1]+"<br>");
}

testArray = ['a','b','c','d','e','f','g','h','i','j','k','l','m',
             'n','o','p','q','r','s','t','u','v','w','x','y','z'];
pairs(testArray);

</script>
</body>
</html>

The trick is to maintain a "pointer" variable and increment it after each pass through the nested loop.

Hope I got it right for you.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Algorithm required


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT