Statement of Completion#f3102be3
Fun and Puzzles
easy
Simple Nonograms in Python
Resolution
Activities
Complete the empty function below and check your activity:
In [1]:
def nonogram_sequence(binary_array):
pass
In [3]:
def nonogram_sequence(binary_array):
sequence = []
counter = 0
for num in binary_array:
if num == 1:
counter += 1
elif counter != 0:
sequence.append(counter)
counter = 0
if counter:
sequence.append(counter)
return sequence
When you're ready, use the Check Activity button to check your function.
Test the function by yourself..
In [6]:
example_1 = [1, 1, 1, 0, 1, 1]
example_2 = [1, 0, 1, 1, 1, 1]
example_3 = [1, 1, 1, 1, 1, 1]
example_4 = [1, 0, 1, 0, 1, 1]
example_5 = [0, 0, 0, 0, 0, 0]
In [7]:
nonogram_sequence(example_1)
Out[7]:
[3, 2]
In [ ]:
In [ ]:
nonogram_sequence(example_2)
In [ ]:
In [ ]:
nonogram_sequence(example_3)
In [ ]:
In [ ]:
nonogram_sequence(example_4)
In [ ]:
In [ ]:
nonogram_sequence(example_5)
In [ ]: