The word problem:
"An old computer consists of 18000 vacuum tubes. One vacuum tube lasts 900 hours. How long can you run the computer before you have to replace one vacuum tube?"
My attempt:
I thought "How many times does $900$ fit in $18000$", so $$ \frac{18000}{900}=20 \, \text{hours} \tag 1 $$
But the answer is instead reversed $$ \frac{900}{18000}=\frac{1}{20} \, \text{hours} \tag 2 $$
I often confuse which value I should have in the numerator/denominator. How should I think? Is there any tricks?
The "correct" way to handle this (as in: this is how I was taught in school) is to keep all the units of measurement together with your numbers, whatever you are doing.
So you have "$900$ hours", and you have "$18000$ tubes".
You are looking for an answer of the form "how long per tube?", that is, "how long per (gap between changing the next) tube (to fail)?"
You expect the answer to be in hours, or technically "hours per tube".
So you want to divide "hours" by "number of tubes".
Hence the answer: $$\dfrac {900 \text { hours} } {18000 \text { tubes} }$$
and you see that you end up with a number which is in the form $\dfrac {\text { hours} } {\text { tube} }$, that is, "hours per tube".
The original answer you gave, that is, $\dfrac {18000} {900}$ in fact gives you the answer to "How many tubes are you going to need to change every hour?"
This technique is often called dimensional analysis.