In: Advanced Math
Ten students shall be sorted into the four houses (namely Gryffindor, Slytherin, Ravenclaw, and Hufflepuff) in Hogwarts. If at least one student shall go to each house, how many ways can the students be sorted?
For the sake of simplicity , let us denote Gryffindor by G, Slytherin by S, Ravenclaw by R and Hufflepuff by H.
Let the 10 students be denoted by a1 , a2 , ....a10.
Suppose we have a sorting of the 10 students into the four
houses such that at least one student has been assigned to each
house. Each student can be assigned to a unique house. However, one
or more students can be assigned to the same house. Thus, we have a
function f : {a1,a2,...a10}
{G,S,R,H}
defined by f(ai) = The house to which ai is
assigned to in the sorting for each i in {1,2,...10},
such that every element in the codomain (every house) has at
least one student(preimage) assigned to it. In other words, a
sorting of the 10 students into the four houses such that at least
one student has been assigned to each house corresponds to unique
onto function f : {a1,...a10}
{G,S,R,H} such that f(ai) = The house to which
ai has been assigned to in the sorting for
all i in {1,2,...10}.
Conversely, given an onto function f :
{a1,....a10}
{G,S,R,H} , we get a unique sorting of the 10 students into the 4
houses such that at least one student has been assigned to each
house ( assign student ai to house f(ai) for
all i in {1,2,...10} ).
Thus, the set of all such sortings of the 10 students into the four houses such that each house contains at least one student is in bijective correspondence with the set of all onto functions from {a1,....a10} onto {G,S,R,H}.
Hence, the required number of ways of sorting the 10 students is equal to the number of onto functions from the set of the 10 students onto the set of the 4 houses.
The solution calculates this using the Principle of Inclusion and Exclusion.