1

This Python script is supposed to make a CGoL Glider, but matrix just outputs [[1, 1, 1], [1, 1, 1], [1, 1, 1]] instead of [[0, 1, 0], [0, 0, 1], [1, 1, 1]] as intended.

I added a print statement after the if to display the cell and block when the if is flipped, and that showes the appropriate value, but the matrix assignment still does not work.

#!/usr/bin/python3

matrix = [[0] * 3] * 3

def chunks(in_list, size):
    out_chunks = []
    for item in range(0, len(in_list), size):
        out_chunks.append(list(in_list[item:item + size]))
    return list(out_chunks)

for block in range(len(matrix)):
    for cell in range(len(matrix[block])):
        if chunks(range(9), 3)[block][cell] in [1, 5, 6, 7, 8]:
            print(f"Block: {block}\nCell: {cell}\n")
            matrix[block][cell] = 1
Dew Wisp
  • 11
  • 3

0 Answers0