This is both a Koan and a Ghost Story.
A Koan is a Buddhist saying or parable, designed to teach an aspect of Buddhist belief.
The most well-known koan is ‘the sound of one hand clapping.’
These days a koan is not an exclusively Buddhist phenomenon, and there are koans written by adherents to all religions, but the one that follows is an old traditional Buddhist story.
A young wife fell sick and was about to die. “I love you so much,” she told her husband, “I do not want to leave you. Do not go from me to any other woman. If you do, I will return as a ghost and cause you endless trouble.”
Soon the wife passed away. The husband respected her last wish for the first three months, but then he met another woman and fell in love with her. They became engaged to be married.
Immediately after the engagement a ghost appeared every night to the man, blaming him for not keeping his promise. The ghost was clever too. She told him exactly what had transpired between himself and his new sweetheart. Whenever he gave his fiancee a present, the ghost would describe it in detail. She would even repeat conversations, and it so annoyed the amn that he could not sleep. Someone advised him to take his problem to a Zen master who lived close to the village. At length, in despair, the poor man went to him for help.
“Your former wife became a ghost and knows everything you do, ” commented the master. “Whatever you do or say, whatever you give your beloved, she knows. She must be a very wise ghost. Really you should admire such a ghost. The next time she appears, bargain with her. Tell her that she knows so much you can hide nothing from her, and that if she will answer you one question, you promise to break your engagement and remain single.”
“What is the question I must ask her?” inquired the man.
The master replied: “Take a large handful of soy beans and ask her exactly how many beans you hold in your hand. If she cannot tell you, you will know that she is only a figment of your imagination and will trouble you no longer.”
The next night, when the ghost appeared the man flattered her and told her that she knew everything.
“Indeed,” replied the ghost, “and I know you went to see that Zen master today.”
“And since you know so much,” demanded the man, “tell me how many beans I hold in this hand!”
There was no longer any ghost to answer the question.