Created
December 18, 2022 06:38
-
-
Save timrprobocom/d329829456b1476c1b1f16a0321c792c to your computer and use it in GitHub Desktop.
Checking for water flow through a block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def physics(data): | |
block = [[int(i) for i in row.split(',')] for row in data.split(';')] | |
width = len(block[0]) | |
height = len(block) | |
water = block[0].index(1) | |
for row in range(1,height): | |
for possible in (-1,0,1): | |
if water+possible in range(width) and block[row][water+possible]: | |
water += possible | |
break | |
else: | |
print("blocked at level", row) | |
return "No" | |
return "Yes" | |
#string = input("Enter: ") | |
string = "1,0,0,0,0;0,1,0,0,0;0,1,0,0,0;0,0,1,0,0;0,0,0,1,0" | |
print(physics(string)) | |
string = "1,0,0,0,0;0,0,1,0,0;0,1,0,0,0;0,0,1,0,0;0,0,0,1,0" | |
print(physics(string)) | |
# Output: | |
# Yes | |
# blocked at level 1 | |
# No |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment