From 7c7e1ff1e1f2f67541d665ae3d37f398ff83cc54 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 25 Mar 2025 21:34:29 -0700 Subject: [PATCH] Add one.py --- one.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 one.py diff --git a/one.py b/one.py new file mode 100644 index 0000000..5ea1ac5 --- /dev/null +++ b/one.py @@ -0,0 +1,49 @@ +# Function to read the grid from the file + +# This will read the website as a file as store the grid +def read_grid(): + url = "http://54.243.252.9/engr-1330-webroot/8-Labs/Lab07/treasure1.txt" + grid = [] + + with open(url, "r") as file: + for line in file: + new = line.split() + grid.append(list(new)) + print(grid) + return grid + +grid = [ + [34, 21, 32, 41, 25], + [14, 42, 43, 14, 31], + [54, 45, 52, 42, 23], + [33, 15, 51, 31, 35], + [21, 52, 33, 13, 23] +] + + +# Set intial values for tresure hunt + +row, col = 0, 0 + +while True: + # Print position of current cell + current = grid[row][col] + print("Visiting: ", row+1, col+1) + + # If value of cell equals its coorintates, we found treasure + if current == ((row + 1) * 10) + (col + 1): + print("Treasure found at cell (", row+1, ", ", col+1, ")!!!!!!!") + break # End the loop + + # Otherwise, print that we didnt find it + print("Cell does not contain the treasure.") + + # Get the next position + next_row = current // 10 - 1 # Values 10's digit + next_col = current % 10 - 1 # Values 1's digit + + # Define the next cell + row, col = next_row, next_col + +# Main function to run the treasure hunt +