14233221 is the self-summarizing number to which the sequence 1, 11, 21, 1211, 1231, ... stabilizes. The sequence is similar to, but not quite the same as the Audioactive Sequence, and it does not have any name that I know of. The only times I have encountered it have been in the form of a brain teaser like this:1

Given the sequence
  • 1
  • 11
  • 21
  • 1211
  • 1231
  • 131221
  • ...
what is the next number in the sequence? What is the last number in the sequence?

The trick to this brain teaser is that every number after the first is just a summary of the digits of the previous number, as you would read them, high to low. So,

  • 1
  • one 1 -> 11
  • two 1s -> 21
  • one 2, one 1 -> 1211
  • one 2, three 1s -> 1231
  • one 3, one 2, two 1s -> 131221
  • ... and so on and so forth until you get to the last number, which repeats ad infinitum:
  • one 4, two 3s, three 2s, two 1s -> 14233221

Interestingly (or uninterestingly), the entire sequence has just 13 unique terms: 1, 11, 21, 1211, 1231, 131221, 132231, 232221, 134211, 14131231, 14231241, 24132231, 14233221, 14233221, ...

and just for fun, here's some C that solves the problem:

#include <stdio.h>
#include <stdlib.h>

unsigned nextnum(unsigned k)
{
    unsigned breakout[10];
    unsigned i;
    for(i=0; i < 10; i++)
        breakout[i]=0;

    while(k > 0)
    {
        breakout[k%10]++;
        k /= 10;
    }

    for(i=9; i > 0; i--)
        if (breakout[i]>0)
            k = k*100 + 10*breakout[i] + i;

    return k;
}

int main(int argc, char** argv)
{
    unsigned x = 1;
    unsigned i;
    unsigned max = argc > 1 ? atoi(argv[1]) : 14;
    
    printf("iteration %2i: %8i\n", 0, x);
    for(i=1; i < max; i++)
    {
        x = nextnum(x);
        printf("iteration %2i: %8i\n", i, x);
    }
    
    return 0;
}

1 This node was originally the answer to that brain teaser as written by Hermetic in A nice, hard brain teaser... which has since expired, leaving me looking like a bit of a fool.

Log in or register to write something here or to contact authors.