Program to save number list in txt file ( 000000 to 606060 )

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Okay boys and girls (?). Here it is, I worked on the assumption that a combination lock will always have the same numbers available through all the sets.

PHP Code: [ Select ]
 
class combo_lock{
 
   var $max_number;  // numbers available on the combination
 
   var $number_sets; // number of sets containing the max_numbers
 
   var $filename;    // filename to output to
 
   
 
   function combo_lock(){
 
      $this->max_number = 0; // defualt assignments
 
      $this->number_sets   = 0;
 
      $this->filename      = "";
 
   }
 
   
 
   function start_unlock($echo){
 
      if (($this->max_number != 0) && ($this->number_sets != 0) && ($this->filename != "")) {
 
         $power_of   = pow($this->max_number,$this->number_sets); // get possible number of combinations
 
         $fh         = fopen($this->filename,"w");           // open file for writting
 
         $line_num   = 0;
 
         for ($i = 0; $i < $power_of; $i++){
 
            $v1   = $i % $this->max_number;
 
            for ($j = 1; $j <= $this->number_sets; $j++){
 
               $output[$j] = ($i / (pow($this->max_number,$j))) % $this->max_number;
 
            } // get combinations available at point i
 
            $output_str = $v1;
 
            for ($j = 1; $j < count($output);$j++){
 
               $output_str .= "-" . $output[$j];
 
            } // build output string
 
            $output_str .= "\n";
 
            $line_num++;
 
            if ($echo == 1) {
 
               echo "<b>" . $line_num . "</b>:" . $output_str . "<br />";  
 
            }
 
            fwrite($fh,$output_str);
 
         } // for loop though number of combinations
 
         fclose($fh);
 
         echo "Completed!" ;
 
      }else{
 
         die ("Please set the properties for the class");
 
      }
 
   }
 
   
 
}
 
 
 
 
 
// usage-----------------------------------------------------------------
 
$oLock   = new combo_lock();
 
$oLock->max_number   = 10;
 
$oLock->number_sets = 5;
 
$oLock->filename  = "combo_lock.txt";
 
$oLock->start_unlock(1); // 1 to echo the values (true)
 
 
  1.  
  2. class combo_lock{
  3.  
  4.    var $max_number;  // numbers available on the combination
  5.  
  6.    var $number_sets; // number of sets containing the max_numbers
  7.  
  8.    var $filename;    // filename to output to
  9.  
  10.    
  11.  
  12.    function combo_lock(){
  13.  
  14.       $this->max_number = 0; // defualt assignments
  15.  
  16.       $this->number_sets   = 0;
  17.  
  18.       $this->filename      = "";
  19.  
  20.    }
  21.  
  22.    
  23.  
  24.    function start_unlock($echo){
  25.  
  26.       if (($this->max_number != 0) && ($this->number_sets != 0) && ($this->filename != "")) {
  27.  
  28.          $power_of   = pow($this->max_number,$this->number_sets); // get possible number of combinations
  29.  
  30.          $fh         = fopen($this->filename,"w");           // open file for writting
  31.  
  32.          $line_num   = 0;
  33.  
  34.          for ($i = 0; $i < $power_of; $i++){
  35.  
  36.             $v1   = $i % $this->max_number;
  37.  
  38.             for ($j = 1; $j <= $this->number_sets; $j++){
  39.  
  40.                $output[$j] = ($i / (pow($this->max_number,$j))) % $this->max_number;
  41.  
  42.             } // get combinations available at point i
  43.  
  44.             $output_str = $v1;
  45.  
  46.             for ($j = 1; $j < count($output);$j++){
  47.  
  48.                $output_str .= "-" . $output[$j];
  49.  
  50.             } // build output string
  51.  
  52.             $output_str .= "\n";
  53.  
  54.             $line_num++;
  55.  
  56.             if ($echo == 1) {
  57.  
  58.                echo "<b>" . $line_num . "</b>:" . $output_str . "<br />";  
  59.  
  60.             }
  61.  
  62.             fwrite($fh,$output_str);
  63.  
  64.          } // for loop though number of combinations
  65.  
  66.          fclose($fh);
  67.  
  68.          echo "Completed!" ;
  69.  
  70.       }else{
  71.  
  72.          die ("Please set the properties for the class");
  73.  
  74.       }
  75.  
  76.    }
  77.  
  78.    
  79.  
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86. // usage-----------------------------------------------------------------
  87.  
  88. $oLock   = new combo_lock();
  89.  
  90. $oLock->max_number   = 10;
  91.  
  92. $oLock->number_sets = 5;
  93.  
  94. $oLock->filename  = "combo_lock.txt";
  95.  
  96. $oLock->start_unlock(1); // 1 to echo the values (true)
  97.  
  98.  


Well that was loads of fun! I wish Ozzu had a code challenge. Really nice to build these small things. Challenging
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Never got any feed back on this? Wondering if anyone had some ...

Post Information

  • Total Posts in this topic: 32 posts
  • Users browsing this forum: No registered users and 99 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.