These two types of batteries are similar enough to be interchangeable as long as the battery is made to fit, which is where aluminum foil comes into play.
Aluminum foil is a conductor, meaning electricity can pass through it. This means it can bridge the gap left between a triple-A battery and a double-A battery slot.