Write me a pseudocode for a maze solving algorithm. Assume the agent navigating the maze…
- User
Write me a pseudocode for a maze solving algorithm. Assume the agent navigating the maze can only tell what's directly in front of them (a wall, an exit, or nothing). You can freely assume there are no loops in the maze.
- Assistant
Sure! Here's an example pseudocode for a maze solving algorithm that uses a depth-first search approach:
codefunction mazeSolver(maze): create a stack and push the starting position create a set to store visited positions while stack is not empty: current = pop stack if current is the goal: return "path found" if current is not in visited set: add current to visited set for each adjacent cell in current's four directions: if adjacent is not a wall: push adjacent to stack with current as its parent return "no path found" - User
Write a python script of the above pseudo code
- Assistant
Sure, here you go:
codedef mazeSolver(maze): stack = [(0, 0)] # Starting position visited = set() while stack: current = stack.pop() if current == (len(maze)-1, len(maze[0])-1): # Goal position return "path found" if current not in visited: visited.add(current) row, col = current[0], current[1] directions = [(row+1, col), (row-1, col), (row, col+1), (row, col-1)] for adjacent in directions: adj_row, adj_col = adjacent[0], adjacent[1] if 0 <= adj_row < len(maze) and 0 <= adj_col < len(maze[0]) and maze[adj_row][adj_col] != "W": stack.append(adjacent + (current,)) return "no path found"
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)