I’m writing this article because I recently did this exercise in HackerRank:

I don’t have a degree in computer science or similar (but i’m working as a software engineer the last 3 years) so I really don’t have a solid math knowledge and at first sight this exercise seems easy, right?

Most of you will think that it is, but to me it wasn’t. My first approach was to think in a logical solution (at least I’d like to think that it was), then I thinked that if i wanted to know if the kangaroos will ever land on the same location at the same time I would have to move the kangaroos until they were both on the same location

I designed a loop that would move the kangaroos and check if they are on the same position.

Forgetting other validations, I only wrote the necessary code for the case:

```
for i:=0 ; i<10000; i++ {
kOnePosition = moveKangoro(x1, v1)
kTwoPosition = moveKangoro(x2, v2)
if kOnePosition == kTwoPosition {
fmt.Println(“YES”)
break;
}
}
```

I wrote variants of this code and other ones, but neither of them passed the tests. After 10 or 20 minutes I thought in a math solution.

The equation to verify if in n jumps the kangaroos are going to be on the same location is this:

x1 + (v1 * n) = x2 + (v2 * n) -> where n is of num of jumps.

So, we are going to resolve this equation:

(v1 * n) — (v2 * n) = x2 — x1

n(v1 — v2) = x2 — x1

n = (x2 — x1) / (v1 — v2)

We know that the value of n needs to be an integer, so we’re going to replace the division by the modular division and check if the operation leaves a remainder of 0

(x2 — x1) % (v1 — v2) == 0

This means that for a set of initial positions and meters per jump, we can know that the kangaroos are going to be on the same position at the same time only if the remainder value is 0.

Again, I’m forgetting other validations, I only wrote the necessary code for the case:

```
if x1 == x2 && v1 == v2 {
fmt.Println("YES")
} else if x1 == x2 && v1 != v2{
fmt.Println("NO")
} else {
if v1 > v2 && ((x2-x1)%(v1-v2)) == 0 {
fmt.Println("YES")
} else {
fmt.Println("NO")
}
}
```

This algorithm passed all the tests and we could only do this efficiently with maths.

Sometimes I hear developers say “Math is not very important” or phrases like “A good coder is bad at math” and I think that they are wrong because as we can saw in this case, maths helps us to solve a problem in an efficient way.

I’ve a lot to learn and It’s exciting to find these problems to improve every day.

Posted on by:

### Douglas Makey Mendez Molero

I am a young enthusiastic programmer with great desires to overcome new challenges. I like to face unknown issues and learn new technologies always trying to give more than 100% in everything I do. On

## Discussion

I'd say a formal math education is totally unnecessary for 99% of the programming tasks, however people who are good at programming will in general also be good (or at least okay) in math. To be good at programming requires the ability to think in an abstract, analytical and systematic way, and that goes for math too.

On the other hand, I've read (and believe) that performing programming tasks activates the "language" part of the brain rather than the "math" part of the brain.

So I'd say there are ties or commonalities between the two but I wouldn't overstate the importance of math for being a good developer in general.

The story changes of course once you venture into numerical/scientific programming or data science.

Hi! Could you tell me where you read the thing about programming activating the "language" part of the brain please? I'm interested about it.

Yes absolutely, I don't know where I read it originally but it was easy to google it. Scientists put programmers in an MRI scanner and then analyzed which brain centers were activated when they started to study/read source code. Their conclusion was that primarily the "language" center of the brain was activated.

In case you'd want to read the original research paper: infosun.fim.uni-passau.de/cl/publi... however here is a good layman's summary:

medium.com/javascript-scene/are-pr...

and another one:

huffingtonpost.com/chris-parnin/sc...

and some discussions:

reddit.com/r/askscience/comments/7...

Now, my take on it is that I'm not surprised by this outcome, not just because "programming language" has the word 'language' in it, but also remember the phrase "well written software reads like prose" (or like a novel).

Also remember the importance of stuff like choosing good (meaningful) variable names, and so on. Having an excellent command of native or natural language has got to be a foundational pillar for at least a large part of programming.

On the other hand, I noticed that there are many articles on this topic, but all of them seem to refer to the same scientific paper with the MRI scanner, so the scientific basis seems to be a bit narrow (only one group who researched it), but it seems reliable enough.

However, the scope of the study is fairly narrow - only

