<awangdev>Permutation Sequence_1.java
public String getPermutation(int n, int k) {
        if (n <= 0 || k <= 0) {
            return "";
        }
        StringBuffer sb = new StringBuffer();
        boolean[] visited = new boolean[n];
        int factorio = 1;
        for (int i = 1; i < n; i++) {
            factorio *= i;
        }
        k = k - 1;

        for (int i = 0; i < n; i++) {
            int index = k / factorio;
            k = k % factorio;

            for (int j = 0; j < n; j++) {
                if (!visited[j]) {
                    if (index == 0) {
                        visited[j] = true;
                        sb.append((char)('0' + j + 1));
                        break;
                    } else {
                        index--;
                    }
                } 
            }

            if (i < n - 1) {
                factorio = factorio / (n - i - 1);
            }
        }

        return sb.toString();
    }
public String var_0 ( int var_1 , int var_2 ) {
  if ( var_1 <= 0 || var_2 <= 0 ) {
    return "" ;
  }
  StringBuffer var_6 = new StringBuffer ( ) ;
  boolean [ ] var_8 = new boolean [ var_1 ] ;
  int var_10 = 1 ;
  for ( int var_11 = 1 ;
  var_11 < var_1 ;
  var_11 ++ ) {
    var_10 *= var_11 ;
  }
  var_2 = var_2 - 1 ;
  for ( int var_11 = 0 ;
  var_11 < var_1 ;
  var_11 ++ ) {
    int var_12 = var_2 / var_10 ;
    var_2 = var_2 % var_10 ;
    for ( int var_13 = 0 ;
    var_13 < var_1 ;
    var_13 ++ ) {
      if ( ! var_8 [ var_13 ] ) {
        if ( var_12 == 0 ) {
          var_8 [ var_13 ] = true ;
          var_6 . append ( ( char ) ( '0' + var_13 + 1 ) ) ;
          break ;
        }
        else {
          var_12 -- ;
        }
      }
    }
    if ( var_11 < var_1 - 1 ) {
      var_10 = var_10 / ( var_1 - var_11 - 1 ) ;
    }
  }
  return var_6 . toString ( ) ;
}
