Skip to content

Commit

Permalink
Create snake.py
Browse files Browse the repository at this point in the history
  • Loading branch information
MohanaSrinivas authored Oct 15, 2023
1 parent b3f6e00 commit 32e519d
Showing 1 changed file with 34 additions and 0 deletions.
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)

0 comments on commit 32e519d

Please sign in to comment.