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 computer solution | Comment 3 of 17 |

Part A actually has three solutions, found by adding on digits left to right and stopping if a number already accounted for in a digit is exceeded, andthen backtracking and going forward again.  If the 9th digit is set, then check the whole thing:

 5  3  3  2  1  1  0  0  0
 5  4  2  1  2  1  0  0  0
 7  4  0  1  1  0  1  1  0

found by

DECLARE SUB addOn ()
DEFDBL A-Z
CLEAR , , 9000
CLS

DIM SHARED ct(10), d(10), noDigs, tOfDigs, rejCt

noDigs = 0

addOn

END

SUB addOn
 max = 20 - tOfDigs
 IF max > 9 THEN max = 9
 FOR i = 0 TO max
  ' IF noDigs = 1 THEN PRINT i
  IF noDigs OR i THEN
   good = 1
   noDigs = noDigs + 1
   tOfDigs = tOfDigs + i
   d(noDigs) = i
   ct(i) = ct(i) + 1
   ct(i + 1) = ct(i + 1) + 1
   cts1 = ct(i)
   cts2 = ct(i + 1)
   IF i <= noDigs THEN
    IF cts1 > d(i) AND i > 0 THEN
     good = 0
    END IF
   END IF
   IF i + 1 <= noDigs THEN
    IF cts2 > d(i + 1) THEN
     good = 0
    END IF
   END IF

   IF good THEN
    IF noDigs = 9 THEN
     FOR j = 1 TO 9
      IF d(j) <> ct(j) THEN good = 0
     NEXT
     IF good THEN
      FOR j = 1 TO 9
       PRINT d(j);
      NEXT
      PRINT
     END IF
    ELSE
     IF tOfDigs < 18 THEN
      addOn
     END IF
    
    END IF
   END IF
   noDigs = noDigs - 1
   tOfDigs = tOfDigs - i
   ct(i) = ct(i) - 1
   ct(i + 1) = ct(i + 1) - 1
  END IF
 NEXT
END SUB

A similar program works for part 2:

DECLARE SUB addOn ()
DEFDBL A-Z
CLEAR , , 9000
CLS

DIM SHARED ct(11), d(11), noDigs, tOfDigs, rejCt

noDigs = 0

addOn


END

SUB addOn
 max = 20 - tOfDigs
 IF max > 9 THEN max = 9
 FOR i = 0 TO max
  ' IF noDigs = 1 THEN PRINT i
  IF noDigs OR i THEN
   good = 1
   noDigs = noDigs + 1
   tOfDigs = tOfDigs + i
   d(noDigs) = i
   SELECT CASE i
    CASE 0
     ia = 10
     ib = 1
    CASE 9
     ia = 9
     ib = 10
    CASE ELSE
     ia = i
     ib = i + 1
   END SELECT
   ct(ia) = ct(ia) + 1
   ct(ib) = ct(ib) + 1
   cts1 = ct(ia)
   cts2 = ct(ib)
   IF ia <= noDigs THEN
    IF cts1 > d(ia) AND ia > 0 THEN
     good = 0
    END IF
   END IF
   IF ib <= noDigs THEN
    IF cts2 > d(ib) THEN
     good = 0
    END IF
   END IF


   IF good THEN
    IF noDigs = 10 THEN
     FOR j = 1 TO 10
      IF d(j) <> ct(j) THEN good = 0
     NEXT
     IF good THEN
      FOR j = 1 TO 10
       PRINT d(j);
      NEXT
      PRINT
     END IF
    ELSE
     IF tOfDigs < 18 THEN
      addOn
     END IF
    
    END IF
   END IF
   noDigs = noDigs - 1
   tOfDigs = tOfDigs - i
   ct(ia) = ct(ia) - 1
   ct(ib) = ct(ib) - 1
  END IF
 NEXT
END SUB

giving

 4  2  2  4  4  0  0  0  0  4


  Posted by Charlie on 2005-09-23 19:44:37
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 (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

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