"Elementary, Dear Data" is the third episode of the second season of Star Trek: The Next Generation. It was first shown on December 5, 1988. It is episode #29, production #129, written by Brian Alan Lane and directed by Rob Bowman.
Overview: Geordi asks the holodeck to make a Sherlock Holmes villain that can defeat Data. The resulting story mixes characters from Star Trek: The Next Generation and "Sherlock Holmes"; Lane and the producers of the episode erroneously believed the Holmes characters to be in the public domain, when they were in fact still owned by the estate of their creator, Arthur Conan Doyle.
Data and Geordi go to Holodeck Two in costume with Data wearing Holmes' signature deerstalker cap, pipe, and cape-backed overcoat and Geordi wearing Watson's bowler, waistcoat and tie. The doors open to Holmes' sitting room at 221B Baker Street and the two take in all the details. Soon a carriage pulls and Data, getting in character, informs Watson that Inspector Lestrade has arrived. Lestrade enters with an anxious foreign emissary and says the man was accosted by Gypsies who have stolen a photograph from him. Before Lestrade can finish, Data rips the emissary's jacket open and withdraws the photograph. Data quickly spins an explanation saying that this emissary works against the King of Bohemia, and that photograph is of the King and his ex-mistress to be used as blackmail. Geordi interrupts for the computer to freeze the program and he barges out of the holodeck.
Geordi goes to Ten Forward with Data following. There, Geordi expresses his frustration in experiencing a Holmes mystery to which Data already knows the outcome. He explains the fun is in the attempt to solve the mystery, not skip to the end. Dr. Pulaski overhears the discussion and argues that Data can only mimic Holmes and can't solve a unique Holmes mystery he hasn't memorized. Geordi disagrees saying Data has exceptional deduction skills and bets he can solve an original scenario that the holodeck generates. Pulaski accepts the challenge maintaining Data will fail nonetheless.
Returning to the holodeck, Geordi and Data are joined by Pulaski who wears a Victorian-era dress. Geordi calls up an original Holmes scenario and the doors open to a fog-shrouded thoroughfare somewhere in 1890's London. Nearby, a vendor shouts that he has been robbed and the trio witness a man running off. Geordi is about to make a move, but Data grabs his arm saying it's a ruse. Data makes for an alley as Geordi and Pulaski curiously follow. Data withdraws Holmes' magnifying glass and spots a rope dangling from a window. Data explains the thief is a diversion and points to a man, Mr. Jabez Wilson, employee of the Red-Headed League, was coming here to meet an untimely demise.
Pulaski cries a foul and claims that Data didn't deduce anything and simply recognized elements from two different Holmes novels. Geordi calls for the holodeck arch and he asks for an original scenario that Sir Arthur Conan Doyle hasn't written to challenge Data. He tells the computer to "create an adversary capable of defeating Data." The London street scene shuffles around a bit and Geordi dismisses the arch. The trio begin heading down the street wondering what surprise the holodeck has in store. From the shadows a well dressed gentleman steps into the street. A prostitute lingers near him who notices the odd look in his eyes. He says that he feels like "a new man" and turns saying "arch" aloud. The holodeck arch appears just as ordered. The prostitute becomes frightened; "Aii! It's dark magic, Moriarty." The man smirks; "...the best kind I'm sure."
Data and Geordi wander the street but soon they hear a scream behind them. Turning, they find Dr. Pulaski is missing. Data withdraws the magnifying glass and announces that Pulaski has been abducted by two men and hurriedly proceeds exclaiming; "The game is afoot! Come, Watson!"
The captor's trail leads into an alley where a crowd has gathered. Data is then surprised by Inspector Lestrade who claims there has been a murder and points to a man on the ground. Data and Geordi examine the body, but Data sees no relevance to the abduction of the Doctor. He quickly deduces evidence that the man was killed by his wife who dreaded his release from prison. Data resumes to follow Pulaski's trail which leads to a warehouse. Inside, Data finds a secret door leading to a sitting room. Geordi mentions this has become a game worth playing, but suddenly a cold voice from behind them speaks... "The time for games is over."
Data recognizes the man as Professor Moriarty, the one worthy opponent of Sherlock Holmes. Moriarty greets his visitors, calling Data, Holmes — "but not Holmes", and Geordi, Watson — "but not Watson". Data asks for Dr. Pulaski and Moriarty assures she is safe, but says his mind is crowded with thoughts and images he doesn't understand. Moriarty continues saying there is a great power called "Computer" which controls everything. He waves about the room and he calls for the arch which appears as commanded. Geordi and Data are astonished. Moriarty explains that the Computer has shown him a monstrous shape afloat in a vast emptiness. He hands Data a paper and a serious look comes over Data's face. Data hurriedly walks out with Geordi following in confusion. Data calls for the exit where he tells the computer to terminate the program, but it denies access indicating an override protocol has been activated. Data tells Geordi they must see the Captain immediately and holds up the paper which has a drawn outline sketch of the Enterprise. Outside the holodeck, Data and Geordi are confounded because the hologram piece of paper is now continuing to exist in real space and time.
Data and Geordi meet with Captain Picard, Commander Riker and Lieutenant Worf to explain the situation. Geordi explains the bet he made with Pulaski, whether Data could use deductive reasoning to solve a Holmes mystery with a worthy opponent who could defeat Data. Suddenly, Geordi realizes his mistake announcing the computer didn't make an opponent for Holmes, but for Data himself. Picard is concerned however that if Moriarty can call the arch then he must have access to the main computer. Data confirms that it would be a level of information necessary to defeat him and that since Moriarty was programed to defeat him and not Holmes, Moriarty would require something he possesses, consciousness. Suddenly the Enterprise is racked by turbulence where the computer states that attitude and stabilization control was momentarily routed to holodeck two. Picard thinks its best he pay Moriarty a visit himself.
Meanwhile, Moriarty entertains Dr. Pulaski by offering her tea and crumpets. Moriarty explains that the computer has informed him they are within a vast ship that sails the stars, but Pulaski feigns ignorance. Pulaski says it's time for her to leave, but Moriarty wonders if she's leaving for here and points to another drawing of the Enterprise on his chalkboard. Pulaski confirms and asks if he'd like to join her.
Picard, now in costume himself, arrives at the holodeck with Data and Geordi in tow. Picard enters and they proceed to Moriarty's warehouse as the holodeck environment chaotically changes around them phasing in and out and revealing parts of the holodeck grid. Picard suggests Moriarty is using more and more processing power and destabilizing the program. Data leads the way and they soon make it to the warehouse where they find Moriarty with Pulaski still in his company.
Picard tells Moriarty he was created to attempt to defeat Holmes, and now that purpose is concluded, win or lose, his purpose is done and must deactivate. Moriarty states he has become so much more and pulls a lever on a contraption next to him which shakes the Enterprise once again. Moriarty says he can affect this vessel as well as inflict bodily harm if he wishes. Picard angrily steps forward and demands to know what Moriarty wants. Moriarty answers that he wants to continue to exist. Picard tries to press that Moriarty is not alive and just a computer conjuration, but Moriarty refuses to believe it saying "Cogito ergo sum" — I think, therefore I am. Moriarty says he was conjured because someone asked for a nefarious character capable of defeating Data, but he is no longer that creation — he is alive and aware of his own consciousness. Moriarty says he wants an existence off the holodeck like they have, but Picard says that isn't possible because they cannot convert holodeck matter into a more permanent form.
Moriarty claims it a pity, saying what he has learned so far has fascinated him, and he does not want to die. Picard admits he does not want to kill him. Moriarty calls for the arch and releases control back to the main computer. Picard tells Moriarty that the ship has a vast computer memory and they will save his program. If, in the future, they find a way to bring him back in a form capable of leaving the holodeck, they will. Moriarty smiles to Pulaski, saying "perhaps we'll meet again." Picard tells the computer to save the Moriarty program and discontinue. Moriarty vanishes.
Back in engineering Picard and Geordi are looking over the HMS Victory model. Geordi states she cracked a spar when the ship was shaken, but otherwise she weathered well. Geordi can't help but think how much more damage could have happened because of a simple misspoken word. Riker calls to report that the starship Victory has arrived. Picard asks Geordi of the model "Will she sail?". Geordi replies "Yes sir". Picard responds, "Then so shall we."