Sorry for the long reply here, but I think a lot of people have the same thoughts, so I’ll elaborate.

It’s not in the individual instructions that there is uniqueness, but instead in the combination of them, that makes the code. By your same argument, every possible thing you could do with the English language has already been done because we’re limited by a finite number of 26 letters or a finite number of about 170,000 words, give or take, and so there’s nothing novel or unique in a new novel -- it’s already in the sandbox.

There are 2 big things going on to get you a patent. 1 – it has to be subject matter than we, as a society, by our laws, deem “patentable subject matter” and 2 – your particular thing, that you say you’ve invented, is both novel and nonobvious (the latter means it wouldn’t have been obvious to combine more than one novelty reference together to come up with your invention).

Think of 1 as the ticket getting you into the show, and 2 as your seat at the show.

The math thing you’re talking about comes from the Supreme Court. For over a hundred years, the Supreme Court has narrowed the meaning of article 1, sec. 8, clause 8 of the constitution (about patents) to exclude mathematics and algorithms as patentable subject matter (item 1), because it’s too important, not because it’s trivial (item 2). They call it “preemption,” meaning giving someone a limited monopoly say over E=MC^2 can preempt an entire field from developing.

That’s very different from it being obvious (item 2), in fact you could say it’s the opposite, which is the argument you’re making in your first paragraph.

But, it turns out that you’re in good company. This particular Supreme Court, the Roberts Court, made the same mistake, namely of mixing patentable subject matter and obviousness in it’s Alice decision, that runs contrary to it’s own case law. It's been harshly criticized in the patent field, though it's unlikely anyone outside our "sandbox" has heard it.

The Alice decision doesn’t really kill business method or software patents, as many have said, but it did weaken them. Much of this is because if you're defending an alleged infringer (and I've represented both plaintiffs and defendants), you will make much hay out of the court's language ("dicta") to win your case.

The other issue we have is with the courts. You see, for several decades, the Supreme Court has punted on patent law, and let its lower appellate court, the Federal Circuit make the calls. The Fed Cir is the appellate court with exclusive jurisdiction over patents, and it’s decisions are way more important than what the USPTO says (in fact the USPTO must follow it).

This particular Supreme Court has woken up and decided to kick the Fed Cir’s butt (reverse it’s decisions). Think of it like parents who’ve placed all of their child raising duties on the oldest sibling. Then one day, after shirking their own duties for years and when the kids are nearly grown, they beat the tar out of the oldest sibling. For years, the Supreme Court has even admitted it doesn't really understand technology or patent law.

And don’t get me wrong. I’m not advocating for software patents, but I do want (1) that our laws be logical and consistent in creation and application, and (2) preferably for a law to be passed by the people versus de facto by the Supreme Court in its application (which is really a construction).