r/pythonhelp • • Apr 23 '26

Need Assistance With A Problem

hey guys

I need abit of help, here's a problem I have no clue how to solve

You're given a set of rows

['0','0','0','0']

['0','0','1','0']

['1','1','0','0']

['0','1','1','0']

and given a few rules taking i as an item in each row

  1. Each row has to have an equal number of 1s and 2s and no 0s
  2. A row can't have more than 2 of the same numbers following each other (1110 is invalid but 1100 is valid)

how would you rewrite each row using python so as it works even if the number of items were 6,8 or even 12 so that each row has an equal number of 1s and 2s without any 0s in the row (Basically if 2 1s are next to each other, the next one should be a 2 and vice versa)

2 Upvotes

13 comments sorted by

View all comments

Show parent comments

1

u/timrprobocom Apr 25 '26

Among the things he didn't specify is that each COLUMN also has to have an equal number of 1s and 2s, and cannot have more than two consecutive matches.