Nov-18-2022, 03:46 PM
The rules, as stated in the original post, are wrong. I think these are the rules
0 is an empty seat
You can only sit in an empty seat
1 cannot sit next to 1 or 2
2 cannot sit next to 1
I don't understand the problem. Are you trying to add occupants to an existing seating chart (find where 2 can sit in the partially filled cinema) or are you trying to create a valid seating chart given a list of attendees (find seats for [1,1,1,1,1,1,2,2])? If the latter, I think there are 9715 unique solutions for your guest list. If you are trying to seat 11 1's there is only one solution. Do you need to find all solutions or just one?
Can A sit in seat[x][y]?
To determine if A can sit in seat[x][y], gather the occupants of all neighboring seats.
neighbors = (seat[x-1][y], seat[x+1][y], seat[x][y-1], seat[x][y+1])
If the seat[x][y] is occupied (!= 0), it is not available
If any neighbor == 1, the seat is not available.
If A == 1 and any neighbor != 0 the seat is not available.
0 is an empty seat
You can only sit in an empty seat
1 cannot sit next to 1 or 2
2 cannot sit next to 1
I don't understand the problem. Are you trying to add occupants to an existing seating chart (find where 2 can sit in the partially filled cinema) or are you trying to create a valid seating chart given a list of attendees (find seats for [1,1,1,1,1,1,2,2])? If the latter, I think there are 9715 unique solutions for your guest list. If you are trying to seat 11 1's there is only one solution. Do you need to find all solutions or just one?
Can A sit in seat[x][y]?
To determine if A can sit in seat[x][y], gather the occupants of all neighboring seats.
neighbors = (seat[x-1][y], seat[x+1][y], seat[x][y-1], seat[x][y+1])
If the seat[x][y] is occupied (!= 0), it is not available
If any neighbor == 1, the seat is not available.
If A == 1 and any neighbor != 0 the seat is not available.