The Torah distinguishes between the animals which are pure and those which are impure. The battle between the different thoughts in a person's mind is a battle between the pure and the impure animals. The simple fact is that it is impossible for two thoughts to be in the mind at one and the same time. It is therefore an easy matter to rid yourself of bad thoughts by being quite passive. Simply don't think them.
Thought is a very elevated level.
One who wishes to think only thoughts of holiness and ascend to the world of thought must be completely silent. Even saying something good and noble would spoil the thought. But even when a person is completely silent, there are still many distractions which confuse the mind. He still has to purify his thoughts. Sexual fantasies are the prime source of all impurity.