Решение на Навигация на Piet от Тихомир Божков

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

Към профила на Тихомир Божков

Резултати

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

Код

def calculate_final_vector(coordinates, hex_codes):
x, y = coordinates
for hex_iter in hex_codes:
if hex_iter == 'C0FFC0' or hex_iter == 'C00000':
x -= 1
elif hex_iter == '00C000' or hex_iter == 'FFC0C0':
x += 1
elif hex_iter == 'FFFFC0' or hex_iter == '0000C0':
y -= 1
elif hex_iter == 'C0C000' or hex_iter == 'C0C0FF':
y += 1
elif hex_iter == 'FFFFFF':
continue
elif hex_iter == '000000':
break
print((x, y))

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

FFFFFFFF
======================================================================
FAIL: test_a_metric_shit_ton_of_hexes (test.TestCalculateFinalVector)
----------------------------------------------------------------------
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: None != (-42, 42)

======================================================================
FAIL: test_black_stops (test.TestCalculateFinalVector)
----------------------------------------------------------------------
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: None != (3, 0)

======================================================================
FAIL: test_empty_list (test.TestCalculateFinalVector)
----------------------------------------------------------------------
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: None != (-69, -69)

======================================================================
FAIL: test_mixed_case (test.TestCalculateFinalVector)
----------------------------------------------------------------------
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: None != (2, 2)

======================================================================
FAIL: test_negative_step (test.TestCalculateFinalVector)
----------------------------------------------------------------------
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: None != (-1, 0)

======================================================================
FAIL: test_positive_step (test.TestCalculateFinalVector)
----------------------------------------------------------------------
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: None != (1, 0)

======================================================================
FAIL: test_starting_vector (test.TestCalculateFinalVector)
----------------------------------------------------------------------
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: None != (9001, 0)

======================================================================
FAIL: test_white_ignored (test.TestCalculateFinalVector)
----------------------------------------------------------------------
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: None != (4, 0)

----------------------------------------------------------------------
Ran 8 tests in 0.098s

FAILED (failures=8)

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

Тихомир обнови решението на 24.10.2022 23:10 (преди над 1 година)

+def calculate_final_vector(coordinates, hex_codes):
+
+ x, y = coordinates
+
+ for i in range(len(hex_codes)):
+ if hex_codes[i] == "C0FFC0" or hex_codes[i] == "C00000":
+ x -= 1
+ elif hex_codes[i] == "00C000" or hex_codes[i] == "FFC0C0":
+ x += 1
+ elif hex_codes[i] == "FFFFC0" or hex_codes[i] == "0000C0":
+ y -= 1
+ elif hex_codes[i] == "C0C000" or hex_codes[i] == "C0C0FF":
+ y += 1
+ elif hex_codes[i] == "FFFFFF":
+ continue
+ elif hex_codes[i] == "000000":
+ break
+ print("(" + str(x) + ", " + str(y) + ")")
+
+
+input_coordinates = input("Enter coordinates separated with comma and space : ")

Този инпут ще дойде от нашия тест. Не е проблем ти сам да тестваш по този начин, но останалите редове не са нещо, което ние ще използваме за да проверим решението ти.

+coordinates_tuple = tuple(int(item) for item in input_coordinates.split(', '))
+
+input_string = input("Enter hex codes separated by comma and space : ").upper()
+hex_list = input_string.split(', ')
+
+calculate_final_vector(coordinates_tuple, hex_list)

Тихомир обнови решението на 25.10.2022 15:16 (преди над 1 година)

def calculate_final_vector(coordinates, hex_codes):
-
x, y = coordinates
-
- for i in range(len(hex_codes)):
- if hex_codes[i] == "C0FFC0" or hex_codes[i] == "C00000":
+ for hex_iter in hex_codes:
+ if hex_iter == 'C0FFC0' or hex_iter == 'C00000':
x -= 1
- elif hex_codes[i] == "00C000" or hex_codes[i] == "FFC0C0":
+ elif hex_iter == '00C000' or hex_iter == 'FFC0C0':
x += 1
- elif hex_codes[i] == "FFFFC0" or hex_codes[i] == "0000C0":
+ elif hex_iter == 'FFFFC0' or hex_iter == '0000C0':
y -= 1
- elif hex_codes[i] == "C0C000" or hex_codes[i] == "C0C0FF":
+ elif hex_iter == 'C0C000' or hex_iter == 'C0C0FF':
y += 1
- elif hex_codes[i] == "FFFFFF":
+ elif hex_iter == 'FFFFFF':
continue
- elif hex_codes[i] == "000000":
+ elif hex_iter == '000000':
break
- print("(" + str(x) + ", " + str(y) + ")")
-
+ print((x, y))
-
-input_coordinates = input("Enter coordinates separated with comma and space : ")
-coordinates_tuple = tuple(int(item) for item in input_coordinates.split(', '))
-
-input_string = input("Enter hex codes separated by comma and space : ").upper()
-hex_list = input_string.split(', ')
-
-calculate_final_vector(coordinates_tuple, hex_list)

В момента функцията ти НЕ ВРЪЩА резултат. Или по-скоро връща None по подразбиране. Очакваме функцията да върне резултат, не да принтира резултат.

Пусна ли си sample_test.py?