Решение на Телефонна любов от Мария Марковска

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

Към профила на Мария Марковска

Резултати

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

Код

def nums_to_angle(nums):
angles_nums=[300, 30, 60, 90, 120, 150, 180, 210, 240, 270]
rez=0
for num in nums:
rez+=angles_nums[num]
return rez%360
def angles_to_nums(angles):
rez=[]
angles_nums=[300, 30, 60, 90, 120, 150, 180, 210, 240, 270]
for angle in angles:
if angle<-360:

Може да опиташ да опростиш тази логика, опирайки се на математически операции. Ако ти е интересно, можеш да видиш вече публичните решения на колеги. Има интересни идеи.

angle=abs(abs(angle)%360-360)
elif angle>360:
angle=angle%360
elif angle<0:
angle+=360
if angle>300 and angle<=360:
angle=300
elif angle<30 and angle>=15:
angle=30
elif angle<15:
continue
if angle in angles_nums:
rez.append(angles_nums.index(angle))
continue
elif angle%30<15:
angle-=angle%30
elif angle%30>=15:
angle-=angle%30
angle+=30
rez.append(angles_nums.index(angle))
return rez
def nums_to_text(nums):
a_b_c=[[' ',' ', ' '], [], ['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I'], ['J', 'K', 'L'], ['M', 'N', 'O'], ['P', 'Q', 'R', 'S'], ['T', 'U', 'V'], ['W', 'X', 'Y', 'Z']]
num1=nums[0]
counter=0
rez=""
i=0
for num in nums:
i+=1
if num1 in [1, -1]:
num1=num
continue
if num1==num and i!=len(nums):
counter+=1
continue
elif i==len(nums) and num1==nums[-1]:
counter+=1
if counter>4 and num1 in [7, 9]:
counter=counter%4
elif counter>3 and num1 in [1, 2, 3, 4, 5, 6, 8]:
counter=counter%3
rez+=a_b_c[num1][counter-1]
num1=num
counter=1
return rez
def text_to_nums(text):
a_b_c=[[' '], [], ['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I'], ['J', 'K', 'L'], ['M', 'N', 'O'], ['P', 'Q', 'R', 'S'], ['T', 'U', 'V'], ['W', 'X', 'Y', 'Z']]
rez=[]
for letter in text:
for number, row in enumerate(a_b_c):
for times, element in enumerate(row):
if element == letter.upper():
for i in range(times+1):
rez.append(number)
return rez
def is_phone_tastic(word):
if nums_to_angle(text_to_nums(word))%len(word)==0:
return True
return False

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

..F....FF.E.........FFE.F.FFEFFF.FF..
======================================================================
ERROR: test_empty_input (test.TestIsPhonetastic)
Test with empty input.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
ZeroDivisionError: integer division or modulo by zero

======================================================================
ERROR: test_empty_input (test.TestNumsToText)
Test with empty input.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
IndexError: list index out of range

======================================================================
ERROR: test_spaces_only (test.TestNumsToText)
Test for input of only whitespaces with or without -1.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
IndexError: list index out of range

======================================================================
FAIL: test_ignoring_over_330 (test.TestAnglesToNums)
Test that angles rounded over 330 are ignored.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: Lists differ: [0] != []

First list contains 1 additional elements.
First extra element 0:
0

- [0]
?  -

+ []

======================================================================
FAIL: test_random_mixed_case (test.TestAnglesToNums)
Test with a random mixed input.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: Lists differ: [5, 1, 1, 2, 5, 9, 0, 0, 2, 8, 0, 9] != [5, 1, 2, 4, 9, 1, 8, 0, 9]

First differing element 2:
1
2

First list contains 3 additional elements.
First extra element 9:
8

- [5, 1, 1, 2, 5, 9, 0, 0, 2, 8, 0, 9]
+ [5, 1, 2, 4, 9, 1, 8, 0, 9]

======================================================================
FAIL: test_round_angle_direction (test.TestAnglesToNums)
Test with an angle requiring explicit rounding to floor.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: Lists differ: [2] != [1]

First differing element 0:
2
1

- [2]
+ [1]

======================================================================
FAIL: test_all_chars (test.TestNumsToText)
Test for correct mapping of all chars.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: 'cbcdefghijklmnopqrstuvwxyz' != 'abcdefghijklmnopqrstuvwxyz '
- cbcdefghijklmnopqrstuvwxyz
? ^
+ abcdefghijklmnopqrstuvwxyz 
? ^                         +


======================================================================
FAIL: test_complex_word (test.TestNumsToText)
Test with a complex word that requires -1.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: 'b' != 'ba'
- b
+ ba
?  +


======================================================================
FAIL: test_multiple_timeouts (test.TestNumsToText)
Test with multiple '-1's next to each other.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: 'jmp' != 'jmpt'
- jmp
+ jmpt
?    +


======================================================================
FAIL: test_random_mixed_case (test.TestNumsToText)
Test for a random mixed case.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: 'emi rulzzz' != 'fmi rulzzz'
- emi rulzzz
? ^
+ fmi rulzzz
? ^


======================================================================
FAIL: test_simple_word (test.TestNumsToText)
Test with a simple word that doesn't require -1.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: 'ad' != 'adg'
- ad
+ adg
?   +


======================================================================
FAIL: test_starting_with_timeout (test.TestNumsToText)
Test with a sequence starting with a -1.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: 'n' != 'o'
- n
+ o


======================================================================
FAIL: test_all_chars (test.TestTextToNums)
Test for correct mapping of all chars.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: Lists differ: [2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4,[121 chars]9, 0] != [2, -1, 2, 2, -1, 2, 2, 2, 3, -1, 3, 3, -1, 3[193 chars]9, 0]

First differing element 1:
2
-1

Second list contains 18 additional elements.
First extra element 57:
-1

  [2,
+  -1,
   2,
   2,
+  -1,
   2,
   2,
   2,
   3,
+  -1,
   3,
   3,
+  -1,
   3,
   3,
   3,
   4,
+  -1,
   4,
   4,
+  -1,
   4,
   4,
   4,
   5,
+  -1,
   5,
   5,
+  -1,
   5,
   5,
   5,
   6,
+  -1,
   6,
   6,
+  -1,
   6,
   6,
   6,
   7,
+  -1,
+  7,
+  7,
+  -1,
   7,
   7,
   7,
+  -1,
-  7,
-  7,
   7,
   7,
   7,
   7,
   8,
+  -1,
   8,
   8,
+  -1,
   8,
   8,
   8,
   9,
+  -1,
+  9,
+  9,
+  -1,
   9,
   9,
   9,
+  -1,
-  9,
-  9,
   9,
   9,
   9,
   9,
   0]

======================================================================
FAIL: test_complex_word (test.TestTextToNums)
Test with a complex word that requires -1.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: Lists differ: [4, 6, 6] != [4, 6, -1, 6]

First differing element 2:
6
-1

Second list contains 1 additional elements.
First extra element 3:
6

- [4, 6, 6]
+ [4, 6, -1, 6]
?        ++++


======================================================================
FAIL: test_mixed_casing (test.TestTextToNums)
Test for both lower and capital case.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: Lists differ: [2, 2, 2, 3, 3] != [2, -1, 2, 2, 3, -1, 3]

First differing element 1:
2
-1

Second list contains 2 additional elements.
First extra element 5:
-1

- [2, 2, 2, 3, 3]
+ [2, -1, 2, 2, 3, -1, 3]
?     ++++         ++++


======================================================================
FAIL: test_random_mixed_case (test.TestTextToNums)
Test for a random mixed case.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221020151654/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: [8, 8, 8, 2, 7, 7, 7, 7, 5, 5, 6, 6, 6, 0, 0, 0, 5, 2, 2, 2, 2, 8, 2] not found in ([8, 8, 8, 2, 7, 7, 7, 7, 5, 5, 6, 6, 6, 0, -1, 0, -1, 0, 5, 2, -1, 2, 2, -1, 2, 8, 2], [8, 8, 8, 2, 7, 7, 7, 7, 5, 5, 6, 6, 6, 0, 0, 0, 5, 2, -1, 2, 2, -1, 2, 8, 2])

----------------------------------------------------------------------
Ran 37 tests in 0.362s

FAILED (failures=13, errors=3)

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

Мария обнови решението на 03.11.2022 12:31 (преди над 1 година)

+def nums_to_angle(nums):
+ angles_nums=[300, 30, 60, 90, 120, 150, 180, 210, 240, 270]
+ rez=0
+ for num in nums:
+ rez+=angles_nums[num]
+ return rez%360
+
+def angles_to_nums(angles):
+ rez=[]
+ angles_nums=[300, 30, 60, 90, 120, 150, 180, 210, 240, 270]
+ for angle in angles:
+ if angle<-360:

Може да опиташ да опростиш тази логика, опирайки се на математически операции. Ако ти е интересно, можеш да видиш вече публичните решения на колеги. Има интересни идеи.

+ angle=abs(abs(angle)%360-360)
+ elif angle>360:
+ angle=angle%360
+ elif angle<0:
+ angle+=360
+ if angle>300 and angle<=360:
+ angle=300
+ elif angle<30 and angle>=15:
+ angle=30
+ elif angle<15:
+ continue
+ if angle in angles_nums:
+ rez.append(angles_nums.index(angle))
+ continue
+ elif angle%30<15:
+ angle-=angle%30
+ elif angle%30>=15:
+ angle-=angle%30
+ angle+=30
+ rez.append(angles_nums.index(angle))
+ return rez
+
+def nums_to_text(nums):
+ a_b_c=[[' ',' ', ' '], [], ['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I'], ['J', 'K', 'L'], ['M', 'N', 'O'], ['P', 'Q', 'R', 'S'], ['T', 'U', 'V'], ['W', 'X', 'Y', 'Z']]
+ num1=nums[0]
+ counter=0
+ rez=""
+ i=0
+ for num in nums:
+ i+=1
+ if num1 in [1, -1]:
+ num1=num
+ continue
+ if num1==num and i!=len(nums):
+ counter+=1
+ continue
+ elif i==len(nums) and num1==nums[-1]:
+ counter+=1
+ if counter>4 and num1 in [7, 9]:
+ counter=counter%4
+ elif counter>3 and num1 in [1, 2, 3, 4, 5, 6, 8]:
+ counter=counter%3
+ rez+=a_b_c[num1][counter-1]
+ num1=num
+ counter=1
+ return rez
+
+def text_to_nums(text):
+ a_b_c=[[' '], [], ['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I'], ['J', 'K', 'L'], ['M', 'N', 'O'], ['P', 'Q', 'R', 'S'], ['T', 'U', 'V'], ['W', 'X', 'Y', 'Z']]
+ rez=[]
+ for letter in text:
+ for number, row in enumerate(a_b_c):
+ for times, element in enumerate(row):
+ if element == letter.upper():
+ for i in range(times+1):
+ rez.append(number)
+ return rez
+
+def is_phone_tastic(word):
+ if nums_to_angle(text_to_nums(word))%len(word)==0:
+ return True
+ return False