You start with 50 grams of 80% gold. As you add pure gold, the overall percentage of gold increases. As you keep adding gold it will keep increasing to 100% (but it will never actually be 100% because you'll always have your original 50 grams of impure gold in the mix). When you mix two things together like this, the overall percentage will be weighted toward the one that makes up the majority of the mixture. For example, if we only add a tiny bit of 100% gold, the overall percentage would be very close to 80 because the 80% gold is dominating the mixture. If we had tons of 100% gold, the overall percentage would be very close to 100% because now the pure gold is dominating the mixture.
In this case, we want the percentage to be 90, which is right in the middle of 80 and 100. To achieve this, the amount of the 80% and 100% gold would have to be exactly equal. So that is why it should be 50 grams.
Now let's look at a more complicated example: the case where we want the overall percentage to be 95%. Notice that 95 is 3/4 of the way from 80 to 100. If we add enough of the 100% gold so that it pulls the overall percentage 3/4 of the way from 80 to 100, then it must make up 3/4 of the mixture. If it is 3/4 of the mixture there must be 3 parts 100% gold per 1 part 80% gold, a 3:1 ratio, so you would need to add 150 grams.
Of course, there is also the old-fashioned way to calculate it:
%=100*(amount of gold)/(total weight). Amount of gold in 50 grams of 80% gold is .8*50=40. If we add x grams of pure gold, the total amount of gold would be 40+x, and the total weight would be 50+x.
we want this to equal 90%, so solve: (40+x)/(50+x)=0.9 to get [spoiler]x=50[/spoiler]