title: Count Natural Numbers Whose Permutation Greater Number
signature: func countNaturalNumbersWhosePermutationGreaterNumber(n int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(n int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(n),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver(69, 48)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(72, 48)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(88, 52)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(7, 7)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(66, 45)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(34, 28)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(23, 20)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(37, 31)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(33, 27)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(21, 18)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
  }