Last updated 1 month ago
Channel for Professor mohammed dakhil
Last updated 3 months, 3 weeks ago
Last updated 1 month, 1 week ago
🎯Wipro is hiring
Role : Data Analyst
CTC : 4-8 LPA
Apply Now:- https://careers.wipro.com/careers-home/jobs/3035123
Telegram:- @allcoding1
🎯 TCS is hiring
🎯 infosys is hiring
🎯 flipkart is hiring
🎯 ICICI is hiring
🎯 Airtel is hiring
🎯 HCL is hiring
🎯cognizant is hiring
Apply Now:- www.allcoding1.com
Telegram:- @allcoding1
🎯 global logic is hiring
🎯oracle is hiring
🎯gap Inc is hiring
🎯locus is hiring
🎯 matrimony is hiring
🎯dow Jones is hiring
Apply Now:- www.allcoding1.com
Telegram:- @allcoding1
🎯HCL is hiring
Role : Graduate Trainee
Batch : 2023, 2022 passouts
CTC : 4 LPA
Location : Lucknow, Nagpur
Telegram:- @allcoding1
🎯Amazon off Campus Drive 2024 Hiring Freshers As Associate Quality Services | 2.52-4 LPA
Job Role : Associate Quality Services
Qualification : BE/BTech/MCA/BSc/BCA/MSc
Experience : Freshers
Salary CTC : Rs 2.52-4 LPA
Apply Now:- www.allcoding1.com
Telegram:- @allcoding1
Here's a Python program to simulate the given problem:
`python
def print_terrain(terrain):
for row in terrain:
print(''.join(row))
def flow_water(terrain, n):
water_level = int(terrain[n // 2][n // 2])
terrain[n // 2][n // 2] = 'W'
def can_flow(x, y, direction):
if direction == 'N':
return x > 0 and terrain[x-1][y] != 'W' and int(terrain[x-1][y]) <= water_level
elif direction == 'S':
return x < n - 1 and terrain[x+1][y] != 'W' and int(terrain[x+1][y]) <= water_level
elif direction == 'E':
return y < n - 1 and terrain[x][y+1] != 'W' and int(terrain[x][y+1]) <= water_level
elif direction == 'W':
return y > 0 and terrain[x][y-1] != 'W' and int(terrain[x][y-1]) <= water_level
def flow(x, y):
if can_flow(x, y, 'N'):
terrain[x-1][y] = 'W'
return True
if can_flow(x, y, 'S'):
terrain[x+1][y] = 'W'
return True
if can_flow(x, y, 'E'):
terrain[x][y+1] = 'W'
return True
if can_flow(x, y, 'W'):
terrain[x][y-1] = 'W'
return True
return False
while True:
print_terrain(terrain)
has_flown = False
for i in range(n):
for j in range(n):
if terrain[i][j] == 'W':
if flow(i, j):
has_flown = True
if not has_flown:
water_level += 1
print(f"Cannot flow, increasing water level to {water_level}")
break
if any(cell == 'W' and (i == 0 or j == 0 or i == n - 1 or j == n - 1) for i, row in enumerate(terrain) for j, cell in enumerate(row)):
print("Reached edge, exiting.")
break
n = 7
terrain = [
[494, 88, 89, 778, 984, 726, 587],
[340, 959, 220, 301, 639, 280, 290],
[666, 906, 632, 824, 127, 505, 787],
[673, 499, 843, 172, 193, 613, 154],
[544, 211, 124, 60, 575, 572, 389],
[635, 170, 174, 946, 593, 314, 300],
[620, 167, 931, 780, 416, 954, 275]
]
flow_water(terrain, n)
Python
Telegram:- @allcoding1_official
Today Qualitlabs Online Test ANS
Last updated 1 month ago
Channel for Professor mohammed dakhil
Last updated 3 months, 3 weeks ago
Last updated 1 month, 1 week ago