Решение на Астрологични забави от Минх Нгуен

Обратно към всички решения

Към профила на Минх Нгуен

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)

Код

WESTERN_SIGN_BOUNDARY = [
21,
19,
21,
21,
21,
21,
23,
23,
23,
23,
22,
22
]
WESTERN_SIGN_MONTHS = [
'aquarius',
'pisces',
'aries',
'taurus',
'gemini',
'cancer',
'leo',
'virgo',
'libra',
'scorpio',
'sagittarius',
'capricorn'
]
CHINESE_SIGNS = [
'rat',
'ox',
'tiger',
'rabbit',
'dragon',
'snake',
'horse',
'sheep',
'monkey',
'rooster',
'dog',
'pig'
]
def interpret_western_sign(day, month):
if day < WESTERN_SIGN_BOUNDARY[month - 1]:
if month - 1 > -1:
return WESTERN_SIGN_MONTHS[month - 2]
else:
return WESTERN_SIGN_MONTHS[11]
return WESTERN_SIGN_MONTHS[month - 1]
def interpret_chinese_sign(year):
return CHINESE_SIGNS[(year - 1900) % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Лог от изпълнението

......
----------------------------------------------------------------------
Ran 6 tests in 0.006s

OK

История (4 версии и 1 коментар)

Минх обнови решението на 06.03.2015 21:34 (преди над 9 години)

+SIGN_BOUNDARY = {
+ '1': 21,
+ '2': 19,
+ '3': 21,
+ '4': 21,
+ '5': 21,
+ '6': 21,
+ '7': 23,
+ '8': 23,
+ '9': 23,
+ '10': 23,
+ '11': 22,
+ '12': 22
+}
+
+SIGN_MONTHS = {
+ '1': 'aquarius',
+ '2': 'pisces',
+ '3': 'aries',
+ '4': 'taurus',
+ '5': 'gemini',
+ '6': 'cancer',
+ '7': 'leo',
+ '8': 'virgo',
+ '9': 'libra',
+ '10': 'scorpio',
+ '11': 'sagittarius',
+ '12': 'capricorn'
+}
+
+CHINESE_SIGNS = {
+ '0': 'rat',
+ '1': 'ox',
+ '2': 'tiger',
+ '3': 'rabbit',
+ '4': 'dragon',
+ '5': 'snake',
+ '6': 'horse',
+ '7': 'sheep',
+ '8': 'monkey',
+ '9': 'rooster',
+ '10': 'dog',
+ '11': 'pig'
+}
+
+
+def interpret_western_sign(day, month):
+ if day < SIGN_BOUNDARY[str(month)]:
+ if month - 1 > 0:
+ return SIGN_MONTHS[str(month-1)]
+ else:
+ return SIGN_MONTHS[str(12)]
+ return SIGN_MONTHS[str(month)]
+
+
+def interpret_chinese_sign(year):
+ return CHINESE_SIGNS[str((year - 1900) % 12)]
+
+
+def interpret_both_signs(day, month, year):
+ return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Минх обнови решението на 06.03.2015 23:09 (преди над 9 години)

-SIGN_BOUNDARY = {
+WESTERN_SIGN_BOUNDARY = {
'1': 21,
'2': 19,
'3': 21,
'4': 21,
'5': 21,
'6': 21,
'7': 23,
'8': 23,
'9': 23,
'10': 23,
'11': 22,
'12': 22
}
-SIGN_MONTHS = {
+WESTERN_SIGN_MONTHS = {
'1': 'aquarius',
'2': 'pisces',
'3': 'aries',
'4': 'taurus',
'5': 'gemini',
'6': 'cancer',
'7': 'leo',
'8': 'virgo',
'9': 'libra',
'10': 'scorpio',
'11': 'sagittarius',
'12': 'capricorn'
}
CHINESE_SIGNS = {
'0': 'rat',
'1': 'ox',
'2': 'tiger',
'3': 'rabbit',
'4': 'dragon',
'5': 'snake',
'6': 'horse',
'7': 'sheep',
'8': 'monkey',
'9': 'rooster',
'10': 'dog',
'11': 'pig'
}
def interpret_western_sign(day, month):
- if day < SIGN_BOUNDARY[str(month)]:
+ if day < WESTERN_SIGN_BOUNDARY[str(month)]:
if month - 1 > 0:
- return SIGN_MONTHS[str(month-1)]
+ return WESTERN_SIGN_MONTHS[str(month-1)]
else:
- return SIGN_MONTHS[str(12)]
- return SIGN_MONTHS[str(month)]
+ return WESTERN_SIGN_MONTHS[str(12)]
+ return WESTERN_SIGN_MONTHS[str(month)]
def interpret_chinese_sign(year):
return CHINESE_SIGNS[str((year - 1900) % 12)]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Речниците индексирани с последователни естествени числа много приличат на един друг вграден тип в python, който може би ще е по-удачен в твоя случай, да не говорим, че ще ти спести cast-ването към str, което дори и така можеш да избегнеш.

Минх обнови решението на 07.03.2015 14:00 (преди над 9 години)

WESTERN_SIGN_BOUNDARY = {
- '1': 21,
- '2': 19,
- '3': 21,
- '4': 21,
- '5': 21,
- '6': 21,
- '7': 23,
- '8': 23,
- '9': 23,
- '10': 23,
- '11': 22,
- '12': 22
+ 1: 21,
+ 2: 19,
+ 3: 21,
+ 4: 21,
+ 5: 21,
+ 6: 21,
+ 7: 23,
+ 8: 23,
+ 9: 23,
+ 10: 23,
+ 11: 22,
+ 12: 22
}
WESTERN_SIGN_MONTHS = {
- '1': 'aquarius',
- '2': 'pisces',
- '3': 'aries',
- '4': 'taurus',
- '5': 'gemini',
- '6': 'cancer',
- '7': 'leo',
- '8': 'virgo',
- '9': 'libra',
- '10': 'scorpio',
- '11': 'sagittarius',
- '12': 'capricorn'
+ 1: 'aquarius',
+ 2: 'pisces',
+ 3: 'aries',
+ 4: 'taurus',
+ 5: 'gemini',
+ 6: 'cancer',
+ 7: 'leo',
+ 8: 'virgo',
+ 9: 'libra',
+ 10: 'scorpio',
+ 11: 'sagittarius',
+ 12: 'capricorn'
}
CHINESE_SIGNS = {
- '0': 'rat',
- '1': 'ox',
- '2': 'tiger',
- '3': 'rabbit',
- '4': 'dragon',
- '5': 'snake',
- '6': 'horse',
- '7': 'sheep',
- '8': 'monkey',
- '9': 'rooster',
- '10': 'dog',
- '11': 'pig'
+ 0: 'rat',
+ 1: 'ox',
+ 2: 'tiger',
+ 3: 'rabbit',
+ 4: 'dragon',
+ 5: 'snake',
+ 6: 'horse',
+ 7: 'sheep',
+ 8: 'monkey',
+ 9: 'rooster',
+ 10: 'dog',
+ 11: 'pig'
}
def interpret_western_sign(day, month):
- if day < WESTERN_SIGN_BOUNDARY[str(month)]:
+ if day < WESTERN_SIGN_BOUNDARY[month]:
if month - 1 > 0:
- return WESTERN_SIGN_MONTHS[str(month-1)]
+ return WESTERN_SIGN_MONTHS[month-1]
else:
- return WESTERN_SIGN_MONTHS[str(12)]
- return WESTERN_SIGN_MONTHS[str(month)]
+ return WESTERN_SIGN_MONTHS[12]
+ return WESTERN_SIGN_MONTHS[month]
def interpret_chinese_sign(year):
- return CHINESE_SIGNS[str((year - 1900) % 12)]
+ return CHINESE_SIGNS[(year - 1900) % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

Минх обнови решението на 09.03.2015 22:48 (преди над 9 години)

-WESTERN_SIGN_BOUNDARY = {
- 1: 21,
- 2: 19,
- 3: 21,
- 4: 21,
- 5: 21,
- 6: 21,
- 7: 23,
- 8: 23,
- 9: 23,
- 10: 23,
- 11: 22,
- 12: 22
-}
+WESTERN_SIGN_BOUNDARY = [
+ 21,
+ 19,
+ 21,
+ 21,
+ 21,
+ 21,
+ 23,
+ 23,
+ 23,
+ 23,
+ 22,
+ 22
+]
-WESTERN_SIGN_MONTHS = {
- 1: 'aquarius',
- 2: 'pisces',
- 3: 'aries',
- 4: 'taurus',
- 5: 'gemini',
- 6: 'cancer',
- 7: 'leo',
- 8: 'virgo',
- 9: 'libra',
- 10: 'scorpio',
- 11: 'sagittarius',
- 12: 'capricorn'
-}
+WESTERN_SIGN_MONTHS = [
+ 'aquarius',
+ 'pisces',
+ 'aries',
+ 'taurus',
+ 'gemini',
+ 'cancer',
+ 'leo',
+ 'virgo',
+ 'libra',
+ 'scorpio',
+ 'sagittarius',
+ 'capricorn'
+]
-CHINESE_SIGNS = {
- 0: 'rat',
- 1: 'ox',
- 2: 'tiger',
- 3: 'rabbit',
- 4: 'dragon',
- 5: 'snake',
- 6: 'horse',
- 7: 'sheep',
- 8: 'monkey',
- 9: 'rooster',
- 10: 'dog',
- 11: 'pig'
-}
+CHINESE_SIGNS = [
+ 'rat',
+ 'ox',
+ 'tiger',
+ 'rabbit',
+ 'dragon',
+ 'snake',
+ 'horse',
+ 'sheep',
+ 'monkey',
+ 'rooster',
+ 'dog',
+ 'pig'
+]
def interpret_western_sign(day, month):
- if day < WESTERN_SIGN_BOUNDARY[month]:
- if month - 1 > 0:
- return WESTERN_SIGN_MONTHS[month-1]
+ if day < WESTERN_SIGN_BOUNDARY[month - 1]:
+ if month - 1 > -1:
+ return WESTERN_SIGN_MONTHS[month - 2]
else:
- return WESTERN_SIGN_MONTHS[12]
- return WESTERN_SIGN_MONTHS[month]
+ return WESTERN_SIGN_MONTHS[11]
+ return WESTERN_SIGN_MONTHS[month - 1]
def interpret_chinese_sign(year):
return CHINESE_SIGNS[(year - 1900) % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))