In the Brazil nut problem (BNP), hard spheres with larger diameters rise to
the top. There are various explanations (percolation, reorganization, conv
ection), but a broad understanding or control of this effect is by no means
achieved. A theory is presented for the crossover from BNP to the reverse
Brazil nut problem based on a competition between the percolation effect an
d the condensation of hard spheres. The crossover condition is determined,
and theoretical predictions are compared to molecular dynamics simulations
in two and three dimensions.