How is order determined in the recommended Pokémon list when fighting at a gym?

Solution 1:

As far as I've seen, it orders them by CP, skipping any that are not at full health. This can be kind of ridiculous when you have a 1000cp Pokemon with 89/90 health, and it suggests a 700cp Pokemon with 68/68 health over it, but this game is not perfect, it just does the best it can.

I'd also guess that the game takes type effectiveness into account, I've seen this happen in training a gym. The game suggested a weaker vaporeon over a stronger flareon, because the first opponent in the gym was a fire-type pokemon. I have no idea if the suggestions are just based on the first opponent or every opponent in the gym though.

Solution 2:

I observed that there are some criteria it looks for:

  • High cp pokemon have a higher chance to show up
  • High remaining hp pokemon have a higher chance to show up, it may suggest pokemon with lower hp as long as its remaining hp is higher than your others
  • Tries to counter the pokemon types in the gym
  • Does not take DPS, move strength or speed in consideration at all

I'm sure there is a formula, which mixes these variables with different weights. I'm also searching for it.