Решение на Астрологични забави от Христо Владев

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

Към профила на Христо Владев

Резултати

  • 8 точки от тестове
  • 1 отнета точка
  • 7 точки общо
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)

Код

CHINESE_SIGNS_CYCLIC_GROUP = [
'monkey',
'rooster',
'dog',
'pig',
'rat',
'ox',
'tiger',
'rabbit',
'dragon',
'snake',
'horse',
'sheep',
]
def interpret_western_sign(day, month):
date = (month, day)
if (1, 21) <= date <= (2, 18): return 'aquarius'
elif (2, 19) <= date <= (3, 20): return 'pisces'
elif (3, 21) <= date <= (4, 20): return 'aries'
elif (4, 21) <= date <= (5, 20): return 'taurus'
elif (5, 21) <= date <= (6, 20): return 'gemini'
elif (6, 21) <= date <= (7, 22): return 'cancer'
elif (7, 23) <= date <= (8, 22): return 'leo'
elif (8, 23) <= date <= (9, 22): return 'virgo'
elif (9, 23) <= date <= (10, 22): return 'libra'
elif (10, 23) <= date <= (11, 21): return 'scorpio'
elif (11, 22) <= date <= (12, 21): return 'sagittarius'
else: return 'capricorn'
def interpret_chinese_sign(year):
return CHINESE_SIGNS_CYCLIC_GROUP[abs(year) % 12]
def interpret_both_signs(day, month, year):
return (interpret_western_sign(day, month), interpret_chinese_sign(year))

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

...F..
======================================================================
FAIL: test_negative_years (test.TestSigns)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20150312-24164-rcqqsn/test.py", line 26, in test_negative_years
    self.assertEqual(solution.interpret_chinese_sign(-23), 'rooster')
AssertionError: 'sheep' != 'rooster'
- sheep
+ rooster


----------------------------------------------------------------------
Ran 6 tests in 0.007s

FAILED (failures=1)

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

Христо обнови решението на 06.03.2015 08:49 (преди над 9 години)

+SIGNS_PERIODS = {
+ 'aries': {'from': (3, 21), 'to': (4, 20)},
+ 'taurus': {'from': (4, 21), 'to': (5, 20)},
+ 'gemini': {'from': (5, 21), 'to': (6, 20)},
+ 'cancer': {'from': (6, 21), 'to': (7, 22)},
+ 'leo': {'from': (7, 23), 'to': (8, 22)},
+ 'virgo': {'from': (8, 23), 'to': (9, 22)},
+ 'libra': {'from': (9, 23), 'to': (10, 22)},
+ 'scorpio': {'from': (10, 23), 'to': (11, 21)},
+ 'sagittarius': {'from': (11, 22), 'to': (12, 21)},
+ 'capricorn': {'from': (12, 22), 'to': (1, 20)},
+ 'aquarius': {'from': (1, 21), 'to': (2, 18)},
+ 'pisces': {'from': (2, 19), 'to': (3, 20)},
+}
+
+def interpret_western_sign(day, month):
+ for sign, period in SIGNS_PERIODS.items():
+ if period['from'] <= (month, day) <= period['to']:
+ return sign

Христо обнови решението на 06.03.2015 09:02 (преди над 9 години)

-SIGNS_PERIODS = {
+WESTERN_SIGNS = {
'aries': {'from': (3, 21), 'to': (4, 20)},
'taurus': {'from': (4, 21), 'to': (5, 20)},
'gemini': {'from': (5, 21), 'to': (6, 20)},
'cancer': {'from': (6, 21), 'to': (7, 22)},
'leo': {'from': (7, 23), 'to': (8, 22)},
'virgo': {'from': (8, 23), 'to': (9, 22)},
'libra': {'from': (9, 23), 'to': (10, 22)},
'scorpio': {'from': (10, 23), 'to': (11, 21)},
'sagittarius': {'from': (11, 22), 'to': (12, 21)},
'capricorn': {'from': (12, 22), 'to': (1, 20)},
'aquarius': {'from': (1, 21), 'to': (2, 18)},
'pisces': {'from': (2, 19), 'to': (3, 20)},
}
def interpret_western_sign(day, month):
- for sign, period in SIGNS_PERIODS.items():
+ for sign, period in WESTERN_SIGNS.items():
if period['from'] <= (month, day) <= period['to']:
return sign

Христо обнови решението на 06.03.2015 12:44 (преди над 9 години)

-WESTERN_SIGNS = {
- 'aries': {'from': (3, 21), 'to': (4, 20)},
- 'taurus': {'from': (4, 21), 'to': (5, 20)},
- 'gemini': {'from': (5, 21), 'to': (6, 20)},
- 'cancer': {'from': (6, 21), 'to': (7, 22)},
- 'leo': {'from': (7, 23), 'to': (8, 22)},
- 'virgo': {'from': (8, 23), 'to': (9, 22)},
- 'libra': {'from': (9, 23), 'to': (10, 22)},
- 'scorpio': {'from': (10, 23), 'to': (11, 21)},
- 'sagittarius': {'from': (11, 22), 'to': (12, 21)},
- 'capricorn': {'from': (12, 22), 'to': (1, 20)},
- 'aquarius': {'from': (1, 21), 'to': (2, 18)},
- 'pisces': {'from': (2, 19), 'to': (3, 20)},
-}
-
def interpret_western_sign(day, month):
- for sign, period in WESTERN_SIGNS.items():
- if period['from'] <= (month, day) <= period['to']:
+ return {
- return sign
+ 1: lambda day: 'capricorn' if day <= 20 else 'aquarius',
+ 2: lambda day: 'aquarius' if day <= 18 else 'pisces',
+ 3: lambda day: 'pisces' if day <= 20 else 'aries',
+ 4: lambda day: 'aries' if day <= 20 else 'taurus',
+ 5: lambda day: 'taurus' if day <= 20 else 'gemini',
+ 6: lambda day: 'gemini' if day <= 20 else 'cancer',
+ 7: lambda day: 'cancer' if day <= 22 else 'leo',
+ 8: lambda day: 'leo' if day <= 22 else 'virgo',
+ 9: lambda day: 'virgo' if day <= 22 else 'libra',
+ 10: lambda day: 'libra' if day <= 22 else 'scorpio',
+ 11: lambda day: 'scorpio' if day <= 21 else 'sagittarius',
+ 12: lambda day: 'sagittarius' if day <= 21 else 'capricorn',
+ }[month](day)

Христо обнови решението на 10.03.2015 03:12 (преди над 9 години)

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