Lots of good stuff in this thread already, so I'll just add a thought or two. A lot of commentators here have picked up that what you need is roughly the equivalent of a "Data Structures & Algorithms" course. I agree with that sentiment. Whether you actually take a course, or work through some books, or whatever, so long as you acquire that knowledge you'll have a great foundation.
The question then is "what next?" To which I would say that you want roughly the equivalent of a course titled something like "Introduction to Computation" or "Automata Theory & Computation" or whatever. That is, you'll want to understand things like Universal Turing Machines, Finite-State Automata, Formal Grammars, and some basics of Computational Complexity Theory (the same "Big O" stuff you'll hear mentioned in the Data Structures & Algorithms class, but going a little bit deeper). This stuff isn't necessarily required to do a lot of "grunt work" programming, but it starts coming into play if you want to do some more advanced stuff.
One of the classic texts in this area is by Hopcroft & Ullman.
And on a semi-related note, there's a really good course on Youtube: MIT 6.042J Mathematics for Computer Science, taught by Tom Leighton[1], that you might find useful as well. A version of the book[2] used in that course is freely available online as well
The question then is "what next?" To which I would say that you want roughly the equivalent of a course titled something like "Introduction to Computation" or "Automata Theory & Computation" or whatever. That is, you'll want to understand things like Universal Turing Machines, Finite-State Automata, Formal Grammars, and some basics of Computational Complexity Theory (the same "Big O" stuff you'll hear mentioned in the Data Structures & Algorithms class, but going a little bit deeper). This stuff isn't necessarily required to do a lot of "grunt work" programming, but it starts coming into play if you want to do some more advanced stuff.
One of the classic texts in this area is by Hopcroft & Ullman.
https://www.amazon.com/Introduction-Automata-Theory-Language...
And on a semi-related note, there's a really good course on Youtube: MIT 6.042J Mathematics for Computer Science, taught by Tom Leighton[1], that you might find useful as well. A version of the book[2] used in that course is freely available online as well
https://www.youtube.com/playlist?list=PLB7540DEDD482705B
[1]: https://en.wikipedia.org/wiki/F._Thomson_Leighton
[2]: https://people.csail.mit.edu/meyer/mcs.pdf