开发者

Algorithm for star sign compatibility lookup

开发者 https://www.devze.com 2023-01-09 10:11 出处:网络
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 a

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 compat开发者_开发知识库ibility 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"
...


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


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.


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)
}
0

精彩评论

暂无评论...
验证码 换一张
取 消