Skip to content

Instantly share code, notes, and snippets.

@timrprobocom
Created December 18, 2022 06:38
Show Gist options
  • Save timrprobocom/d329829456b1476c1b1f16a0321c792c to your computer and use it in GitHub Desktop.
Save timrprobocom/d329829456b1476c1b1f16a0321c792c to your computer and use it in GitHub Desktop.
Checking for water flow through a block
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