Решение на Навигация на Piet от Димитър Аврамов

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

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

Резултати

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

Код

def calculate_final_vector(initial, directions):
colors_vectors = {
'00c000': (1, 0), 'c0c000': (0, 1), 'c00000': (-1, 0),
'0000c0': (0, -1), 'c0ffc0': (-1, 0), 'ffffc0': (0, -1),
'ffc0c0': (-1, 0), 'c0c0ff': (0, -1), 'ffffff': (0, 0)
}
result_x, result_y = initial
for direction in directions:
hex_code = direction.lower()
if hex_code == '000000':
break
result_x += colors_vectors[hex_code][0]
result_y += colors_vectors[hex_code][1]
return result_x, result_y

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

FF.FF.FF
======================================================================
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: Tuples differ: (-242, -158) != (-42, 42)

First differing element 0:
-242
-42

- (-242, -158)
+ (-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: Tuples differ: (-3, 0) != (3, 0)

First differing element 0:
-3
3

- (-3, 0)
?  -

+ (3, 0)

======================================================================
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: Tuples differ: (-2, -2) != (2, 2)

First differing element 0:
-2
2

- (-2, -2)
?  -   -

+ (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: Tuples differ: (-1, 0) != (1, 0)

First differing element 0:
-1
1

- (-1, 0)
?  -

+ (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: Tuples differ: (8995, 0) != (9001, 0)

First differing element 0:
8995
9001

- (8995, 0)
+ (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: Tuples differ: (-4, 0) != (4, 0)

First differing element 0:
-4
4

- (-4, 0)
?  -

+ (4, 0)

----------------------------------------------------------------------
Ran 8 tests in 0.115s

FAILED (failures=6)

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

Димитър обнови решението на 24.10.2022 12:13 (преди около 2 години)

+def calculate_final_vector(initial, directions):
+ colors_vectors = {
+ '00c000': (1, 0), 'c0c000': (0, 1), 'c00000': (-1, 0),
+ '0000c0': (0, -1), 'c0ffc0': (-1, 0), 'ffffc0': (0, -1),
+ 'ffc0c0': (-1, 0), 'c0c0ff': (0, -1), 'ffffff': (0, 0)
+ }
+
+ result_x = initial[0]
+ result_y = initial[1]
+
+ for direction in directions:
+ hex_code = direction.lower()
+
+ if hex_code == '000000':
+ break
+
+ x_change = colors_vectors[hex_code][0]
+ y_change = colors_vectors[hex_code][1]
+ result_x += x_change
+ result_y += y_change
+
+ result = (result_x, result_y)
+ return result

Димитър обнови решението на 25.10.2022 11:19 (преди около 2 години)

def calculate_final_vector(initial, directions):
colors_vectors = {
'00c000': (1, 0), 'c0c000': (0, 1), 'c00000': (-1, 0),
'0000c0': (0, -1), 'c0ffc0': (-1, 0), 'ffffc0': (0, -1),
'ffc0c0': (-1, 0), 'c0c0ff': (0, -1), 'ffffff': (0, 0)
}
- result_x = initial[0]
- result_y = initial[1]
+ result_x, result_y = initial
for direction in directions:
hex_code = direction.lower()
if hex_code == '000000':
break
- x_change = colors_vectors[hex_code][0]
- y_change = colors_vectors[hex_code][1]
- result_x += x_change
- result_y += y_change
+ result_x += colors_vectors[hex_code][0]
+ result_y += colors_vectors[hex_code][1]
- result = (result_x, result_y)
- return result
+ return result_x, result_y