Herbert A. Hauptman, who won the Nobel Prize in chemistry for developing pathbreaking techniques used to determine the molecular structure of chemical compounds and who had a lasting impact on research into anti-cancer drugs and other pharmaceuticals, died Oct. 23 at a hospice in the Buffalo suburb of Williamsville, N.Y.

He was 94 and had a stroke several weeks ago. The death was confirmed by the Hauptman-Woodward Medical Research Institute in Buffalo, where Dr. Hauptman had been president for more than 20 years.

Dr. Hauptman, a mathematician who had taken just one chemistry class in his life, became the first non-chemist to win the Nobel in chemistry. He shared the prize in 1985 with Jerome Karle, a physical chemist who spent his career at the Naval Research Laboratory in Washington.

Dr. Hauptman and Karle had been classmates at the City College of New York in the 1930s and were reunited after World War II at the Naval Research Laboratory. At the time, Dr. Hauptman was working at the laboratory while pursuing a doctorate in mathematics at the University of Maryland.

He said his background in math complemented Karle’s knowledge of chemistry as they worked to unravel a problem that had flummoxed scientists since the development of X-ray crystallography in 1912.

Crystallography, a method to view atomic and molecular structures, involved beaming radiation through a crystal. The resulting pattern of perhaps hundreds of thousands of dark spots could be captured on an X-ray sheet.

But chemists and crystallographers had found it difficult to work backward from this pattern to decipher the structure of the molecular atoms from the pattern recorded on the X-ray sheet.

Dr. Hauptman and Karle devised mathematical algorithms to reconstruct a three-dimensional picture of the atoms, thus unlocking valuable information about the architecture of molecules vital to human life. Their algorithms helped determine molecular structures quickly and easily.

It was this work that set the foundations for which they won the Nobel Prize, which cited their “outstanding achievements in the development of direct methods for the determination of crystal structures.”

Their findings, produced in a 1953 monograph and many papers, initially met with tremendous skepticism.

“There was a lot of resistance to it, mostly because it wasn’t understood,” Dr. Hauptman told the New York Times in 1985. “It was highly mathematical and crystallographers didn’t have the training to understand it.”

The Hauptman-Karle method came into wider use in the 1960s, mostly because crystallographers began using it successfully to study proteins.

The duo’s greatest impact came in the 1980s when a computer program Dr. Hauptman helped design, known colloquially as “Shake and Bake,” allowed scientists to apply the mathematical algorithms to increasingly larger, more complex molecules.

“This greatly expanded its potential use for the drug industry,” said Eaton Lattman, a biophysicist who is chief executive and executive director of the Hauptman-Woodward Medical Research Institute.

The work done by Dr. Hauptman and Karle has been credited with breakthroughs in many fields, notably research into drugs to treat cancer, high blood pressure and heart disease.

Herbert Aaron Hauptman was born in the Bronx on Feb. 14, 1917, and was the eldest of three sons of a printer and a sales clerk. He said he developed an interest in mathematics as soon as he could read, and his parents encouraged his pursuits.

He was a 1937 mathematics graduate of the City College of New York and received a master’s degree in mathematics from Columbia University in 1939. He received a doctorate from the University of Maryland in 1954.

During World War II, he was a civilian radar instructor for the Army Air Forces and eventually served active duty in the Navy in the Pacific.

After the war, he joined the Naval Research Laboratory and became head of the mathematical physics branch by the mid-1960s. Lattman said Dr. Hauptman was being pushed increasingly into weapons research, but his opposition to the Vietnam War prompted him to leave the NRL.

Dr. Hauptman had earlier collaborated with the Medical Foundation of Buffalo, which was then a small center specializing in endocrine research. He joined the foundation in 1970 and later became its research director and president. In 1994, the foundation was renamed the Hauptman-Woodward Medical Research Institute to honor Dr. Hauptman and a major benefactor.

The institute is now a center for the development of X-ray crystallography and serves as the department of structural biology at the University of Buffalo. The institute also conducts drug research, building on Dr. Hauptman’s groundbreaking early work.

Beyond his laboratory and administrative obligations, Dr. Hauptman enjoyed designing stained glass in geometric patterns, and some of his work was displayed at a Buffalo gallery.

In 1940, Dr. Hauptman married Edith Citrynell, a teacher. Besides his wife, of Williamsville, survivors include two daughters, Barbara Hauptman of Williamsville and Dr. Carol Fullerton of Bethesda; and a brother, Robert Hauptman of Silver Spring.

After winning the Nobel, Dr. Hauptman reflected on his fruitful if hectic early years in the Washington area, shuttling almost constantly between the lab, the university and his home in Bethesda.

His daughter Carol, a research psychologist, admitted to a mischievous streak growing up. She told The Washington Post in 1985 that she once tried to play a prank on her father, adding a minus sign to one of his formulas he left on the dining room table.

“But right away, he knew,” she said.