I’m not a lawyer, but isn’t patent cover the idea […]
In theory, a patent cannot cover an idea. That’s why there are no patents on mathematics.
Practically, patents cover algorithms made into software, or more precisely, a computer system that embodies an idea. Patents were not meant for that, and it is really not clear whether they are actually legal, but such patents are granted.
It is a mess. Especially since the initial motivation for them was - as was it for copyright! - to give individuals which put much money and work into developing something new, something which they can live from.