Skip to content

Instantly share code, notes, and snippets.

@Tadaboody
Created December 16, 2019 20:32
Show Gist options
  • Select an option

  • Save Tadaboody/5ecec17144508616df94f0aebffd2787 to your computer and use it in GitHub Desktop.

Select an option

Save Tadaboody/5ecec17144508616df94f0aebffd2787 to your computer and use it in GitHub Desktop.
Calculate the hint for a line from a griddler image
import typing
def griddler_line_hint(line: typing.Sequence[int]) -> typing.Iterator[int]:
"""
Creates the hint for griddlers for the given line
>>> list(griddler_line_hint([1, 1, 1]))
[3]
>>> list(griddler_line_hint([1, 1, 0, 1, 1]))
[2, 2]
>>> list(griddler_line_hint([1, 1, 0, 0]))
[2]
>>> list(griddler_line_hint([]))
[]
"""
if not line:
return
try:
next_blank = line.index(0)
yield next_blank
try:
line_starting_from_blank = line[next_blank + 1 :]
next_filled_in_square = line_starting_from_blank.index(1)
yield from griddler_line_hint(
line_starting_from_blank[next_filled_in_square:]
)
except ValueError:
return
except ValueError:
yield len(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment