<commit_before>const _swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];


export function permutations(n) {
  const p = [];
  for (let i = 1; i <= n; ++i)
    p.push(i);

  const result = [];

  while (true) {
    let i, j;

    result.push(p.slice());

    for (i = n-2; i >= 0 && p[i] > p[i+1]; --i)
      ;
    if (i < 0)
      break;

    for (j = n-1; p[j] < p[i]; --j)
      ;

    _swap(p, i, j);

    for (++i, j = n-1; i < j; ++i, --j)
      _swap(p, i, j);
  }

  return result;
};<commit_msg> make permutations() a generator<commit_after>const _swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];


export function* permutations(n) {
  const p = [];
  for (let i = 1; i <= n; ++i)
    p.push(i);

  while (true) {
    let i, j;

    yield p.slice();

    for (i = n-2; i >= 0 && p[i] > p[i+1]; --i)
      ;
    if (i < 0)
      break;

    for (j = n-1; p[j] < p[i]; --j)
      ;

    _swap(p, i, j);

    for (++i, j = n-1; i < j; ++i, --j)
      _swap(p, i, j);
  }
};
{'fraction_non_alphanumeric': 0.2569089048106448, 'fraction_numerical': 0.014329580348004094, 'mean_word_length': 1.818443804034582, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '4905128', 'n_tokens_mistral': 484, 'n_tokens_neox': 453, 'n_words': 129}