r/CodingForBeginners • • 2d ago

math in coding

hello everyone im about to start learning to code (python specifically) and i want to learn the math i would need for it first to make the learning process a bit easier.

any pointers would be greatly appreciated

thx for the help

5 Upvotes

16 comments sorted by

View all comments

3

u/mjmvideos 2d ago

Really, the math comes with the domain area you are programming for. The language itself requires no math at all. Though an understanding of addition is helpful in working with loops.

2

u/TheUmgawa 2d ago

I second this. I had to write a prime-number generator for a programming class, where we had to write weekly comments on what we learned that week, and I wrote over a thousand words (including code snippets) on how I increased the efficiency of the generator, without cheating and implementing the Sieve of Eratosthenes.

Every other number is even, so you don’t even have to check those beyond 2. The largest factor of any number cannot be larger than its square root. At this point, you’ve increased efficiency by a huge amount, but you’re still checking all of the odds, even when they’re not prime, so what do you do? You build out the list of primes on the fly, then reference that array, vector, list, or whatever data structure as your modulo. I don’t recall the efficiency increases, but they were pretty significant from iteration to iteration of the program.

Most math isn’t terribly advanced. You just have to figure out how it works. By the way, it’s not (typically ) number theory, because I found those books in the library in high school, and they were not what I was looking for. It came in handy during college, but had nothing to do with anything I ever had to program (except maybe once or twice).