From 8985f2ab39813239bad70547b89723daba6b7212 Mon Sep 17 00:00:00 2001 From: MohanaSrinivas <128175768+MohanaSrinivas@users.noreply.github.com> Date: Mon, 16 Oct 2023 01:59:19 +0530 Subject: [PATCH] Create Snake.py --- Snake.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Snake.py diff --git a/Snake.py b/Snake.py new file mode 100644 index 0000000000..9a3c4c1261 --- /dev/null +++ b/Snake.py @@ -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)