<commit_before>package integer_partition_generation

type partition []int

func Partitions(n int) []partition {
	partitions := []partition{}

	// The first partition of n in lexicographically decreasing order is {n} itself.
	p := partition{n}

	for p != nil {
		partitions = append(partitions, p)
		p = next(p)
	}

	return partitions
}

func next(p partition) partition {
	g := indexLastGreaterThan1(p)
	if g < 0 {
		// Root case: p is made entirely of 1s. There is no next partition.
		return nil
	}

	// To generate a new partition that is after p in lexicographically decreasing order, we remove
	// 1 from the last element greater than 1, then append it back at the end of the partition.
	// Example: {3, 1, 1} -> {2, 1, 1, 1}.
	c := clone(p)
	c[g]--
	c = append(c, 1)

	// This new partition is after p in lexicographically decreasing order, however it is not
	// necessarily *immediately* after p. To fix that, we must "collect" all the 1s that follow g.
	// Example: {2, 1, 1, 1} -> {2, 2, 1}.
	// Note that in the above example, we must be careful not to "overcollect" the 1s into {2, 3},
	// because that's the same partition as {3, 2}, which has already been generated since it's<commit_msg>[integer_partition_generation/go] Condense loop.<commit_after>package integer_partition_generation

type partition []int

func Partitions(n int) []partition {
	partitions := []partition{}

	// The first partition of n in lexicographically decreasing order is {n} itself.
	for p := (partition{n}); p != nil; p = next(p) {
		partitions = append(partitions, p)
	}

	return partitions
}

func next(p partition) partition {
	g := indexLastGreaterThan1(p)
	if g < 0 {
		// Root case: p is made entirely of 1s. There is no next partition.
		return nil
	}

	// To generate a new partition that is after p in lexicographically decreasing order, we remove
	// 1 from the last element greater than 1, then append it back at the end of the partition.
	// Example: {3, 1, 1} -> {2, 1, 1, 1}.
	c := clone(p)
	c[g]--
	c = append(c, 1)

	// This new partition is after p in lexicographically decreasing order, however it is not
	// necessarily *immediately* after p. To fix that, we must "collect" all the 1s that follow g.
	// Example: {2, 1, 1, 1} -> {2, 2, 1}.
	// Note that in the above example, we must be careful not to "overcollect" the 1s into {2, 3},
	// because that's the same partition as {3, 2}, which has already been generated since it's
{'fraction_non_alphanumeric': 0.10997127615921215, 'fraction_numerical': 0.021337710299548625, 'mean_word_length': 3.473394495412844, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1563815', 'n_tokens_mistral': 835, 'n_tokens_neox': 754, 'n_words': 355}