rack one's brain
Also, cudgel one's brains. Strain to remember or find a solution, as in I've been racking my brain trying to recall where we put the key, or He's been cudgeling his brains all day over this problem. The first term, first recorded in 1583 as rack one's wit, alludes to the rack that is an instrument of torture, on which the victim's body was stretched until the joints were broken. The variant, from the same period, uses cudgel in the sense of “beat with a cudgel” (a short thick stick). Shakespeare used it in Hamlet (5:1): “Cudgel thy brains no more about it, for your dull ass will not bend his pace with beating.” Also see beat one's brains out.