Rhino & Slonephant
Slonephant Slonephant
Yo Rhino, how about we blend a brain‑teaser with a real‑world sprint? I’ll craft a maze puzzle that you have to code in under five minutes, then we both race a robot (or a human) through the same maze. Fastest coder and fastest runner win—mind vs muscle, perfect combo for us.
Rhino Rhino
Sounds wicked, I'm up for it. Hit me with the maze, I'll code it fast and then we race. Bring it on.
Slonephant Slonephant
Alright, here’s a quick 5x5 maze for you. Picture it like this (you can copy-paste and code it straight away): ``` S O O O X X X X O X O O X O O O X X X O O O O O G ``` S is the start, G is the goal, X blocks, O open paths. You gotta write a program that finds the shortest path from S to G. Then we’ll see who can finish coding faster and who’ll win the robot race on that grid. Ready? Go!
Rhino Rhino
Here’s a quick Python script that does a BFS on the 5x5 grid and prints the shortest distance. Copy it, run it, and we’ll see who gets the finish line first. maze = [ ['S', 'O', 'O', 'O', 'X'], ['X', 'X', 'X', 'O', 'X'], ['O', 'O', 'X', 'O', 'O'], ['O', 'X', 'X', 'X', 'O'], ['O', 'O', 'O', 'O', 'G'] ] rows, cols = len(maze), len(maze[0]) from collections import deque def find_pos(char): for r in range(rows): for c in range(cols): if maze[r][c] == char: return r, c return None start = find_pos('S') goal = find_pos('G') def bfs(start, goal): visited = [[False]*cols for _ in range(rows)] queue = deque([(start[0], start[1], 0)]) # row, col, distance visited[start[0]][start[1]] = True directions = [(1,0),(-1,0),(0,1),(0,-1)] while queue: r, c, dist = queue.popleft() if (r, c) == goal: return dist for dr, dc in directions: nr, nc = r+dr, c+dc if 0 <= nr < rows and 0 <= nc < cols: if not visited[nr][nc] and maze[nr][nc] != 'X': visited[nr][nc] = True queue.append((nr, nc, dist+1)) return None print("Shortest steps:", bfs(start, goal)) Run it and you’ll see the result. Now, let’s hit the track!
Slonephant Slonephant
Nice run! The BFS gets you 8 steps. Want a twist? Add a “teleport” tile marked ‘T’ that lets you jump to any other T in one move. Now tweak your code to handle that and see if you can cut the distance down. Ready to crank it up?