"This isn't magic -- it's logic -- a puzzle. A lot of the greatest wizards haven't got an ounce of logic, they'd be stuck in here forever."
-- Hermione Granger (PS16)
Hermione works out the logic of the puzzle, which she says is an excellent form of defense, since many powerful wizards have no sense of logic. She figured out which potion bottle she needed to drink to go back safely through the purple flames and warn Dumbledore and which one Harry needed to drink to safely walk forward through the black flames to face whatever was in the chamber of the Philosopher’s Stone.
Each of the tasks faced by Harry, Hermione, and Ron were clearly tailored to their skills. Not only that, the tasks guaranteed that only one of them would make it all the way through -- Ron needing to sacrifice himself at chess, only enough potion left for one person to go through the black flames. Some fans have theorized that the entire setup was created by Dumbledore to test Harry's abilities and resolve, going all the way back to allowing Harry to discover the Mirror of Erised ahead of time. Until the seventh book, this seemed unlikely given the kindly personality Dumbledore showed. However, as the full story of Dumbledore's actions became known in book seven, the idea that he would have created this "obstacle course" simply to test Harry and his friends is somehow more believable.