I am looking for an idiom or phrase that means "thinking hard by myself to solve a problem". I hope the idiom or phrase has the word "head" in it.
Example: I have been ____ head ______ for the last 5 days to solve this math puzzle.
I have been scratching my head for the last 5 days to solve this math puzzle.
The Cambridge Dictionary says the following with regard to British English:
scratch your head
- to think hard about something
- A lot of people must be scratching their heads about which way to vote.
It also says the following with regard to American English:
scratch your head
- to have difficulty understanding something
- All I can do is scratch my head and ask why.
To address the point that you want something that means "thinking hard" instead of "to have difficulty understanding," I can attest as a native speaker of English in the United States that to scratch one's head does imply effort being put into solving a problem. Also, if someone is spending 5 days on a math puzzle they must find it difficult, the implication is present that some effort is being put into solving it is there anyway.
You have been trying to wrap your head around it.
The Free Dictionary says:
wrap (one's) head around
To comprehend something that one considers challenging, confusing, or a foreign concept.
So your sentence could be modified a bit:
I have been trying to wrap my head around this math puzzle for the last 5 days.
EDIT: As per Mari-Lou A's comment, in British English you can also say that you can't get your head around it.
From the Cambridge Dictionary:
If you say that you can't get your head around something, you mean that you cannot understand it:
I just can't get my head around these tax forms.
So the sentence would be:
I haven't been able to get my head around this math puzzle for the last 5 days.
You've been banging your head against a wall.
The Free Dictionary gives an example that is almost the same as your sample sentence.
To attempt continuously and fruitlessly to accomplish some task or achieve some goal that is or seems ultimately hopeless.
- I feel like I've been banging my head against a wall trying to understand this math equation.
- Some people are never going to agree with you on this, so it's no use banging your head against a wall trying to convince everyone.
Of course if you actually solved the problem, and did it in a clever way, someone might tell you that you really used your head (there).
There's racking my brain, which means exactly that and sort of comes close to an expression with "head" in it.
I've been doing my head in trying to come up with an answer.
Or less clumsily,
This maths question has been doing my head in for the last five days.
If you're working with someone else, you can put your heads together to find a solution.
The term "headwork" comes to mind:
It would need to need some (head)work to fit in your sentence, however. Perhaps "doing some serious headwork." The verb form "headworking" doesn't appear in MW, or other sources I've found.
Jerome Rodale, The Synonym Finder (1978) suggests trouble one's head.
Christine Ammer, The American Heritage Dictionary of Idioms, second edition (2013) offers this entry for the phrase:
trouble one's head with Also trouble oneself about. Bother or worry about, as in Don't trouble your head with these details; I'll take care of it, or It seems to me that teachers should trouble themselves more about teaching and less about manners. The first term dates from the mid-1600s, the variant from the early 1500s.