|
Yes, but I doubt you had write code to factor a quadratic equation because it's a solved problem and you have libs that will do it for you. Imagine if you had been given an exercise of such a low level nature for every single topic you might touch in IT in the future. You would have had to code a function to do UTF8 decoding, JPEG rendering, TCP/IP error correction, font rasterization, ray tracing, PEG parsing, an USB driver, data diffing, model training, etc. Also, you don't learn much about programming by creating a function to factor a quadratic equation. You seldom learn about types, side effects, algo complexity, or even about collections, iteration, branching, memory, debugging, etc. You just learn to badly translate a very specific, narrow problem to the language you use. |
Actually, I have, because I've done a fair bit of embedded development and "toss this massive lib on" is not always a reasonable solution. Inferring the structure of plant in controls is often a polynomial factoring problem and it's not something that one tosses Singular or FLINT at on small hardware. But aside from that...
Factoring a quadratic by hand is something I expect a CS major to know how to do, because they might very well be doing algebraic manipulation to develop solutions to real world problems.
And someone who knows how to factor a quadratic by hand knows a number of formulaic (suboptimal) steps to perform it-- the exact kind of things that's easiest to translate to code before you have gotten into that mindset of explicit thinking.
So--- declare and manipulate variables to do the quadratic formula. OK, what if we want to confine ourselves to integers, what can we do? Can we loop and search solutions in some meaningful way like a human would?
It's a completely reasonable space to explore as an early programming problem for someone who's familiar with it.
I'm teaching a secondary student to program right now. In his core math class he's doing a lot of trig. In turn, we're doing a whole lot of exercises like "make these dots chase the other dot using atan2 and sin/cos".