Clockwork Guardian | Coding
-
2 mins read

๐ฐ๏ธ Clockwork Guardian โ Write-Up | Cyber Apocalypse 2025
| Details | |
|---|---|
| URL | [Hack The Box :: Clockwork Guardian |
| Difficulty | Easy |
| Team Rank | 541 / 8129 |
| CTF Date | 26 Mar, 13:00 |
๐ Challenge Summary
The Clockwork Sentinels defending Eldoria’s Skywatch Spire have gone rogue! You must navigate through the spire, avoiding hostile sentinels (
1) and finding the safest path to the exit ('E'), starting from(0, 0).
๐ง Problem Rules
You are given a 2D grid where:
0= safe cell1= hostile sentinel (blocked)'E'= exit- Start point is always
(0, 0)
You can move:
- Up
- Down
- Left
- Right (no diagonals)
The goal is to find the shortest path from the start to the exit.
๐งญ Strategy
This appears to be a shortest path problem on a grid โ ideal for Breadth-First Search (BFS):
- BFS guarantees the shortest path in unweighted graphs (like grids).
- We enqueue each step with the running distance.
- If we find
'E', we immediately return the current distance.
Edge cases handled:
- Start cell is a
1โ no valid path. 'E'must be treated as walkable.- Output must be only the path length or
"Code is incorrect!"if unreachable.
๐ฎ Final Challenge Input
from collections import deque
# Read grid input (e.g., via copy-paste or platform input box)
grid = eval(input())
def bfs(grid):
rows, cols = len(grid), len(grid[0])
visited = [[False]*cols for _ in range(rows)]
directions = [(-1,0), (1,0), (0,-1), (0,1)]
if grid[0][0] == 1:
print("Code is incorrect!")
return
queue = deque()
queue.append((0, 0, 0)) # (row, col, distance)
visited[0][0] = True
while queue:
r, c, dist = queue.popleft()
if grid[r][c] == 'E':
print(dist)
return
for dr, dc in directions:
nr, nc = r + dr, c + dc
if 0 <= nr < rows and 0 <= nc < cols:
cell = grid[nr][nc]
if not visited[nr][nc] and (cell == 0 or cell == 'E'):
visited[nr][nc] = True
queue.append((nr, nc, dist + 1))
print("Code is incorrect!")
bfs(grid)
๐งช Example
Input:
[
[0, 0, 1, 0, 0, 1],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 'E']
]
Output:
8
๐ Flag
