The self descriptive number

I have a ten-digit number. The first digit tells me how many zeros are in the number. The second digit tells me how many ones are in the number. The third digit tells me how many twos are in the number, and so on, until the tenth digit which tells me how many nines are in the number.

What is my number?


Bonus: Are there more solutions or is it a unique solution?


The answer is 6210001000.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Andy Hayes
Dec 10, 2017

Suppose that the leftmost digit is 9. Then the rightmost digit must be 1. But then there are not enough digits left for 9 0s, a contradiction.

9 0 0 0 0 0 0 0 0 Not enough digits for 9 0s 1 \underline{9} \ \underbrace{\underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}}}_{\text{Not enough digits for 9 0s}} \ \underline{1}

Now suppose that the leftmost digit is 8. Then the second to last digit must be 1. Then, the second from the left digit must be at least 1. But then there are not enough digits left for 8 0s, a contradiction.

8 1 0 0 0 0 0 0 1 0 Not enough digits for 8 0s \underbrace{\underline{8} \ \underline{1} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{1} \underline{\hphantom{0}}}_{\text{Not enough digits for 8 0s}}

Now suppose that the leftmost digit is 7. Then the third to last digit must be 1. Now we can resolve 2s and 1s by placing a 2 in the second digit and a 1 in the third digit. But then there are not enough digits left for 7 0s, a contradiction.

7 2 1 0 0 0 0 1 0 0 Not enough digits for 7 0s \underbrace{\underline{7} \ \underline{2} \ \underline{1} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}} \ \underline{1} \ \underline{\hphantom{0}} \ \underline{\hphantom{0}}}_{\text{Not enough digits for 7 0s}}

Now suppose that the leftmost digit is 6. Then the fourth to last digit must be 1. Now we can resolve 2s and 1s by placing a 2 in the second digit and a 1 in the third digit. And this works! There are exactly enough digits left to place the 6 0s.

6 2 1 0 0 0 1 0 0 0 \underline{6} \ \underline{2} \ \underline{1} \ \underline{0} \ \underline{0} \ \underline{0} \ \underline{1} \ \underline{0} \ \underline{0} \ \underline{0}

Hunter Edwards
Nov 10, 2017

C# is a great medium for problems like these. Here's my solution:

using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO;

namespace SelfDescribingNumbers { class Program { static void Main(string[] args) { StreamReader mystreamreader = new StreamReader(args[0]); List<string> LinesFromFile = new List<string>(); string LinesFromTheFile = null;

        LinesFromTheFile = ReadLinesFromFile(mystreamreader, LinesFromFile, LinesFromTheFile);

        foreach (string myline in LinesFromFile)
        {
            string mytrimline = myline.Trim();
            int[] array_converted_line = new int[mytrimline.Length];
            array_converted_line = ConvertStringToArray(mytrimline);

            if (the_number_is_self_describing(array_converted_line))
            {
                Console.WriteLine('1');
            }
            else
            {
                Console.WriteLine('0');
            }
        }

        Console.ReadLine();
    }

    private static bool the_number_is_self_describing(int[] d)
    {
        int number_of_elements = d.Length;
        bool is_self_describing_number = true;

        if (number_of_elements == 1)
        {
            if (d[0] == 0)
                return false;
            else
                return true;
        }
        else
        {
            for (int i = 0; i < number_of_elements; i++)
            {
                if (card_of_digit_in_array(d, i) != d[i])
                {
                    return false;
                }
            }
        }

        return is_self_describing_number;
    }

    public static int card_of_digit_in_array(int[] thearray, int x)
    {
        int counter = 0;
        foreach (int i in thearray)
        {
            if (i == x)
            {
                counter++;
            }
        }

        return counter;
    }

    private static int[] ConvertStringToArray(string line)
    {
        int[] toreturn = line.Select(n => (int)Char.GetNumericValue(n)).ToArray();
        return toreturn;
    }

    private static string ReadLinesFromFile(StreamReader reader, List<string> LinesFromFile, string linefromfile)
    {
        using (reader)
        {
            linefromfile = reader.ReadLine();

            while (linefromfile != null)
            {
                LinesFromFile.Add(linefromfile);
                linefromfile = reader.ReadLine();
            }
        }
        return linefromfile;
    }
}

}

Last Sword
Dec 10, 2017

I think 6210001000 is a unique solution, you cannot have 6++ zeros because of self contradictory, if you reduce the zero then you must add a number, which is not possible because there is none that will counter them.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...