top of page

Self-Describing Numbers

 

Self-describing numbers may be hard to understand, so even though my JS program is small, I have decided to give it its own page. First, here's a riddle: what is the next number in the following sequence?

 

1

11

21

1112

3112

211213

?????????

 

This is quite tough for most people, especially those who are mathemtically-minded. The next number is 312213. Each number in the sequence actually "describes" the number before it. So, let us begin with the number one (1). This number has a single one, or "one one" (11). 11, then has two ones (21), which has a one and a two (one one, one two or 1112). I became interested in this pattern, and decided to check it out a bit more.

 

...

312213

212223

114213

31121314

41122314

31221324

21322314

21322314

 

You might notice that the last two numbers are identical. This is no mistake. The number 21322314 actually describes itself; it has two ones, three twos, one three, and one four. I became interested in this property, and, using JavaScript and HTML, I created a program that allows the user to generate a number that describes the input in the text box. The "Find Self-Describing Number" button runs the code through a loop, and once the number starts to repeat, it displays the self-describing number.

bottom of page