Floor to Ceiling

Yesterday I posed a simple (ish) question on twitter:

“What is the nth term of the following sequence:

2, 20, 202, 2020, 20202, 202020, …?”

I love the question for a number of reasons that i’ll discuss here.

Firstly, on the surface it’s a really simple sequence. It’s very easy to describe it in English.

“Start with a two, then add a zero, then a two, then a zero, …”

Or, if you want to get a little more specific:

“follow the recurring sequence 202020 with n digits”

So far so good. But this is a great example of how something can use very few words as an easy instruction in English, but be arguably much more difficult to translate into mathematics.

Often it’s the other way around.

Consider the formula below:

2n2 + 7

Simple to write in mathematics, and say as “2 n squared plus 7”

but to describe it to someone less familiar with the terminology we’d say “take n, multiply it by itself, then multiply it by two, then add seven”.

In this case the mathematics is much simpler than the spoken English, if you’re fluent in both.

But how do we write mathematically :

“follow the recursive sequence 202020… with n digits”

You’d think it’d be straight forward… well, it depends on what tools you have at your disposal.

An initial approach

I began by ‘seeing’ the pattern 2, 20, 202, 2020, 20202, … as


2 x 10

2 x 100 + 2

2 x 1000 + 2 x 10

2 x 10000 + 2 x 100 + 2

(spoiler: there are better ways to see this pattern!)

Or, written utilising ‘n’:

inf series 1

This felt like progress. The pattern utilised ‘n’ and generated the sequence, but it’s not a neat ‘nth term’ just yet.

The issue I had now though was that the pattern wasn’t quite consistent enough with the tools I wanted to use. How could I define that if n is even, just do the thing you did for the term before, but if n is odd, you do one more thing? How do I tell the sequence when to stop? If n is odd then I stop at 2 x 10n-n but if n is even, then I stop at 2 x 10n-n+1

At this point I thought maybe I needed two nth terms, one for if n is odd, and one for if n is even. That wasn’t very satisfying though. Surely I could just merge the two things together…

I should probably have just decided to take an entirely different approach, but I was in it to win it now (or… lose ultimately).

Note:  on twitter, various incarnations of the above had begun to surface as others were also punching holes in this problem. I had a few people write solutions literally in words, with clauses for odd and even, and many others had latched onto variations of the 2 x 10n idea.

So, even though it felt messy, maybe this was just destined to be a messy nth term. I struggled on.

As I was continually adding things onto the sequence, I figured I’d need sigma. But how exactly would I use it to incorporate all the little clauses that were rearing their ugly heads?

sigma 1

Something like this maybe?

It should be noted that sigma is in my tool box. For a lot of people it might not be. Hence it’s a good time to mention that problems like these are great for reaching a point where you say ‘hang on, I think I need a new tool… is there a tool that does…”

I know there are some teachers who teach students along these lines, exploring a tool until you’ve exhausted it and discovered you *need* a new one, rather than just being given it.

I realised after a bit of thought that, using this model that I was kind of now blindly following because I’d invested in it, I’d need a second variable (maybe I don’t need it, but I decided I did). So I came up with this:

sigma 2

I felt like I was closer, and I was (barely) pleased that I was somehow managing to incorporate everything into one formula, rather than having an odd and an even… alas there were a few issues. Firstly, it doesn’t work for n=1. Secondly, it kind of scrappily works for n=2 (I think…), thirdly it doesn’t work at all once “n-2x+1” results in a negative number. I thought I could fix that last part with yet another clause:


But now it was scrappier than hell, and it still doesn’t really work, and I’m not convinced it’s even an ‘ok’ thing to do… I was basically laying out a flow diagram into a messy, erroneous blurg.

Time to change my approach and start over again. I felt like I’d hit a wall.

In the back of my mind when I noticed that odd and even ‘n’ seemed to need different rules, I imagined I’d possibly need to use either the ceiling or floor functions. Again, these are tools I’ve needed in the past, but may be unknown to many. ‘Floor’ rounds anything down to the nearest integer, and ‘ceiling’ rounds anything up to the nearest integer. They’re useful for many reasons, but it felt like they might be useful here to use some kind of division when ‘n’ is odd to get something more workable. Indeed, here is a submission from someone on twitter using the ceiling function:


(It’s used for n/2).

Anyway, I left it alone for an hour or two, but it was on my mind. Then it struck me that 0.202020202020… is just 20/99. I hadn’t even been thinking at all along those lines. I’d got too obsessed with picturing each output as the sum of separate parts.

The rest fell into place very quickly.

floor soln2

hence the nth term is “simply”:

floor soln

I feel embarrassed to have even pursued the first line of enquiry (probably just a symptom of maths anxiety), which is silly because that’s what we all do: chase an idea until it stops working. I could probably have made it work eventually, but it would have been a mess. Below are some of the other solutions and almost solutions that people posted in answer to the tweet: