Skip to content

Commit

Permalink
natural coords
Browse files Browse the repository at this point in the history
  • Loading branch information
Starwort committed Dec 19, 2019
1 parent abaaab3 commit 40771ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .mypy_cache/3.8/day18.meta.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id": "day18", "path": "/home/starwort/Documents/aoc/2019/day18.py", "mtime": 1576691180, "size": 8797, "hash": "c58a0bf1c1c9ad772b3f2b2aae893856", "data_mtime": 1576691146, "dependencies": ["collections", "functools", "string", "builtins", "abc", "typing"], "suppressed": [], "child_modules": [], "options": {"warn_return_any": false, "disallow_any_expr": false, "disallow_untyped_decorators": false, "show_none_errors": true, "warn_no_return": true, "disallow_untyped_defs": false, "disallow_any_decorated": false, "always_false": [], "ignore_errors": false, "bazel": false, "disallow_any_explicit": false, "follow_imports_for_stubs": false, "warn_unused_ignores": false, "disallow_any_generics": false, "implicit_reexport": true, "strict_optional": true, "disallow_subclassing_any": false, "strict_optional_whitelist": null, "platform": "linux", "disallow_untyped_calls": false, "allow_redefinition": false, "always_true": [], "no_implicit_optional": false, "follow_imports": "silent", "mypyc": false, "strict_equality": false, "plugins": [], "warn_unreachable": false, "allow_untyped_globals": false, "disallow_any_unimported": false, "disallow_incomplete_defs": false, "local_partial_types": false, "ignore_missing_imports": true, "check_untyped_defs": false}, "dep_prios": [5, 5, 10, 5, 30, 30], "dep_lines": [85, 86, 87, 1, 1, 1], "interface_hash": "f82733ddf8f04378334a4abefaf8b2ba", "version_id": "0.740", "ignore_all": false}
{"child_modules": [], "data_mtime": 1576691146, "dep_lines": [85, 86, 87, 1, 1, 1], "dep_prios": [5, 5, 10, 5, 30, 30], "dependencies": ["collections", "functools", "string", "builtins", "abc", "typing"], "hash": "efccdf6a322f06db7a52a2a575258ffa", "id": "day18", "ignore_all": false, "interface_hash": "f82733ddf8f04378334a4abefaf8b2ba", "mtime": 1576731521, "options": {"allow_redefinition": false, "allow_untyped_globals": false, "always_false": [], "always_true": [], "bazel": false, "check_untyped_defs": false, "disallow_any_decorated": false, "disallow_any_explicit": false, "disallow_any_expr": false, "disallow_any_generics": false, "disallow_any_unimported": false, "disallow_incomplete_defs": false, "disallow_subclassing_any": false, "disallow_untyped_calls": false, "disallow_untyped_decorators": false, "disallow_untyped_defs": false, "follow_imports": "silent", "follow_imports_for_stubs": false, "ignore_errors": false, "ignore_missing_imports": true, "implicit_reexport": true, "local_partial_types": false, "mypyc": false, "no_implicit_optional": false, "platform": "linux", "plugins": [], "show_none_errors": true, "strict_equality": false, "strict_optional": true, "strict_optional_whitelist": null, "warn_no_return": true, "warn_return_any": false, "warn_unreachable": false, "warn_unused_ignores": false}, "path": "/home/starwort/Documents/aoc/2019/day18.py", "size": 8799, "suppressed": [], "version_id": "0.740"}
18 changes: 9 additions & 9 deletions day18.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def reachable_keys(map, position, obtained):
dists = {position: 0}
keys = {}
while queue:
row, col = queue.popleft()
for (y, x) in [
col, row = queue.popleft()
for (x, y) in [
(row, col + 1),
(row, col - 1),
(row + 1, col),
Expand All @@ -102,15 +102,15 @@ def reachable_keys(map, position, obtained):
if not (0 <= x < len(map[0]) and 0 <= y < len(map)):
continue
tile = map[y][x]
if tile == "#" or (y, x) in dists:
if tile == "#" or (x, y) in dists:
continue
dists[y, x] = dists[row, col] + 1
dists[x, y] = dists[col, row] + 1
if tile in string.ascii_uppercase and tile.lower() not in obtained:
continue
if tile in string.ascii_lowercase and tile not in obtained:
keys[tile] = dists[y, x], (y, x)
keys[tile] = dists[x, y], (x, y)
else:
queue.append((y, x))
queue.append((x, y))
return keys


Expand All @@ -137,12 +137,12 @@ def shortest_path(positions, obtained):
for y, row in enumerate(map):
for x, tile in enumerate(row):
if tile == "@":
position = (y, x)
position = (x, y)
break
else:
continue
break
print(shortest_path(((y, x),), ""))
print(shortest_path((position,), ""))
shortest_path.cache_clear()
map[y - 1][x - 1] = "@"
map[y - 1][x] = "#"
Expand All @@ -155,5 +155,5 @@ def shortest_path(positions, obtained):
map[y + 1][x + 1] = "@"

print(
shortest_path(((y - 1, x - 1), (y - 1, x + 1), (y + 1, x - 1), (y + 1, x + 1)), "")
shortest_path(((x - 1, y - 1), (x - 1, y + 1), (x + 1, y - 1), (x + 1, y + 1)), "")
)

0 comments on commit 40771ee

Please sign in to comment.