title: Count Natural Numbers Whose Permutation Greater Number
signature: function countNaturalNumbersWhosePermutationGreaterNumber($n) {
test_code: <?php
  
  
  // SOLUTION CODE 
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function validateSolution($actual, $expected){
      return serialize($actual) == serialize($expected);
  }
  
  function driver($n, $expected){
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME($n), $expected)){
          return "PASSED";
        }
        return "FAILED";
      }
      catch (Exception $exception_obj) {
        return get_class($exception_obj);
      }
  }
  
  function main(){
      printf("TEST-0...%s\n",driver(
        69, 
        48));
      
      printf("TEST-1...%s\n",driver(
        72, 
        48));
      
      printf("TEST-2...%s\n",driver(
        88, 
        52));
      
      printf("TEST-3...%s\n",driver(
        7, 
        7));
      
      printf("TEST-4...%s\n",driver(
        66, 
        45));
      
      printf("TEST-5...%s\n",driver(
        34, 
        28));
      
      printf("TEST-6...%s\n",driver(
        23, 
        20));
      
      printf("TEST-7...%s\n",driver(
        37, 
        31));
      
      printf("TEST-8...%s\n",driver(
        33, 
        27));
      
      printf("TEST-9...%s\n",driver(
        21, 
        18));
      
  }
  
  main();
  ?>
source_py: def count_natural_numbers_whose_permutation_greater_number(n):
      result = 0
      for i in range(1, 10):
          s = []
          if (i <= n):
              s.append(i)
              result += 1
          while (len(s) != 0):
              tp = s[(- 1)]
              s.pop()
              for j in range((tp % 10), 10):
                  x = ((tp * 10) + j)
                  if (x <= n):
                      s.append(x)
                      result += 1
      return result
source_cpp: int count_natural_numbers_whose_permutation_greater_number(int n) {
    int result = 0;
    for ( int i = 1;
    i <= 9;
    i ++ ) {
      stack < int > s;
      if ( i <= n ) {
        s . push ( i );
        result ++;
      }
      while ( ! s . empty ( ) ) {
        int tp = s . top ( );
        s . pop ( );
        for ( int j = tp % 10;
        j <= 9;
        j ++ ) {
          int x = tp * 10 + j;
          if ( x <= n ) {
            s . push ( x );
            result ++;
          }
        }
      }
    }
    return result;
  }