Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Backtracking) The graduate students in the department of Renotational Pedantics

ID: 3638993 • Letter: #

Question

(Backtracking) The graduate students in the department of Renotational Pedantics have a reputation for not showering very often. The students have discovered that attending class is most pleasant when there are at least two free seats between any two students in a row. The question is: suppose there are k students in a row of n seats. How many different ways are there for the students to sit without smelling each other?
(a) Write a Python program that takes integers n and k and outputs all odor-free subsets
of size k.

Explanation / Answer

def permutation(k, s): r = s[:] for j in range(2, len(s)+1): r[j-1], r[k%j] = r[k%j], r[j-1] k = k/j+1 return r