print('How many rows in your theator: ') rows = input() print('How many columns in your theator: ') columns = input() soldTickets = [] while len(soldTickets) < rows: print('Fill data for the row: ') row = raw_input() splittedRow = row.split() intifyedRow = list(map(int, splittedRow)) soldTickets.append(intifyedRow) # DEBUG ONLY """ soldTickets = [ [0, 1, 0, 0, 0, 0, 1, 0, 1, 0], [0, 1, 1, 1, 1, 0, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 1, 0, 1, 0], [0, 0, 0, 1, 0, 0, 1, 0, 0, 1], [0, 1, 0, 1, 1, 1, 1, 1, 1, 0], ] """ print('Tickets map') print(soldTickets) print('How many consecutive seats do you need?') requestedSeats = input() AVAILAIBLE_SEAT = 0 rowsWithConsecutiveSeats = [] i = 0 for row in soldTickets: consecutiveSeats = 0 prev = 1 j = 0 for seat in row: # handle first row index if j == 0 & seat == AVAILAIBLE_SEAT: consecutiveSeats += 1 j += 1 continue elif j == 0 & seat != AVAILAIBLE_SEAT: j += 1 continue # first occurence if row[j] == AVAILAIBLE_SEAT & row[j] != row[j - 1]: consecutiveSeats += 1 j += 1 continue # n-th occurence if row[j] == AVAILAIBLE_SEAT & row[j] == row[j - 1]: consecutiveSeats += 1 j += 1 continue # requested occurence is reached if consecutiveSeats >= requestedSeats: j = 0 break consecutiveSeats = 0 j += 1 prev = seat if consecutiveSeats >= requestedSeats: rowsWithConsecutiveSeats.append(i) i += 1 consecutiveSeats = 0 print('Rows with consecutive seats') # DEBUG ONLY # print(rowsWithConsecutiveSeats) if len(rowsWithConsecutiveSeats) > 1: print(min(rowsWithConsecutiveSeats)) else: print(0)