Congratulations, you’re now the drummer in my band. Unfortunately, we don’t have any drums, so you’ll have to make due by snapping your fingers. Your first task, as my newly appointed drummer, is to play a steady beat with your left hand while I lay down some tasty licks on lead guitar.

Great! Now let’s add some spice to this dish. In the span of time it takes you to snap three times with your left hand, I want you to lay down five evenly spaced snaps with your right. You probably already know this as the drummer in our band, but this is called a polyrhythm.

Sound easy? Cool, give it a try!

Hmm, I guess being a drummer is harder than I thought. Let’s take a different approach. This time, just start counting up from one. Every time you land on a number divisible by three, snap your left hand. Every time you land on a number divisible by five, snap your right hand. If you land on a number divisible by both three and five, snap both hands.

Go!

You’ll notice that fifteen is the first number we hit that requires we snap both hands. After that, the snapping pattern repeats. Congratulations, you don’t even have that much to memorize!

Here, maybe it’ll help if I draw things out for you. Every character represents a tick of our count. "ı" represents a snap of our left hand, ":" represents a snap of our right hand, and "i" represents a snap of both hands simultaneously.

But man, I don’t want to have to manually draw out a new chart for you every time I come up with a sick new beat. Let’s write some code that does it for us!


_.chain(_.range(1, 15 + 1))
    .map(i => {
        if (i % 3 === 0 && i % 5 === 0) {
            return "i";
        } else if (i % 3 === 0) {
            return "ı";
        } else if (i % 5 === 0) {
            return ":";
        } else {
            return ".";
        }
    })
    .join("")
    .value();

Here’s the printout for the “three against five” polyrhythm I need you to play:

..ı.:ı..ı:.ı..i

But wait, this looks familiar. It’s FizzBuzz! Instead of printing "Fizz" for our multiples of three, we’re printing "i", and instead of printing "Buzz" for our multiples of five, we’re printing "ı".

FizzBuzz is just a three against five polyrhythm.

We could even generalize our code to produce charts for any kind of polyrhythm:


const polyrhythm = (pulse, counterpulse) =>
    _.chain(_.range(1, pulse * counterpulse + 1))
    .map(i => {
            if (i % pulse === 0 && i % counterpulse === 0) {
                return "i";
            } else if (i % pulse === 0) {
                return "ı";
            } else if (i % counterpulse === 0) {
                return ":";
            } else {
                return ".";
            }
        })
        .join("")
        .value();

And while we’re at it, we could drop this into a React project and create a little tool that does all the hard work for us:

Anyways, we should get back to work. We have a Junior Developer interview lined up for this afternoon. Maybe we should have them play us a polyrhythm to gauge their programming abilities?