I can spend hours and days programming incredibly boring, repetitive code, because the end result is valuable. Teaching your brain to understand this is the struggle the OP faces.
BTW especially with maths, teachers mostly fail at providing any context above 'learn this rule, so you can apply a slightly more advanced version of it next year'. There is a huge amount of context and thought around the mathematics that's being taught, but little effort ever goes into expounding it. If you're struggling with maths in particular, try reading up on some of the history of the topics to find out why they were invented, and what problems they solve. It brings an incredibly richness to what can be a fairly dry, abstract subject.