This story was first published in 1909. As one of Twain's later stories, it was tightly written, and it is also very reminiscent of the folk tale genre that he was emulating. In fact, it sounds do much like an actual folk tale, that I tried to find one that inspired it, but I couldn't find anything quite like it. I did change the ending a bit to clarify my sense of what the story is about.