readingsource code. What about writing, what about debugging, testing, what about other activities associated with 'programming'? I dare to make a prediction that additional "centers" will be activated, but these kind of scenarios weren't scientifically studied (with MRI and whatnot).Also, reading source code may be a little like reading a book (detective novel?) but grokking a complex system also seem akin to taking apart a complex piece of machinery.

So all in all I believe the basic premise of the theory

butI'm convinced that it's only part of the story and the full picture is a lot more complex and nuanced.Thanks a bunch! I agree with you entirely. I read the articles and the thing is, we're just going to have to wait for more in-depth studies to come out to form meaningful opinions on the subject. Still a very interesting read and I recommend it to any developer on here.

I think this is a case of everyone being generally right, but saying the same thing in different ways.

Having been a dev for ~17 years, I agree that most tasks I perform each day can't be expressed in pure mathematics as easily as the kangaroo problem above.

Also having been a dev for ~17 years, I agree with you that for some problems, a mathematical solution is superior to an algorithmic one.

You seem to see clearly the relative importance of mathematics in software development.

Thatis far more important than who's right or wrong in this case. :DCheers!

I would say that a strong understanding of algebra, functions, and boolean logic/truth table work is pretty much required for any developer.

Beyond that, it really depends on the type of work and the problem domain you work in. Certain technologies, and certain problem domains can require additional mathematical skills for you to understand the problem you're solving, and be able to relate to it in your code.

For instance, someone heavily involved in relational databases needs a strong understanding of set theory (the basis of SQL). If you're working in a bioinformatics realm, you need a strong linear algebra and statistics background. If you're doing real-world modeling (eg, simulating for airflow over a wing), you'll need to understand the physics involved (and hence the math required by that physics).

It depends on the type of programming job you have I'd say. For mine working on CAD/CAE software it's critical as I have to read/write academic research at times to implement complex/unique algorithms to do a particular job. It's fairly maths intensive at times, with lots of geometry and topology.

Also, Mathematics is more than just numbers and equations, it provides you with a logical way of breaking down a problem and gives you a toolbox of thought processes to use when trying to solve a problem.

So I'd have to sit on the fence for this one. I'd say it's not essential for all dev jobs, but can help for some software development roles.

It really depends on what you are programming. If you want to become a video-games developer, you absolutely need to know maths. Specially geometry and vectors.

For Neural Networks, you will need to know calculus in order to understand the papers.

If you are a web developer and work with a high level programming language, literacy skills are the most important because your main job will be, not making the computer do what you want, but understanding other developers' code and write code that other developers can understand.

Being able to code a big amount of business logic without making a spaghetti mess, is a really important skill to have, and it does not require any knowledge of mathematics.

Algorithms are math. Logic is math (and philosophy). Finance is math. Statistics is math. Metrics (QA, Marketing, Business) are math.

Math is a large field of study. There are obviously portions of coding that have nothing to do with math, but the vast majority of it involves math in some way.

I find it hard to believe that somebody could be a good coder without being good at least some aspects of math.

Be leary of coders who say they don't know, or don't like math.

"Be leary of coders who say they don't know, or don't like math."

This is a silly statement, how does a preference to a potentially unrelated field of study relate to the skill of the developer?

Web developers very rarely need any advanced math concepts for example. If you're not gonna hire a web developer because he doesn't like maths you're gonna have a hard time hiring. In fact from my personal experience most developers don't like maths. In Romania they go to Informatics universities as opposed to Mathematics-Informatics ones in order to evade a large part of maths.

Do you disagree with my assessment of the breadth of the math discipline? Or are you really saying that a coder could get away without know any math what-so-ever?

I said advanced mathematics, you obviously can't get away as a programmer without knowing basic maths.

However generalizing that a programmer who hates maths is a programmer you should avoid is beyond silly. It depends on the subfield. If you're gonna hire a game engine developer who doesn't know trigonometry or linear algebra of course you're gonna have a bad time, but if you're hiring a mobile developer you don't care how good he is at calculus.

Math is important, but not because of the mathematics.

Instead, it is important because it teaches you to think structured, so math is not the aim, it's the means. It teaches you analytical skills that you need to solve programming problems.

Because jumping kangaroos are rarely interesting ...

source

First, I would say that Discrete Mathematics is very important. You learn Boolean logic and set theory. Nice things to know when writing software. From my own personal experience mathematics has been quite valuable. For example, you are working on an application that requires the best possible performance. You have two algorithms that you are considering, but which one will be faster? I have used mathematics extensively to make this decision. It's so much easier to do a little calculus than a series of tests with actual data. I spent my career working on apps where execution time was vital. Using a little math always seemed easier to me.

