… if we conceive of a being whose faculties are so sharpened that he
can follow every molecule in its course, such a being, whose attributes
are as essentially finite as our own, would be able to do what is
impossible to us.
… if the whole universe consisted of the demon and the container, and
energy were needed to operate the gate, the only source of energy is
letting heat flow from B to A. Now, the quantum of B to A heat flow is
a single particle going from B to A. This restores entropy, because on
average the single particles going from B to A are more energetic than
the ones going from A to B.
Put simply, no matter how it is done, both the act of the demon
watching molecules and the act of opening and closing the trapdoor is
by definition work and requires the expenditure of energy.