Skip to content

Instantly share code, notes, and snippets.

@scdekov
Created February 1, 2017 14:52
Show Gist options
  • Save scdekov/0fb1605c6af34016647ca331f480f261 to your computer and use it in GitHub Desktop.
Save scdekov/0fb1605c6af34016647ca331f480f261 to your computer and use it in GitHub Desktop.
def validate_row(nonogram, keys):
for i, rows in enumerate(nonogram):
current_group = keys[i]
print("before", current_group)
for idx, e in enumerate(rows):
if e != 'x':
continue
if current_group:
current_group[0] -= 1
print("inside_before", current_group)
try:
if current_group[0] == 0 and rows[idx+1] == ' ':
current_group.pop(0)
elif current_group[0] == 0:
return False
except IndexError:
if current_group[0] == 0 and len(rows)-1 == idx:
current_group.pop(0)
print("inside_after", current_group)
else:
return False
print("after", current_group)
if current_group:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment