Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Snake.py #3011

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Snake.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def find_position(board, die_inputs):
current_position = 1 # Start position
snakes_encountered = 0
ladders_encountered = 0

for die_input in die_inputs:
new_position = current_position + die_input

if new_position > 100:
continue # Skip moves that go beyond the board

# Check if there's a snake or ladder at the new position
square = board[new_position // 10][new_position % 10]
if square.startswith("S("):
snakes_encountered += 1
new_position = int(square[2:-1]) # Move to the snake's tail
elif square.startswith("L("):
ladders_encountered += 1
new_position = int(square[2:-1]) # Move to the ladder's top

current_position = new_position

if current_position == 100:
return "Possible", snakes_encountered, ladders_encountered
else:
return "Not possible", snakes_encountered, ladders_encountered, current_position

# Input processing
board = [input().split() for _ in range(10)]
die_inputs = list(map(int, input().split()))

# Find and print the result
result = find_position(board, die_inputs)
print(*result)
Loading