Решение на Телефонна любов от Лъчезар Цветков

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

Към профила на Лъчезар Цветков

Резултати

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

Код

def nums_to_text(nums):
arr = ['a','d','g','j','m','p','t','w']
text = ""
lastNum = -2
times = 0
for number in nums:
if lastNum != number and lastNum != -2:
if lastNum == 7 or lastNum == 9:
text += chr(ord(arr[lastNum-2]) + (times-1)%4)
elif lastNum == 0:
text += ' '
elif lastNum != -1:
text += chr(ord(arr[lastNum-2]) + (times-1)%3)
times = 0
lastNum = number
times += 1
if lastNum == 7 or lastNum == 9:
text += chr(ord(arr[lastNum-2]) + (times-1)%4)
else:
text += chr(ord(arr[lastNum-2]) + (times-1)%3)
return text
print(nums_to_text([4, 4, 3, 3, 5, 5, 5, -1, 5, 5, 5, 6, 6, 6]))
def text_to_nums(strArr):
int_list = []
last_c = '`'
for c in strArr:
c = c.upper()
if last_c == c and c != ' ':
int_list.append(-1)
elif c >= 'A' and c <= 'C':
for x in range (1, 4 - (ord('C') - ord(c))):
int_list.append(2)
elif c >= 'D' and c <= 'F':
for x in range (1, 4 - (ord('F') - ord(c))):
int_list.append(3)
elif c >= 'G' and c <= 'I':
for x in range (1, 4 - (ord('I') - ord(c))):
int_list.append(4)
elif c >= 'J' and c <= 'L':
for x in range (1, 4 - (ord('L') - ord(c))):
int_list.append(5)
elif c >= 'M' and c <= 'O':
for x in range (1, 4 - (ord('O') - ord(c))):
int_list.append(6)
elif c >= 'P' and c <= 'S':
for x in range (1, 5 - (ord('S') - ord(c))):
int_list.append(7)
elif c >= 'T' and c <= 'V':
for x in range (1, 4 - (ord('V') - ord(c))):
int_list.append(8)
elif c >= 'W' and c <= 'Z':
for x in range (1, 5 - (ord('Z') - ord(c))):
int_list.append(9)
elif c == ' ':
int_list.append(0)
last_c = c
return int_list
print(text_to_nums('asl pls'))
def nums_to_angle(nums):
angle = 0
for number in nums:
if(number == 0):
angle += 300
else:
angle += number*30
while angle >=360:
angle -= 360
return angle
print (nums_to_angle([1, 5, 9]))
def angles_to_nums(angles):
num = []
for angle in angles:
angle = angle % 360
if angle >=15 and angle <= 315:
count = 1
while angle > 30:
angle -= 30
count += 1
num.append(count)
return num
print(angles_to_nums([16, 14, 90, -120]))
def is_phone_tastic(string):
numb = nums_to_angle(text_to_nums(string)) % 360
count = 1
while numb > 30:
numb -= 30
count += 1
if numb % len(string) == 0:
return "true"
return "false"
print(is_phone_tastic('GOD'))

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

hello
[2, 7, 7, 7, 7, 5, 5, 5, 0, 7, 5, 5, 5, 7, 7, 7, 7]
90
[1, 3, 8]
true
....F..FF.EF........F.FF..F.F.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

======================================================================
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: [1, 6, 2, 2, 3] != [1, 6, 2, 2, 2]

First differing element 4:
3
2

- [1, 6, 2, 2, 3]
?              ^

