<commit_before>function swap(a, i, j) {
  [a[i],a[j]] = [a[j],a[i]];
}

function generatePermutations(a, n) {
  if (n === 0) {
    console.log(a.join(''));
  } else {
    for (let i = 0; i <= n; i++) {
      generatePermutations(a, n - 1);
      swap(a, n % 2 === 0 ? i : 0, n);
    }
  }
}

if (process.argv.length !== 3) {
  console.error('Exactly one argument is required');
  process.exit(1);
}
let word = process.argv[2];
generatePermutations(word.split(''), word.length - 1);<commit_msg>Fix anagrams script to be the real Heaps Algorithm<commit_after>function generatePermutations(a, n) {
  if (n === 0) {
    console.log(a.join(''));
  } else {
    for (let i = 0; i < n; i++) {
      generatePermutations(a, n - 1);
      let j = n % 2 === 0 ? i : 0;
      [a[j], a[n]] = [a[n], a[j]];
    }
    generatePermutations(a, n - 1);
  }
}

if (process.argv.length !== 3) {
  console.error('Exactly one argument is required');
  process.exit(1);
}
let word = process.argv[2];
generatePermutations(word.split(''), word.length - 1);
{'fraction_non_alphanumeric': 0.20833333333333334, 'fraction_numerical': 0.020348837209302327, 'mean_word_length': 3.0669291338582676, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2075700', 'n_tokens_mistral': 422, 'n_tokens_neox': 392, 'n_words': 100}