Решение на Навигация на Piet от Харут Партамиан

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

Към профила на Харут Партамиан

Резултати

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

Код

def calculate_final_vector(start_point: tuple, tiles: list):
# validations
if not isinstance(start_point, tuple):
raise Exception(f"Give start point as tuple instead of {start_point}")
if len(start_point) != 2:
raise Exception(f"Give exactly 2 coordinates instead of {len(start_point)} for the start point")
if not isinstance(tiles, list):
raise Exception(f"Please give a list for the hex codes instead of {type(tiles).__name__}")
# unpack coordinates
x, y = start_point
# dict for readability
hex_code_dict = {
'C0FFC0': 'Light Green',
'FFFFC0': 'Light Yellow',
'FFC0C0': 'Light Red',
'C0C0FF': 'Light Blue',
'00C000': 'Dark Green',
'C0C000': 'Dark Yellow',
'C00000': 'Dark Red',
'0000C0': 'Dark Blue',
'FFFFFF': 'White',
'000000': 'Black'
}
# main loop
for tile in tiles:
if not isinstance(tile, str):
raise Exception(f"Please give hex code as string: '{tile}' instead of: {tile}")
# assure case sensitivity
tile = tile.upper()
if tile not in hex_code_dict.keys():
raise Exception("Please give valid hex code for colour")
match hex_code_dict[tile]:
case 'Light Green':
x -= 1
case 'Light Yellow':
y -= 1
case 'Light Red':
x += 1
case 'Light Blue':
x += 1
case 'Dark Green':
x += 1
case 'Dark Yellow':
y += 1
case 'Dark Red':
x -= 1
case 'Dark Blue':
x -= 1
case 'White':
continue
case 'Black':
break
return x, y

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

F..FFF..
======================================================================
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: (58, -58) != (-42, 42)

First differing element 0:
58
-42

- (58, -58)
+ (-42, 42)

======================================================================
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: (4, 0) != (2, 2)

First differing element 0:
4
2

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

First differing element 0:
1
0

- (1, 0)
+ (0, 1)

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

First differing element 0:
-1
0

- (-1, 0)
+ (0, -1)

----------------------------------------------------------------------
Ran 8 tests in 0.108s

FAILED (failures=4)

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

Харут обнови решението на 20.10.2022 19:09 (преди над 1 година)

+def calculate_final_vector(start_point: tuple, tiles: list, /):
+ # validations
+ if not isinstance(start_point, tuple):
+ raise Exception(f"Give start point as tuple instead of {start_point}")
+ if len(start_point) != 2:
+ raise Exception(f"Give exactly 2 coordinates instead of {len(start_point)} for the start point")
+ if not isinstance(tiles, list):
+ raise Exception(f"Please give a list for the hex codes instead of {type(tiles).__name__}")
+
+ # unpack coordinates
+ x, y = start_point
+
+ # dict for readability
+ hex_code_dict = {
+ 'C0FFC0': 'Light Green',
+ 'FFFFC0': 'Light Yellow',
+ 'FFC0C0': 'Light Red',
+ 'C0C0FF': 'Light Blue',
+ '00C000': 'Dark Green',
+ 'C0C000': 'Dark Yellow',
+ 'C00000': 'Dark Red',
+ '0000C0': 'Dark Blue',
+ 'FFFFFF': 'White',
+ '000000': 'Black'
+ }
+
+ # main loop
+ for tile in tiles:
+ if not isinstance(tile, str):
+ raise Exception(f"Please give hex_code as string: '{tile}' instead of: {tile}")
+
+ # asure case sensitivity
+ tile = tile.upper()
+
+ if tile not in hex_code_dict.keys():
+ raise Exception(f"Please give valid hex code for colour")
+ match hex_code_dict[tile]:
+ case 'Light Green':
+ x -= 1
+ case 'Light Yellow':
+ y -= 1
+ case 'Light Red':
+ x += 1
+ case 'Light Blue':
+ x += 1
+ case 'Dark Green':
+ x += 1
+ case 'Dark Yellow':
+ y += 1
+ case 'Dark Red':
+ x -= 1
+ case 'Dark Blue':
+ x -= 1
+ case 'White':
+ continue
+ case 'Black':
+ break
+
+ return x, y

