Решение на Телефонна любов от Ирина Антонова

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

Към профила на Ирина Антонова

Резултати

  • 5 точки от тестове
  • 0 бонус точки
  • 5 точки общо
  • 19 успешни тест(а)
  • 18 неуспешни тест(а)

Код

def nums_to_text(arrayNum):
keyboard = {2: ["a", "b", "c"],
3: ["d", "e", "f"],
4: ["g", "h", "i"],
5: ["j", "k", "l"],
6: ["m", "n", "o"],
7: ["p", "q", "r", "s"],
8: ["t", "u", "v"],
9: ["w", "x", "y", "z"],
0: [" "]}
word = ""
count = 0
for num in range(len(arrayNum) - 1):
if arrayNum[num] == arrayNum[num + 1]:
count += 1
elif arrayNum[num] == -1:
count = 0
else:
arr = keyboard.get(arrayNum[num])
count %= len(keyboard.get(arrayNum[num]))
word += arr[count]
count = 0
if num == len(arrayNum) - 2:
arr = keyboard.get(arrayNum[num + 1])
word += arr[count]
word = word.upper()
return word
def text_to_nums(string):
string = string.lower()
reverse_keyboard = {"a": (2, 1), "b": (2, 2), "c": (2, 3), "d": (3, 1), "e": (3, 2), "f": (3, 3),
"g": (4, 1), "h": (4, 2), "i": (4, 3), "j": (5, 1), "k": (5, 2), "l": (5, 3),
"m": (6, 1), "n": (6, 2), "o": (6, 3), "p": (7, 1), "q": (7, 2), "r": (7, 3),
"s": (7, 4), "t": (8, 1), "u": (8, 2), "v": (8, 3), "w": (9, 1), "x": (9, 2),
"y": (9, 3), "z": (9, 4), " ": (0, 1)}
array_to_return = []
for char in string:
for br in range(reverse_keyboard.get(char)[1]):
array_to_return.append(reverse_keyboard.get(char)[0])
return array_to_return
def nums_to_angle(array):
sum = 0
for num in array:
sum += num * 30
sum = sum % 360
return sum
def round_angle(angle):
if angle % 30 >= 16:
angle = (angle // 30 + 1) * 30
else:
angle = (angle // 30) * 30
return angle
def filter_angles(array):
arr = []
for index in range(len(array)):
if not (0 <= array[index] <= 15 or 360 >= array[index] >= 316):
arr.append(array[index])
return arr
def angles_to_nums(array):
for i in range(len(array)):
array[i] = array[i] // 30
return array
def valid_angle(array):
for index in range(len(array)):
if array[index] < 0:
array[index] = 360 + array[index]
if array[index] >= 16:
array[index] = round_angle(array[index])
return filter_angles(array)
def is_phone_tastic(string):
return nums_to_angle(text_to_nums(string)) % len(string) == 0

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

..FFFFFF.FE..F....F.E..E.EE...FF.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_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
TypeError: object of type 'NoneType' has no len()

======================================================================
ERROR: test_ending_with_timeout (test.TestNumsToText)
Test with a sequence ending 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
TypeError: 'NoneType' object is not subscriptable

======================================================================
ERROR: test_overflow_input (test.TestNumsToText)
Test with oveflowing number of presses.
----------------------------------------------------------------------
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_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
TypeError: object of type 'NoneType' has no len()

======================================================================
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: [10] != []

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

- [10]
+ []

======================================================================
FAIL: test_ignoring_under_30 (test.TestAnglesToNums)
Test that angles rounded under 30 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_multiple_angles (test.TestAnglesToNums)
Test with a couple of angles as 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: [0, 6, 1, 2, 2] != [1, 6, 2, 2, 2]

First differing element 0:
0
1

- [0, 6, 1, 2, 2]
+ [1, 6, 2, 2, 2]

======================================================================
FAIL: test_negative_angles (test.TestAnglesToNums)
Test with a negative 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] != [7]

First differing element 0:
-5
7

- [-5]
+ [7]

======================================================================
FAIL: test_overflowing_angles (test.TestAnglesToNums)
Test with an overflowed 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: [98] != [2]

First differing element 0:
98
2

- [98]
+ [2]

======================================================================
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: [-7, 0, 0, 0, 1, 2, 4, 9, 11, 11, 24, 97, 367, 9993081, 12813] != [5, 1, 2, 4, 9, 1, 8, 0, 9]

First differing element 0:
-7
5

First list contains 6 additional elements.
First extra element 9:
11

- [-7, 0, 0, 0, 1, 2, 4, 9, 11, 11, 24, 97, 367, 9993081, 12813]
+ [5, 1, 2, 4, 9, 1, 8, 0, 9]

======================================================================
FAIL: test_round_angle_easy_case (test.TestAnglesToNums)
Test with an angle requiring rounding - easy 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] != [3]

First differing element 0:
2
3

- [2]
+ [3]

======================================================================
FAIL: test_correct_mapping (test.TestNumsToAngles)
Test correct mapping for all numbers.
----------------------------------------------------------------------
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: 0 != 300

======================================================================
FAIL: test_random_mixed_case (test.TestNumsToAngles)
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: 90 != 150

======================================================================
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.366s

FAILED (failures=13, errors=5)

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

Ирина обнови решението на 03.11.2022 12:59 (преди над 1 година)

+def nums_to_text(arrayNum):
+ keyboard = {2: ["a", "b", "c"],
+ 3: ["d", "e", "f"],
+ 4: ["g", "h", "i"],
+ 5: ["j", "k", "l"],
+ 6: ["m", "n", "o"],
+ 7: ["p", "q", "r", "s"],
+ 8: ["t", "u", "v"],
+ 9: ["w", "x", "y", "z"],
+ 0: [" "]}
+ word = ""
+ count = 0
+ for num in range(len(arrayNum) - 1):
+ if arrayNum[num] == arrayNum[num + 1]:
+ count += 1
+ elif arrayNum[num] == -1:
+ count = 0
+ else:
+ arr = keyboard.get(arrayNum[num])
+ count %= len(keyboard.get(arrayNum[num]))
+ word += arr[count]
+ count = 0
+ if num == len(arrayNum) - 2:
+ arr = keyboard.get(arrayNum[num + 1])
+ word += arr[count]
+ word = word.upper()
+ return word
+
+
+def text_to_nums(string):
+ string = string.lower()
+ reverse_keyboard = {"a": (2, 1), "b": (2, 2), "c": (2, 3), "d": (3, 1), "e": (3, 2), "f": (3, 3),
+ "g": (4, 1), "h": (4, 2), "i": (4, 3), "j": (5, 1), "k": (5, 2), "l": (5, 3),
+ "m": (6, 1), "n": (6, 2), "o": (6, 3), "p": (7, 1), "q": (7, 2), "r": (7, 3),
+ "s": (7, 4), "t": (8, 1), "u": (8, 2), "v": (8, 3), "w": (9, 1), "x": (9, 2),
+ "y": (9, 3), "z": (9, 4), " ": (0, 1)}
+ array_to_return = []
+ for char in string:
+ for br in range(reverse_keyboard.get(char)[1]):
+ array_to_return.append(reverse_keyboard.get(char)[0])
+ return array_to_return
+
+
+def nums_to_angle(array):
+ sum = 0
+ for num in array:
+ sum += num * 30
+ sum = sum % 360
+ return sum
+
+
+def round_angle(angle):
+ if angle % 30 >= 16:
+ angle = (angle // 30 + 1) * 30
+ else:
+ angle = (angle // 30) * 30
+ return angle
+
+
+def filter_angles(array):
+ arr = []
+ for index in range(len(array)):
+ if not (0 <= array[index] <= 15 or 360 >= array[index] >= 316):
+ arr.append(array[index])
+ return arr
+
+
+def angles_to_nums(array):
+ for i in range(len(array)):
+ array[i] = array[i] // 30
+ return array
+
+
+def valid_angle(array):
+ for index in range(len(array)):
+ if array[index] < 0:
+ array[index] = 360 + array[index]
+ if array[index] >= 16:
+ array[index] = round_angle(array[index])
+ return filter_angles(array)
+
+
+def is_phone_tastic(string):
+ return nums_to_angle(text_to_nums(string)) % len(string) == 0