Is there an idiom/phrase which contains the word "head" to mean "thinking hard to solve a problem"?

Solution 1:

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.

(link)

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.

Solution 2:

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.

Solution 3:

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).