correctly matching and unmatching gems

the solution to every problem is to loop through every array twice,
twice as twice if needed