title: Count Natural Numbers Whose Permutation Greater Number
signature: count_natural_numbers_whose_permutation_greater_number <- function(n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          69L, 
          48L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          72L, 
          48L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          88L, 
          52L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          7L, 
          7L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          66L, 
          45L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          34L, 
          28L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          23L, 
          20L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          37L, 
          31L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          33L, 
          27L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          21L, 
          18L
      )))
  
  }
  
  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;
  }