<commit_before>package ps

import (
	"strconv"
	"strings"
)

func getPermutation(n, k int) string {
	if n < 1 {
		return ""
	}
	nums := make([]int, n)
	for i := range nums {
		nums[i] = i + 1
	}
	res := make([]string, 0, k)
	genRes(&res, nums)

	// var sb strings.Builder
	// for i := 0; i < n; i++ {
	// 	sb.WriteString(strconv.Itoa(i))
	// }
	// src := sb.String()
	// res := make([]string, 0, k)
	// res = append(res, src)
	// permute(&res, "", 0, src)
	return res[k-1]
}

// just call nextPermutation k times
// src are monotonically increasing "123456...n"

func nextPermutation(nums []int) {
	i := len(nums) - 2
	for i >= 0 && nums[i+1] > nums[i] {
		i--
	}
	if i >= 0 {
		j := len(nums) - 1
		for j >= 0 && nums[j] < nums[i] {
			j--
		}
	}
}

// func nextPermutation(src string) string{
// 	n := len(src)
// 	i := n - 1
// 	for i >=0 && src[i-1] > src[i] {
// 		i--
// 	}
// 	if i > = 0 {
// 		j :=
// 	}
// }

func genRes(res *[]string, nums []int) {
	var st strings.Builder<commit_msg>user netxtPermutation to generate the kth permute<commit_after>package ps

import (
	"strconv"
	"strings"
)

func getPermutation(n, k int) string {
	if n < 1 {
		return ""
	}
	nums := make([]int, n)
	for i := range nums {
		nums[i] = i + 1
	}
	res := make([]string, 0, k)
	genRes(&res, nums)
	for j := 1; j < k; j++ {
		nextPermutation(nums)
		genRes(&res, nums)
	}

	// var sb strings.Builder
	// for i := 0; i < n; i++ {
	// 	sb.WriteString(strconv.Itoa(i))
	// }
	// src := sb.String()
	// res := make([]string, 0, k)
	// res = append(res, src)
	// permute(&res, "", 0, src)
	return res[k-1]
}

// just call nextPermutation k times
// src are monotonically increasing "123456...n"

func nextPermutation(nums []int) {
	i, j := len(nums)-2, len(nums)-1

	for i >= 0 && nums[i+1] < nums[i] {
		i--
	}
	if i >= 0 {
		for j >= 0 && nums[j] < nums[i] {
			j--
		}
	}
	// swap nums[i], nums[j]
	nums[i], nums[j] = nums[j], nums[i]
	reverse(nums, i+1, len(nums)-1)
}

func reverse(nums []int, left, right int) {
	for left < right {
		nums[left], nums[right] = nums[right], nums[left]
		left++
		right--
	}
}

// func nextPermutation(src string) string{
// 	n := len(src)
// 	i := n - 1
// 	for i >=0 && src[i-1] > src[i] {
// 		i--
// 	}
// 	if i > = 0 {
// 		j :=
// 	}
// }

func genRes(res *[]string, nums []int) {
	var st strings.Builder
{'fraction_non_alphanumeric': 0.22007722007722008, 'fraction_numerical': 0.021021021021021023, 'mean_word_length': 2.4193548387096775, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '216543', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1058, 'n_words': 267}