Here we go again! This time, we are going to be working on Pairwise. This is a tough one for beginners, but do not worry, let’s go slow and get this beast under control and understand […]
FCC Bonfire Series 140: Map the Debris
Today’s bonfire, once again, will have us deal with objects. This time, in Map the Debris, we must write a function that, given an array of elements (satellites) and their average altitudes, must return their […]
FCC Bonfire Series 135: Steamroller
This time, I bring a few solutions for the Steamroller bonfire. This guy has been a problem for many campers before, as it deals with recursion, a concept that may take some time to understand properly. […]
FCC Bonfire Series 134: Drop it
I come in with a short one today, similar to the last bonfire, Drop it will have use dealing with arrays and truth tests. This time, we need to drop elements of an array passed in as the […]
FCC Bonfire Series 132: Smallest Common Multiple
Math goodness for everyone today! We are going to be calculating the Smallest (or Least, or Lowest) Common Multiple of a range of numbers, as prompted by the Smallest Common Multiple bonfire. In mathematics, the least common multiple is the smallest positive number that is a multiple of two or more numbers (source).
As an example, take numbers 5 and 11. What is the smallest number divisible by the two? Let’s get the multiples of each and find out!
- Multiples of 5: 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65…
- Multiples of 11: 11, 22, 33, 44, 55, 66, 77, 88, 99…
As you can see, the first match we come across is number 55, that number is the least common multiple. We could try and use fancy math formulas to get it, but we are going to take advantage of our dear friend, the processor to take on the workload this time (at first). Today, I shall present you three different ways to achieve the same goal. One of them will be a more readable, short version, the second will be a little messy, but takes about half the time to come up with a solution. And the third will use some clever math and come up with the answer much faster! Interested? Let’s get to it.