How important is math in computer programming? My first reaction would be "not much" as I've never needed to do much math as a web developer. But I suppose the importance of math depends on what sort of development is being done.

Interestingly I just mentioned to my sister the other day how often people used to assume I was good at maths because I worked in IT (which is not the case). Does anyone else have that happen to them?

Best answer here.

I'd like to add that most people think that math is all about equations and formulas, but it really is much deeper and beautiful. Math is the study of how things work and ultimately how the human mind things and deals with complexity.

You are right that math is very useful (it also depends on what kind of coding you do) but it is also very interesting and beautiful by itself when you learn it the right way. I think many people dislike, fear or misunderstand math because it is not taught correctly in schools.

Congrats for being eager to learn and improve your skills, you are on the right track here.

Finally, I would like to recommend you a coupke of things:

The paper "A mathematician's lament" by Paul Lockhart talks about what's wrong with how math is usually taught. A very nice and entertaining read.

The books "The art of computer programming" and "Concrete Mathematics" by Donald Knuth and others ate simply awesome. Try Concrete Math first as it has the math needed to read the art of computer programming and it really makes you think a lot, it is hard but rewarding and beautifully written.

In the last 25 years, the only serious mathematics I've used was part of a forecasting system, in which I had to take forecasts of A, B, and (A-B), where A & B were a couple of orders of magnitude greater than (A-B), and adjust the forecast values of A and B (lets say Af and Bf) in order that the (Af - Bf) was equal to the the forecast of (A-B).

Now I didn't do the forecasting, I just had to do the adjustment, and it turned out that to so I had to solve a quadratic equation using the classic method.

In Informatica Powercenter.

Law of diminishing returns.

You can be a great programmer without the formal knowledge, sure.

Learning all the math and computer science stuff is hard. And most of the time you don't need it (compared to other coding-related skills others mention), but when you do - boy oh boy it matters alot. Your simple excercise is a great example.

So on the importance - the answer is as usual 'it depends'.

I think most important, generally, is to understand how things that you use work. That includes some math, but more importantly it includes knowing how memory is managed, how the VM that's running your javascript code works and what sort of optimizations it does and so on.. Once all that knowledge fits together it feels really good to know

exactlywhat you are doing.It completely depends what you are doing. I used

`Quaternion.slerp`

in`Unity3D`

on an almost weekly basis in my part-time job for 2 years during high school, and only just learned what Quaternions were and how to use them mathematically this year (and I'm a junior pure mathematics major in university now).Likewise, you could make it pretty far into using something like

`Torch`

for AI/ML without learning abstract or linear algebra, I think.Understanding boolean algebra - which is a lot simpler than it sounds - is very useful. It lets you write shorter and more concise logical statements and better understand overall how computers work. It is absolutely essential to even starting to understand computer hardware at the chip level - for example, CPU design. But a lot of people work for years and years as software developers/engineers and never encounter any of that stuff.

In university, I often learn more in my free time on Stack Exchange and from extra textbooks than in class. Classes provide tests, structured learning, and homework sets, but at the end of the day we have to learn a lot of the material on your own. So not going to college for math or CS isn't necessarily a big deal - it just means you have to learn a bit more on your own than most people.

One area where I feel math really helps is any sort of scientific modeling. I can't imagine doing modeling without having 2 semesters of fairly advanced linear algebra under my belt. That said, a lot of statisticians do similar work from a statistical perspective, and I'm not sure that they all know about metric spaces, vector spaces, fields, groups, etc. etc.

Let's just cut the crab...

I have taken lots of practical math cuz I enrolled in computer engineering (Calculus 1 & 2, Linear Algebra, Statistics & Probability, Differentail equations, physics 1 & 2)

And hell no, I have never used those for the 7 years passed in building enterprise software.

Please correct me if I am wrong but won't your answer print "No" for the following input (0,12,4,2).

Here x1 = 0, v1 = 12 and x2=4 and v2=2.

First Kangaroo x1 reaches 12 in 1 step & second Kangaroo reaches 12 in 4 steps.

But your solution will print "No".

I guess the question is should the both take the same number of steps to reach the common point.

The requirement is to land on the same point at the same time ;)

