Make a great mental effort to understand, solve, or remember something, as in
Joe's beating his brains out to finish this puzzle. Christopher Marlowe used this hyperbolic idiom in
The Massacre of Paris (1593): "Guise beats his brains to catch us in his trap." Also see
rack one's brains.