# Splitting headaches into Solutions

## Theory

In the face of massive problems like, “I need to pay back $30,000 of this debt” or “I have this massive project above my head at work”, it’s very easy to get **overwhelmed**. Most of us will do what makes the most sense, nothing at all. And that’s okay! But most of the time, this leaves us feeling depressed and dejected. What can we do to solve these massive problems? This post will discuss using a method used in Computer Science called Divide and Conquer. This helps us get the solutions we want.

The divide and conquer algorithm is pretty straightforward. All we’ll want to do is split our problem into smaller and smaller subproblems until we get to the easiest subproblems possible. Ideally, the smallest subproblems solve themselves. Divide and Conquer is like Thanksgiving dinner. Your plate is overflowing with food, and there’s no way you could eat all of it in one go! But if you take one bite at a time, you can move *towards* completion. Let’s look at the example above: “$30,000 in debt”. This is a huge problem, and oft times, it’s even scary to think about! Let’s see how we can divide this problem into more manageable chunks.

## Example

**$30,000 in student loan debt**- Monthly payments: ~$300/month for 10 years
- Principal: ~$220/month * Interest: ~$80/month
- 3 different loans with 3 different APR%
- Find the loan with the highest inetrest rate
- Loan 1: $10,000 at 8% (This loan is our highest priority)
- Put our $300 a month towards this loan
- Calculate payoff time
- ($10,000 * 1.08%) / $300 = 36 months to pay off entirely
- Write down each month on paper with how much you’ll pay
**Find a pencil and paper**- $300 / 30 (~days in a month) = ~
**$10 / day**

- Build a budget
- Write down expenses on paper that you know happen each month (like rent and other bills)
- Take a pencil and write down what you bought
**today** **Think about what you can live without tomorrow or find a cheaper alternative**

- Loan 2: $10,000 at 5%
- Loan 3: $10,000 at 3%

- Loan 1: $10,000 at 8% (This loan is our highest priority)

As you can see above, we broke this problem into manageable chunks (the bold ones)! We prioritized our loans into categories, and split our monthly payments into daily payments of $10. This does a few things for us.

- The problems now feel achievable – $10 is an amount of money that’s not
*terrifying*to think about - Setting our mindset – We’re now problem
**solvers**, no longer victim to huge problems - Inspires us to do more – we know that $10 a day is what we need, imagine if we could up that to $15 with budgeting! Snowball effect!

## Code

This code in JavaScript that symbolizes the divide and conquer theory. Just like above, it basically helps us find manageable ways to solve our problems. You can divide and conquer on paper, but doing it with code is *kinda the point of this blog 😉*. Also, when written with code, we get to keep old problems around and organize new ones. We also get to mix and match.

### Principles

The code today is pretty straightforward. We’ll be using the Object Oriented class model. JavaScript doesn’t actually have classes, but in ES6, classes we’re added as a syntax sugar.

Here’s the full example:

This could be extended out a lot, as this is just the basic structure. We could:

- Make a webpage to visually add and remove problems
- Return a list of all the unsolved problems we have, sorted by difficulty
- Add a reward system to our code, giving us positive incentives to complete tasks

I hope this inspired you to go out and look at your problems differently. Take that first step!