I'm saddened by people being dismissive of mathematics here but I think it's because a lot of people dont see maths as being much more than arithmetic and statistics.

I strongly urge you to look at

Category Theory, which is a branch of maths.It is a broad area which is concerned about formalising abstractions, such as sets.

Formalising abstractionsDoes that sound familiar? If you have any interest in functional programming you owe it to yourself to investigate it.en.wikipedia.org/wiki/Category_theory

I've worked as a Programmer in finance for 20 years. In all that time I have never needed more than the most basic maths (+-*/ etc).

and the correct answer to any programming problem involving kangaroos is....Who cares ;)

I feel there are two questions here rolled into one.

## How important is understanding the specifics of maths?

This depends a lot on the area you're working in. If you're working with maths (like in neural networks), you obviously need to know those quite well. Also, if you want a fighting chance with functional languages, you should know the theory behind them. And whatever you do, you must understand Boolean logic. But apart from the above, you can often get by without even undergrad level maths. However...

## How important is understanding the mechanics of maths?

This is the key to all developers. In particular there are two concepts that you have to master with time: abstraction and laziness.

Abstraction is the lifeblood of software development, it's what enables you to identify the structure of a problem, and model it in code appropriately.

And by "laziness", I mean a very specific type of laziness that is shared by maths and software: when you think about it, the history of maths is the history of people finding easier ways to do increasingly more complex things. And the same is true for software: recognising that you're doing a repetitive thing and instead of doing it, using abstraction (and from that, automation) to make your life and job easier.

TL;DR:You may think the specifics of maths aren't important for your job, but the underlying principles absolutely are.I feel like it's always going to be topic specific. Some projects I've worked on have used very basic math and worked flawlessly, while having issues with being able to do math other projects I've had to ask people to help/do the math for me. A company I use to work for even hired 3 mathematicians because of the amount of math that was required.

Specific topics such as machine learning and neural networking will require a lot of it. The topics generally range from needing basic math, algebra and in some cases calculus.

I've always suggested to people to have some basic understanding of the topic that would be required even if someone else is figuring out the math side of things, that way when you come to look and work on it you're not completely lost.

I'm not an experienced dev, but judging by what the task is asking for an output (a simple binary yes/no), this is definitely the most efficient way to come up with the solution. (It honestly didn't even occur to me that you could solve it that way)

However, if the task was also to figure out at what exact second they would meet (or at least be the closest together), maybe a stepping algorythm wouldn't be such a bad idea. For instance, if the difference in distance between the two kangaroos becomes greater after one step, they're never going to meet. However, if the distance shrinks after the first step, the program should loop the steps until both kangaroos meet (distance being zero), or at least monitor when the distance starts increasing again, marking down the step before it started to increase (so we also have the lenght of the shortest distance between them, as well as the exact second that happened)

Hope this all made sense!

There's a problem with websites such as HackerRank: they only test things that can be automated.

The tasks they give you must be formed in such a way that their solution can be quickly verified by a program. Meaning, the tasks must be defined explicitly in a unambiguous way.

For a specific input, your program must return a specific output. Logical thinking is an important trait but it is not the only factor in programming.

These tasks are written by skilled programmers. However, in real life, your client won't be an engineer who figured everything out beforehand. You will have to be flexible, use object design, refactor, improvise along the way and often, work as a team.

How will you gauge these skills? You need human analysis and commentary which takes money and time.

And yet, these sites teach people that the only important thing to know is algorithms. They don't say: "eh, we test a part of your skillset. The other, equally important segments are too much of a hassle for us to check".

I'm a graduating senior double majored in math and CS. I love math and CS and software engineering, but I do have to say that I can't really recommend that path to someone whose only goal is to become a SE/SD. For 90% of people most if the extra curriculum won't ever come up. The real benefit is having a different paradigm to approach problems with. That's great, but a Math degree is probably (definitely) not the most efficient way to achieve that and is totally doable through self study with only cursory looks at proof techniques. All in all it's really a matter of enjoying the subjects you are learning, IMO everything else will fall into place

Math is very important. It help us to make solution looks cleaner. I don’t agree with “good developer is not good at math”

Good Maths base is a must, but you don't have to be THAT good. Just some basic knowledge usually is enough. What you have to be good at is solving math problems 😀

This is the exact same problem that made me realise this thing.I always use it as example to my mentees.

I think everyone in IT should have at least an idea of what time complexity is. Beyond that, math knowledge is relevant or not depending on the subject