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]