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.)
Another computer program | Comment 13 of 19 |

It seems I've joined the dark side...

 

I'm taking a java class and this looked like it might be fun to write a program for.  I only just started, so you won't see any fancy stuff.  The only efficiency you'll see here is not execution time efficiency, but typing time efficiency.

I decided it would be more fun if instead of letting the program run and automatically getting the answer, I let the user participate a little.  Namely, the user chooses which of the ten digits to recalculate at each step.  I could probably add a few lines and let the computer do that for me, but that would be boring.  I'm sure that not much change is required to adjust to finding the nine digit number.

Program:

// Test1.java
// Finds a self-referential number, with the user's help
// Tristan, 9-21-05
// java packages
import javax.swing.JOptionPane;
public class Test1
   { 
   // main method begins execution of Java application
   public static void main( String args[] )
   {
   String choice = ""; // user's choice number
  
   int n01 = 0; // number of 0s and 1s
   int n12 = 0; // number of 1s and 2s
   int n23 = 0; // etc.
   int n34 = 0;
   int n45 = 0;
   int n56 = 0;
   int n67 = 0;
   int n78 = 0;
   int n89 = 0;
   int n90 = 0;
  
   int counter = 0; // counts the number of, for example 0s and 1s
   int ch = 0; // user's choice number 
  
   do
      {
      choice = JOptionPane.showInputDialog( n01 + ", " + n12 + ", "
+ n23 + ", " + n34 + ", " + n45 + ", " + n56 + ", " + n67 +
", " + n78 + ", " + n89 + ", " + n90 +
"
Type out which number you wish to change, or type 0 to quit" );
// read in choice
      ch = Integer.parseInt( choice ); // convert choice to int
     
      counter = 0; // reset counter
     
      // start counting
      if ( n01 == ch % 10 || n01 == ch - 1 )
         counter++;
      if ( n12 == ch % 10 || n12 == ch - 1 )
         counter++;
      if ( n23 == ch % 10 || n23 == ch - 1 )
         counter++;
      if ( n34 == ch % 10 || n34 == ch - 1 )
         counter++;
      if ( n45 == ch % 10 || n45 == ch - 1 )
         counter++;
      if ( n56 == ch % 10 || n56 == ch - 1 )
         counter++;
      if ( n67 == ch % 10 || n67 == ch - 1 )
         counter++;
      if ( n78 == ch % 10 || n78 == ch - 1 )
         counter++;
      if ( n89 == ch % 10 || n89 == ch - 1 )
         counter++;
      if ( n90 == ch % 10 || n90 == ch - 1 )
         counter++;
     
      // store the total into the appropriate number
      if ( ch == 1 )
         n01 = counter;
      if ( ch == 2 )
         n12 = counter;
      if ( ch == 3 )
         n23 = counter;
      if ( ch == 4 )
         n34 = counter;
      if ( ch == 5 )
         n45 = counter;
      if ( ch == 6 )
         n56 = counter;
      if ( ch == 7 )
         n67 = counter;
      if ( ch == 8 )
         n78 = counter;
      if ( ch == 9 )
         n89 = counter;
      if ( ch == 10 )
         n90 = counter;
     
      } while( ch != 0 );
     
   System.exit( 0 ); // exit application with window
     
   } // end method main
 
 
 
   } //end class Test1

Edit:
After trying this program, I really like it!  It turns the puzzle into a sort of maze, and the maze is not as easy to solve as one might expect.  I could do this by hand instead, but this is so much faster and more fun.

Edited on September 24, 2005, 9:29 pm
  Posted by Tristan on 2005-09-24 21:13:16

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