Here's what happened:
1. Bilbo was trapped in the trolls' cave: After getting lost on his journey, Bilbo accidentally ended up in the cave of three trolls: Tom, Bert, and William.
2. The trolls found Bilbo: The trolls captured Bilbo and planned to eat him.
3. Bilbo hides: While the trolls are arguing over who gets to eat him first, Bilbo hides under a large cauldron.
4. Bilbo finds the purse: He discovers a purse filled with gold coins under the cauldron.
5. Bilbo keeps the purse: He takes the purse and hides it in his pocket, feeling guilty but also thinking it's a good thing to have in case the trolls try to harm him.
Bilbo's actions were a bit impulsive, but ultimately, it was the trolls' own greed and arguing that led to their downfall. They argued so much about who gets to eat Bilbo that the sun rose, turning them into stone.