title: Count Natural Numbers Whose Permutation Greater Number
signature: function count_natural_numbers_whose_permutation_greater_number(n)
test_code: using Printf
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  function validate_solution(actual, expected)
      return actual == expected
  end
  
  function driver(n, expected)
      try
  
          if validate_solution(PLACEHOLDER_FN_NAME(n), expected)
              return "PASSED";
          end
          return "FAILED";
      catch exception_obj
          return string(Base.typename(typeof(exception_obj)).wrapper);
      end
  end
  
  function main()
      
      result = driver(69, 48);
      @printf("TEST-0...%s\n",result);
      
      result = driver(72, 48);
      @printf("TEST-1...%s\n",result);
      
      result = driver(88, 52);
      @printf("TEST-2...%s\n",result);
      
      result = driver(7, 7);
      @printf("TEST-3...%s\n",result);
      
      result = driver(66, 45);
      @printf("TEST-4...%s\n",result);
      
      result = driver(34, 28);
      @printf("TEST-5...%s\n",result);
      
      result = driver(23, 20);
      @printf("TEST-6...%s\n",result);
      
      result = driver(37, 31);
      @printf("TEST-7...%s\n",result);
      
      result = driver(33, 27);
      @printf("TEST-8...%s\n",result);
      
      result = driver(21, 18);
      @printf("TEST-9...%s\n",result);
      
  end
  
  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;
  }