Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.7 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a1d9f98e819ed70a0e994e2 Challenge 336: Horoscope Match 29 challenge-336

--description--

Given two star sign strings, return their compatibility percentage.

The signs are arranged in a wheel of 12 positions in this order: "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces", wrapping back to "Aries" after "Pisces". Find the shortest distance between the two signs and return the compatibility:

Distance Compatibility
0 "100%"
1 "40%"
2 "80%"
3 "30%"
4 "90%"
5 "20%"
6 "50%"

--hints--

horoscope_match("Libra", "Sagittarius") should return "80%".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(horoscope_match("Libra", "Sagittarius"), "80%")`)
}})

horoscope_match("Gemini", "Scorpio") should return "20%".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(horoscope_match("Gemini", "Scorpio"), "20%")`)
}})

horoscope_match("Pisces", "Aries") should return "40%".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(horoscope_match("Pisces", "Aries"), "40%")`)
}})

horoscope_match("Capricorn", "Cancer") should return "50%".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(horoscope_match("Capricorn", "Cancer"), "50%")`)
}})

horoscope_match("Aquarius", "Aquarius") should return "100%".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(horoscope_match("Aquarius", "Aquarius"), "100%")`)
}})

horoscope_match("Virgo", "Taurus") should return "90%".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(horoscope_match("Virgo", "Taurus"), "90%")`)
}})

horoscope_match("Leo", "Scorpio") should return "30%".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(horoscope_match("Leo", "Scorpio"), "30%")`)
}})

--seed--

--seed-contents--

def horoscope_match(sign1, sign2):

    return sign1

--solutions--

def horoscope_match(sign1, sign2):
    signs = ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"]
    a = signs.index(sign1)
    b = signs.index(sign2)
    diff = abs(a - b)
    distance = min(diff, 12 - diff)
    compatibility = {0: "100%", 1: "40%", 2: "80%", 3: "30%", 4: "90%", 5: "20%", 6: "50%"}
    return compatibility[distance]