summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimponic <loganhunt@simponic.xyz>2022-12-11 22:27:34 -0700
committerSimponic <loganhunt@simponic.xyz>2022-12-11 22:27:34 -0700
commit7db39f82bfcd196f840bf3c2a820331c6a04d570 (patch)
tree74be3f7116c194184a05a25bcb77c2ee5f0f8ff8
parent4ed1b3307dc5aaa1b3d04e452df723c272344d6c (diff)
downloadaoc-7db39f82bfcd196f840bf3c2a820331c6a04d570.tar.gz
aoc-7db39f82bfcd196f840bf3c2a820331c6a04d570.zip
Day 12
-rw-r--r--day-04/sol.cpp2
-rw-r--r--day-11/sol.py67
2 files changed, 67 insertions, 2 deletions
diff --git a/day-04/sol.cpp b/day-04/sol.cpp
index 7a6a0cb..d7847da 100644
--- a/day-04/sol.cpp
+++ b/day-04/sol.cpp
@@ -61,13 +61,11 @@ std::string solve(std::vector<stack_type> &stacks, std::vector<std::string> &lin
;
if (problem == PROBLEM_1)
- {
for (int i = 0; i < amount; ++i)
{
stacks[to - 1].push(stacks[from - 1].top());
stacks[from - 1].pop();
}
- }
else
{
for (int i = 0; i < amount; ++i)
diff --git a/day-11/sol.py b/day-11/sol.py
new file mode 100644
index 0000000..9da8cec
--- /dev/null
+++ b/day-11/sol.py
@@ -0,0 +1,67 @@
+
+def get_neighbors(grid, current):
+ neighbors = []
+ y, x = current
+ cur_height = ord(grid[y][x])
+ if (grid[y][x] == "S"):
+ cur_height = ord("a")
+ for i in range(-1, 2):
+ for j in range(-1, 2):
+ if i == 0 and j == 0 or (i != 0 and j != 0):
+ continue
+ if (y + i) < 0 or (y + i) >= len(grid):
+ continue
+ if (x + j) < 0 or (x + j) >= len(grid[y + i]):
+ continue
+ new_height = ord(grid[y + i][x + j])
+ if (grid[y + i][x + j] == "E"):
+ new_height = ord("z")
+ if abs(new_height - cur_height) <= 1 or new_height <= cur_height:
+ neighbors.append((y + i, x + j))
+ return neighbors
+
+def bfs(grid, start, end):
+ queue = []
+ queue.append(start)
+ visited = {}
+ visited[start] = 0
+ while queue:
+ current = queue.pop(0)
+ if current == end:
+ return visited[current]
+ for neighbor in get_neighbors(grid, current):
+ if neighbor not in visited:
+ queue.append(neighbor)
+ visited[neighbor] = visited[current] + 1
+ return False
+
+def main():
+ file = open("input", "r")
+ grid = file.readlines()
+ file.close()
+
+ start = (0, 0)
+ end = (0, 0)
+
+ for i in range(len(grid)):
+ for j in range(len(grid[i])):
+ if grid[i][j] == "S":
+ start = (i, j)
+ elif grid[i][j] == "E":
+ end = (i, j)
+
+ best = bfs(grid, start, end)
+ print(best)
+
+ for i in range(len(grid)):
+ for j in range(len(grid[i])):
+ if grid[i][j] == "a":
+ this_as_start = bfs(grid, (i, j), end)
+ if this_as_start and this_as_start < best:
+ best = this_as_start
+
+ print(best)
+
+
+if __name__ == "__main__":
+ main()