All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Self-Referential Numbers (Posted on 2005-09-23) Difficulty: 3 of 5
A nine digit number has the property where the first digit equals the number of zeros and ones used in the number, the second digit equals the number of ones and twos used in the number, the third digit equals the number of twos and threes used in the number, etc. through the ninth digit equals the number of eights and nines used in the number. What could the number be?

A ten digit number has a similar property to the nine digit number. The first digit equals the number of zeros and ones used in the number, the second digit equals the number of ones and twos used in the number, etc. through the ninth digit. And also, the tenth digit equals the number of zeros and nines used in the number. What could this number be?

See The Solution Submitted by Brian Smith    
Rating: 3.4000 (5 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution re: Computer program solution | Comment 6 of 19 |
(In reply to Computer program solution by Penny)

Penny, I liked your method--especially the insight that the sum of all the digits can't be more than 20; which helps optimize the cases you need to look at.

But, obsessive as I am, I had to try to see if I could improve the performance.  The following program, using basically your same method, runs on my machine in 28 seconds:

Option Strict On

Imports System.Math

Module Module1
    Dim i1 As Integer
    Dim i2 As Integer
    Dim i3 As Integer
    Dim i4 As Integer
    Dim i5 As Integer
    Dim i6 As Integer
    Dim i7 As Integer
    Dim i8 As Integer
    Dim i9 As Integer
    Dim i10 As Integer

    Sub main()
        Dim startTime As DateTime = Now
        For i1 = 0 To 9
            For i2 = 0 To 9
                For i3 = 0 To Min(9, 20 - i1 - i2)
                    For i4 = 0 To Min(9, 20 - i1 - i2 - i3)
                        For i5 = 0 To Min(9, 20 - i1 - i2 - i3 - i4)
                            For i6 = 0 To Min(9, 20 - i1 - i2 - i3 - i4 - i5)
                                For i7 = 0 To Min(9, 20 - i1 - i2 - i3 - i4 - i5 - i6)
                                    For i8 = 0 To Min(9, 20 - i1 - i2 - i3 - i4 - i5 - i6 - i7)
                                        For i9 = 0 To Min(9, 20 - i1 - i2 - i3 - i4 - i5 - i6 - i7 - i8)
                                            check9()
                                            For i10 = 0 To Min(9, 20 - i1 - i2 - i3 - i4 - i5 - i6 - i7 - i8 - i9)
                                                check10()
                                            Next
                                        Next
                                    Next
                                Next
                            Next
                        Next
                    Next
                Next
            Next
        Next
        Console.WriteLine()
        Console.WriteLine("Seconds elapsed: {0}", DateDiff(DateInterval.Second, startTime, Now))
        Console.ReadLine()
    End Sub

    Sub check9()
        Dim digits(10) As Integer
        digits(i1) += 1 : digits(i1 + 1) += 1
        digits(i2) += 1 : digits(i2 + 1) += 1
        digits(i3) += 1 : digits(i3 + 1) += 1
        digits(i4) += 1 : digits(i4 + 1) += 1
        digits(i5) += 1 : digits(i5 + 1) += 1
        digits(i6) += 1 : digits(i6 + 1) += 1
        digits(i7) += 1 : digits(i7 + 1) += 1
        digits(i8) += 1 : digits(i8 + 1) += 1
        digits(i9) += 1 : digits(i9 + 1) += 1
        If i1 <> digits(1) Then Return
        If i2 <> digits(2) Then Return
        If i3 <> digits(3) Then Return
        If i4 <> digits(4) Then Return
        If i5 <> digits(5) Then Return
        If i6 <> digits(6) Then Return
        If i7 <> digits(7) Then Return
        If i8 <> digits(8) Then Return
        If i9 <> digits(9) Then Return
        Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7} {8}", i1, i2, i3, i4, i5, i6, i7, i8, i9)
    End Sub

    Sub check10()
        Dim digits(11) As Integer
        digits(i1) += 1 : digits(i1 + 1) += 1
        digits(i2) += 1 : digits(i2 + 1) += 1
        digits(i3) += 1 : digits(i3 + 1) += 1
        digits(i4) += 1 : digits(i4 + 1) += 1
        digits(i5) += 1 : digits(i5 + 1) += 1
        digits(i6) += 1 : digits(i6 + 1) += 1
        digits(i7) += 1 : digits(i7 + 1) += 1
        digits(i8) += 1 : digits(i8 + 1) += 1
        digits(i9) += 1 : digits(i9 + 1) += 1
        digits(i10) += 1 : digits(i10 + 1) += 1
        digits(10) += digits(0) 'adds the count of 0's to the count of 9's.
        If i1 <> digits(1) Then Return
        If i2 <> digits(2) Then Return
        If i3 <> digits(3) Then Return
        If i4 <> digits(4) Then Return
        If i5 <> digits(5) Then Return
        If i6 <> digits(6) Then Return
        If i7 <> digits(7) Then Return
        If i8 <> digits(8) Then Return
        If i9 <> digits(9) Then Return
        If i10 <> digits(10) Then Return
        Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9}", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10)
    End Sub
End Module


  Posted by Ken Haley on 2005-09-24 06:31:59
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (2)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information