Харут обнови решението на 20.10.2022 20:29 (преди над 1 година)

def calculate_final_vector(start_point: tuple, tiles: list, /):
# validations
if not isinstance(start_point, tuple):
raise Exception(f"Give start point as tuple instead of {start_point}")
if len(start_point) != 2:
raise Exception(f"Give exactly 2 coordinates instead of {len(start_point)} for the start point")
if not isinstance(tiles, list):
raise Exception(f"Please give a list for the hex codes instead of {type(tiles).__name__}")
# unpack coordinates
x, y = start_point
# dict for readability
hex_code_dict = {
'C0FFC0': 'Light Green',
'FFFFC0': 'Light Yellow',
'FFC0C0': 'Light Red',
'C0C0FF': 'Light Blue',
'00C000': 'Dark Green',
'C0C000': 'Dark Yellow',
'C00000': 'Dark Red',
'0000C0': 'Dark Blue',
'FFFFFF': 'White',
'000000': 'Black'
}
# main loop
for tile in tiles:
if not isinstance(tile, str):
raise Exception(f"Please give hex_code as string: '{tile}' instead of: {tile}")
# asure case sensitivity
tile = tile.upper()
if tile not in hex_code_dict.keys():
- raise Exception(f"Please give valid hex code for colour")
+ raise Exception("Please give valid hex code for colour")
match hex_code_dict[tile]:
case 'Light Green':
x -= 1
case 'Light Yellow':
y -= 1
case 'Light Red':
x += 1
case 'Light Blue':
x += 1
case 'Dark Green':
x += 1
case 'Dark Yellow':
y += 1
case 'Dark Red':
x -= 1
case 'Dark Blue':
x -= 1
case 'White':
continue
case 'Black':
break
return x, y

Харут обнови решението на 22.10.2022 12:24 (преди над 1 година)

-def calculate_final_vector(start_point: tuple, tiles: list, /):
+def calculate_final_vector(start_point: tuple, tiles: list):
# validations
if not isinstance(start_point, tuple):
raise Exception(f"Give start point as tuple instead of {start_point}")
if len(start_point) != 2:
raise Exception(f"Give exactly 2 coordinates instead of {len(start_point)} for the start point")
if not isinstance(tiles, list):
raise Exception(f"Please give a list for the hex codes instead of {type(tiles).__name__}")
# unpack coordinates
x, y = start_point
# dict for readability
hex_code_dict = {
'C0FFC0': 'Light Green',
'FFFFC0': 'Light Yellow',
'FFC0C0': 'Light Red',
'C0C0FF': 'Light Blue',
'00C000': 'Dark Green',
'C0C000': 'Dark Yellow',
'C00000': 'Dark Red',
'0000C0': 'Dark Blue',
'FFFFFF': 'White',
'000000': 'Black'
}
# main loop
for tile in tiles:
if not isinstance(tile, str):
- raise Exception(f"Please give hex_code as string: '{tile}' instead of: {tile}")
+ raise Exception(f"Please give hex code as string: '{tile}' instead of: {tile}")
- # asure case sensitivity
+ # assure case sensitivity
tile = tile.upper()
if tile not in hex_code_dict.keys():
raise Exception("Please give valid hex code for colour")
match hex_code_dict[tile]:
case 'Light Green':
x -= 1
case 'Light Yellow':
y -= 1
case 'Light Red':
x += 1
case 'Light Blue':
x += 1
case 'Dark Green':
x += 1
case 'Dark Yellow':
y += 1
case 'Dark Red':
x -= 1
case 'Dark Blue':
x -= 1
case 'White':
continue
case 'Black':
break
return x, y