I am creating a Python program which takes the dimensions of a rectangle shape and creates a table through lists. Then it must find the total amount of available positions and fill half of them with the letter 'S' and the remaining with letter 'O'. My goal is to count how many times the 'SOS' word appears horizontally, vertically & diagonally through a cycle of 50 repetitions and extract the average number of the triplets.
My code so far,
import random
n = 6
m = 7
a = [[i * j for j in range(m)] for i in range(n)]
for i in range(n):
for j in range(m):
if i < j:
a[i][j] = 'O'
elif i >= j:
a[i][j] = 'S'
random.shuffle(a)
for i in range(50):
for row in a:
print(' '.join([str(elem) for elem in row]))
Although I am not sure if my method so far is appropiate, I need ideas on how to create the counting structure for horizontal, vertical and diagonal.
Thank you in advance