+ [1, 6, 2, 2, 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: [5, 1, 1, 2, 5, 9, 2, 8, 10, 10] != [5, 1, 2, 4, 9, 1, 8, 0, 9]

First differing element 2:
1
2

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

- [5, 1, 1, 2, 5, 9, 2, 8, 10, 10]
+ [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_random_falses (test.TestIsPhonetastic)
Test with a random input resulting in False.
----------------------------------------------------------------------
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: 'true' is not false

======================================================================
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: 'wabcdefghijklmnopqrstuvwxyzt' != 'abcdefghijklmnopqrstuvwxyz '
- wabcdefghijklmnopqrstuvwxyzt
? -                          ^
+ abcdefghijklmnopqrstuvwxyz 
?                           ^


======================================================================
FAIL: 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
AssertionError: 'o' != ''
- o
+ 


======================================================================
FAIL: 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
AssertionError: 'op' != 'o'
- op
?  -
+ o


======================================================================
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: 'wfmi rulzzz' != 'fmi rulzzz'
- wfmi rulzzz
? -
+ fmi rulzzz


======================================================================
FAIL: 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
AssertionError: '  t' not found in ('   ', '      ')

======================================================================
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, -1] != [4, 6, -1, 6]

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

- [4, 6, -1]
+ [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, -1] != [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, -1]
+ [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.343s

FAILED (failures=13, errors=1)

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

Лъчезар обнови решението на 03.11.2022 15:41 (преди над 1 година)

+def nums_to_text(nums):
+ arr = ['a','d','g','j','m','p','t','w']
+ text = ""
+ lastNum = -2
+ times = 0
+
+ for number in nums:
+ if lastNum != number and lastNum != -2:
+ if lastNum == 7 or lastNum == 9:
+ text += chr(ord(arr[lastNum-2]) + (times-1)%4)
+ elif lastNum == 0:
+ text += ' '
+ elif lastNum != -1:
+ text += chr(ord(arr[lastNum-2]) + (times-1)%3)
+ times = 0
+
+ lastNum = number
+ times += 1
+
+ if lastNum == 7 or lastNum == 9:
+ text += chr(ord(arr[lastNum-2]) + (times-1)%4)
+ else:
+ text += chr(ord(arr[lastNum-2]) + (times-1)%3)
+ return text
+
+print(nums_to_text([4, 4, 3, 3, 5, 5, 5, -1, 5, 5, 5, 6, 6, 6]))
+
+def text_to_nums(strArr):
+ int_list = []
+ last_c = '`'
+ for c in strArr:
+ c = c.upper()
+
+ if last_c == c and c != ' ':
+ int_list.append(-1)
+ elif c >= 'A' and c <= 'C':
+ for x in range (1, 4 - (ord('C') - ord(c))):
+ int_list.append(2)
+ elif c >= 'D' and c <= 'F':
+ for x in range (1, 4 - (ord('F') - ord(c))):
+ int_list.append(3)
+ elif c >= 'G' and c <= 'I':
+ for x in range (1, 4 - (ord('I') - ord(c))):
+ int_list.append(4)
+ elif c >= 'J' and c <= 'L':
+ for x in range (1, 4 - (ord('L') - ord(c))):
+ int_list.append(5)
+ elif c >= 'M' and c <= 'O':
+ for x in range (1, 4 - (ord('O') - ord(c))):
+ int_list.append(6)
+ elif c >= 'P' and c <= 'S':
+ for x in range (1, 5 - (ord('S') - ord(c))):
+ int_list.append(7)
+ elif c >= 'T' and c <= 'V':
+ for x in range (1, 4 - (ord('V') - ord(c))):
+ int_list.append(8)
+ elif c >= 'W' and c <= 'Z':
+ for x in range (1, 5 - (ord('Z') - ord(c))):
+ int_list.append(9)
+ elif c == ' ':
+ int_list.append(0)
+ last_c = c
+
+ return int_list
+
+print(text_to_nums('asl pls'))
+
+def nums_to_angle(nums):
+ angle = 0
+ for number in nums:
+ if(number == 0):
+ angle += 300
+ else:
+ angle += number*30
+ while angle >=360:
+ angle -= 360
+ return angle
+
+
+print (nums_to_angle([1, 5, 9]))
+
+def angles_to_nums(angles):
+ num = []
+
+ for angle in angles:
+ angle = angle % 360
+
+ if angle >=15 and angle <= 315:
+ count = 1
+ while angle > 30:
+ angle -= 30
+ count += 1
+
+ num.append(count)
+
+ return num
+
+print(angles_to_nums([16, 14, 90, -120]))
+
+
+
+
+
+def is_phone_tastic(string):
+ numb = nums_to_angle(text_to_nums(string)) % 360
+
+ count = 1
+ while numb > 30:
+ numb -= 30
+ count += 1
+
+ if numb % len(string) == 0:
+ return "true"
+ return "false"
+
+print(is_phone_tastic('GOD'))