Skip to content

Commit

Permalink
Solve Cops and Robbers in python
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Sep 27, 2024
1 parent 5ef9549 commit 4b1f308
Show file tree
Hide file tree
Showing 7 changed files with 2,917 additions and 0 deletions.
50 changes: 50 additions & 0 deletions solutions/beecrowd/1905/1905.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
t = int(input())


def can_leave_maze(maze):
if maze[0][0] == 1:
return False

to_visit = [(0, 0)]
marked_to_visit = {(0, 0): 1}

while to_visit:
current = to_visit.pop()
to_visit_from_current = (
(current[0] - 1, current[1]),
(current[0], current[1] - 1),
(current[0] + 1, current[1]),
(current[0], current[1] + 1),
)

for x, y in to_visit_from_current:
if (
x in (-1, 5)
or y in (-1, 5)
or maze[x][y] == 1
or (x, y) in marked_to_visit
):
continue

if x == 4 and y == 4:
return True

to_visit.append((x, y))
marked_to_visit[(x, y)] = 1

return False


for _ in range(t):
# It seems the input is not regular on beecrowd.
# Sometimes it has blank lines and sometimes doesn't
maze = []
while len(maze) != 5:
line = input().strip()
if line:
maze.append(list(map(int, line.split())))

if can_leave_maze(maze):
print('COPS')
else:
print('ROBBERS')
26 changes: 26 additions & 0 deletions solutions/beecrowd/1905/generate_in.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -euo pipefail

TESTCASES=400
MATRIX_SIZE=5

echo "${TESTCASES}"

for _ in $(seq "${TESTCASES}"); do
echo
for _ in $(seq "${MATRIX_SIZE}"); do
for i in $(seq "${MATRIX_SIZE}"); do
if [[ ${i} -ne 1 ]]; then
echo -n " "
fi
if [[ $((RANDOM % 3)) -eq 0 ]]; then
echo -n "1"
else
echo -n "0"
fi
done
echo
done
done

Binary file added solutions/beecrowd/1905/imgs/policia.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4b1f308

Please sign in to comment.