Problem Solving

Typically when I tell people that I used to be a pastry chef the reaction is somewhere along the lines of, "How amazing! That sounds so fun!" They picture the instagram version of a pastry chef- all cupcakes and sprinkles and rainbows. Claire smiling and holding a dessert, all cupcakes sprinkles and rainbows

And it is! ...Some of the time. What you don't see on Instagram are the 75 hour weeks, the spreadsheets (I actually adore google sheets, but that's a topic for another blog), the planning and the endless plans for when the plan doesn't work out. Check out these scenes from a day in the life of a pastry chef...

First, I bring you, "That time the walk-in freezer broke on a 100° day."

I was managing an ice cream factory for one of the most successful companies in Denver. When there's a line down the block in the middle of June and you have hundreds of gallons of still-soft, just-spun ice cream in the freezer is not when you want your freezer to crap out. My team and I had noticed the temperature of the freezer creeping up for a couple hours, but thought that maybe it was just running a defrost cycle as it regularly did, or that all of our ins and outs had pushed the temperature up, so we kept an eye on it and continued spinning ice cream.
IMG_0401.JPG

IMG_0398.JPG

When it became abundantly clear that the freezer was not simply defrosting, a hundred decisions flew into motion and "Operation Save the Ice Cream" began. Luckily, the company I worked for was in the middle of moving to an upgraded factory and we had access to a larger freezer space. However, as it turned out, our freezer truck to transport the soft ice cream across town was also on the fritz. It is basically impossible to rent a freezer truck, as I found out, but our Area Manager did manage to secure something and bring it over. We loaded up as much of the (woefully soft) ice cream as we could and drove it across town. And when we got there? SOUP. I'll spare you the details of the rest of our plan but no one is repairing walk in freezers on a Saturday afternoon so our problem solving ultimately turned into three very sad people figuring out how to dispose of hundreds of gallons of soupy ice cream that mostly couldn't be salvaged due to the mix-ins in it. (Spoiler alert, blending a sink-full of melted ice cream soup to try and get brownie chunks to go down the drain doesn't work... we ended up bagging most of it up and throwing it out.)

As a second example, let me bring you, "The Great Freezer Flood of 2019."

This happened a year after we had moved into our shiny new production factory with a huge, fully functional, and redundantly powered freezer. Some July rain began innocently enough then turned quickly into a flash-flood level torrential downpour. The freezer had a big door that opened out onto the alley loading area and about 20 feet away and 2 feet down a slope was a storm drain. We saw the water level rising and slogged out into the alley attempting to unclog the drain, but the few sticks we moved away were nothing compared to the amount of water gushing down the alley.

Retreating back inside with soaked shoes and socks, I will never forget the Jurassic-Park-esque moment that was opening the freezer door and seeing a thick fog hovering in the air above the 3 inches of water that filled the ENTIRE 800 sq ft freezer. Now I'm not sure if you've done the math on all the various reasons that this scenario outright sucks yet, so let me tell you that this freezer, with it's concrete floor and area rugs, was set to -20 degrees F so when the rain finally slowed and the whole team had managed to squeegie, sweep, and shovel most water out of the freezer and drag out the waterlogged rugs, what water was left froze instantly on the floor turning a freezer stocked to the brim with ice cream into an ice rink.

New problem, new solution.

IMG_1359.jpeg

IMG_1360.jpeg

Horror stories aside, I love problem solving. Having the opportunity to solve complex problems daily is one of the main reasons I am entering the field of software development! Though hopefully my future problems will involve a few less freezer-related catastrophes 😅

Today we had some minimally structured time to read and discuss this article about how to become better problem solvers. What I appreciated most about this article was the emphasis on taking the time to understand the problem before diving into code. I am certainly guilty of not reading and understanding directions fully before tackling a problem.

We were then given a short technical challenge to complete:

// Given five positive integers, 
// find the minimum and maximum values 
// that can be calculated by summing 
// exactly four of the five integers.
// Then print the respective minimum
// and maximum values as a single line
// of two space-separated long integers.

// For example, [1, 3, 5, 7, 9]. 
// Our minimum sum is 1 + 3 + 5 + 7 = 16 
// and our maximum sum is 3 + 5 + 7 + 9 = 24
// We would return: [16, 24]

const getMiniMaxSum = numbers => {
  // Your code here
  return numbers;
};

getMiniMaxSum([1, 3, 5, 7, 9]);

Having written both recipes and standard operating procedures in the path, the process of pseudo-coding is fairly intuitive to me. I like to write a little bit, then write a little bit of code, then go back to my pseudo-code, etc. Here are my notes from the 20 or so minutes it took me to solve this problem, beginning with a re-wording of the prompt and some initial thoughts:

// we have a function: getMiniMaxSum that takes in a parameter
// the parameter is an array of 5 numbers
// we are going to sum 4 of the 5 numbers
// we are going to return an array of 2 numbers, the min and the max

// 1. sort the numbers min-max, if they are not sorted already
// 2. create an empty array to store the results
// 3. get the min first by adding the first 4 nums in our sorted array, push to nums
// 4. get the max next by adding the last 4 nums in our sorted array, push to nums
// 5. return the array

// start with a console log of numbers just to double check data/shape
// start with a reduce to find the min value
// got 25 several times, played with the conditional, then did some 
//console logging of counter and realized that I had the counter inside 
//the reduce so its value was 0 every time. moved it outside and got 16 right away.

// max: set up a reduce again, console logged the counter and saw that it was 4, this makes sense. 
//maybe i need 2 counters? no that seems very messy, can I leverage the one I have already?
// maybe it's better to give the reduce a new array of nums instead of all 5?
// slice? (look it up, it's one I always forget, slice(1) should do the trick)

You can see that I struggled a bit with something silly (the placement of the counter inside the reduce), and that it took me a minute to figure out max until I remembered about my good friend slice.

Something else I appreciated from the problem solving article above was that sometimes in this kind of technical challenge it's more important to get a working solution than to have the prettiest code right away. My solution is below, I'd love to hear how you might refactor it or would have approached this in the first place! I initially pushed min and max into the array of nums but thought it was slightly cleaner to move them inside the brackets like I did here. Once I remembered about slice, I could have used it on the min numbers as well, which would have saved a couple lines.

const getMiniMaxSum = numbers => {
  let counter = 0

  const min = numbers.reduce((acc, num) => {
    if (counter < 4 ) {
      counter++
      acc += num
    }
    return acc
  }, 0)

  const max = numbers.slice(1).reduce((acc, num) => {
    acc += num
    return acc
  }, 0)

  const nums = [min, max]
  return nums;
};

getMiniMaxSum([1, 3, 5, 7, 9]);