Make sure to save before entering the cave, I'm not 100% sure, but if you fail the puzzle, I'm not sure if there's a way to reset it.
I had saved as I always do luckily, and failed the first time, and I didn't see a way to reset it. I had to reload. There might be a way but I missed it, or it...