Skip to content

Instantly share code, notes, and snippets.

@josecolella
Created February 17, 2017 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josecolella/f2475bd2accfb7d2bce3b3bed1f77129 to your computer and use it in GitHub Desktop.
Save josecolella/f2475bd2accfb7d2bce3b3bed1f77129 to your computer and use it in GitHub Desktop.
Permutation Problem
#!/usr/bin/env python
def solution(N, S):
reserved_seats = S.split(" ")
seatMarkers= ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K']
count = 0
formatted = []
seats = []
# Creation of list of seats
for row in range(N):
for seatMarker in seatMarkers:
seats.append("{}{}".format(seatMarker, row + 1))
# Format the list into list of sets: 3 seats, 4 seats, 3 seats
for i in range(0, len(seats), 10):
formatted.append(seats[i: i+ 3])
formatted.append(seats[i+3:i+7])
formatted.append(seats[i+7:i+10])
# Remove reserved seats
for seat in formatted:
for reserved_seat in reserved_seats:
try:
seat.remove(reserved_seat)
except ValueError:
pass
# Count available seats
for seats in formatted:
if len(seats) >= 3:
count += 1
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment