views:

80

answers:

3

I'm using VB.NET but any other known language should be fine as long as it uses basic features.

My task is to create astrological compatibility chart, when two users have certain astrological sign as inputs and there is a text about those signs compatibility.

for those who are unaware of astrological signs but still want to help, there are 12 signs. Each sign has different compatibility with other sign or itself. So basically i get into 12^2-12 conditions. ie. Aries with Cancer "do not match at all" so I can save one record of that issue as backwards it is the same (thus -12 at the end).

Question is simple is there any other way to create this except of using 12^2-12 case issues...

ie. pseudo code

if sign1=1 and sign2=4
return "do not match at all"
...
+7  A: 

you need a two-dimensional array, which contains the sort of value you want to return, say, a string then you can say something like

compatibility = c[sign1][sign2]
print compatibility
Nicolas78
also, you don't save 12 but (12*11)/2 (all entries i,j are mirrored by j,i, if i!=j) - might want to make sure you always put the higher index in the first place and the lower one in the second to make this work properly
Nicolas78
@nicolas78, what do you mean by your comment?
eugeneK
@nicolas78, If i save that as two-dimensional array wouldn't it be a waste of space? For example Aries To Libra is c[1][6] and also it would be c[6][1]?
eugeneK
You say you're saving 12 entries. but you're not - you're saving 12*11/2 entries. If you think of a table, the whole upper right or lower left triangle (excluding the diagonal) is redundant as it's a mirror of the other triangle. So you're thinking into the right direction, but the amount of storage space saved is even higher. However, if you only want to store [Gemini][Libra] and not [Libra][Gemini], you should know which one's set and which one's not - I'd suggest going by a "first higher index, then lower index" scheme (ie always [3][1], and leave [1][3] empty)
Nicolas78
as you're planning to leave the entries empty, you don't lose so much space. reserving space in the grid isn't what really costs memory; saving the strings does. you might also choose a dictionary of dictionaries (or a map of maps or a hashtable of hashtable, I don't know the VB lingo) if you're really concerned.
Nicolas78
concerning the triangles - this sounds terribly abstract. just try it out for yourself: check a 3x3, 4x4, 5x5 grid and count the entries that occur twice (1,3) vs (3,1) etc. You should find it's (k*k-1)/2, not k*k-k
Nicolas78
@nicolas78, thanks.
eugeneK
+1  A: 

Yes. Use a lookup table, for example in the form of a text file. This way you can also modify the messages quickly without changing the code.

Text file:

Aries Gemini "Like cat and dog"
Aries Libra "Certain Love"
...

Pseudo-code:

var compatibilities = read(textFile)  // This is a 2D array

function compatibility(sign1, sign2) {
    int sign1Index = signNameToNumber(sign1)
    int sign2Index = signNameToNumber(sign2)
    return compatibilities(sign1Index, sign2Index)
}
Mau
+2  A: 

Just have half a dozen pre-written compatibility summaries, and randomly insert the star signs the user entered. Nobody will be able to tell the difference.

Nick Johnson