<commit_before>function collatz(num) {
  var sequence = [num];
  var counter = 0;

  var AudioContext = window.AudioContext || window.webkitAudioContext;
  var audioCtx = new AudioContext();
  var osc = audioCtx.createOscillator();

  while (num > 1) {
    if (num % 2 === 0) {
      console.log(num + ' is even, so we divide it by 2.');

      num /= 2;
      sequence.push(num);
    } else {
      console.log(num + ' is odd. Multiplyling by 3 and adding 1');

      num = num * 3 + 1;
      sequence.push(num);
    }
  }

  console.log(num);

  osc.type = 'square';
  osc.connect(audioCtx.destination);
  osc.start();
  osc.stop(sequence.length);

  var intervalID = setInterval(function() {
    if (counter === sequence.length) {
      clearInterval(intervalID);
      osc.disconnect(audioCtx.destination);
    } else {
      // multiplying frequency by ten so we can hear better
      osc.frequency.value = sequence[counter] * 10;
      counter++;
    }
  }, 300);
}

collatz(15);<commit_msg>implemented semitone step<commit_after>function collatz(num) {
  var sequence = [num];
  var counter = 0;

  var AudioContext = window.AudioContext || window.webkitAudioContext;
  var audioCtx = new AudioContext();
  var osc = audioCtx.createOscillator();

  while (num > 1) {
    if (num % 2 === 0) {
      console.log(num + ' is even, so we divide it by 2.');

      num /= 2;
      sequence.push(num);
    } else {
      console.log(num + ' is odd. Multiplyling by 3 and adding 1');

      num = num * 3 + 1;
      sequence.push(num);
    }
  }

  console.log(num);

  osc.type = 'square';
  osc.connect(audioCtx.destination);
  osc.start();
  osc.stop(sequence.length);

  var intervalID = setInterval(function() {
    if (counter === sequence.length - 1) {
      clearInterval(intervalID);
      osc.disconnect(audioCtx.destination);
    } else {
      // multiplying frequency by 110 to hear better, and by 1.05946 for the semitones step
      osc.frequency.value = sequence[counter] * 110 * 1.05946;
      counter++;
    }
  }, 300);
}

collatz(15);
{'fraction_non_alphanumeric': 0.1388212372138334, 'fraction_numerical': 0.02484169508037019, 'mean_word_length': 2.7142857142857144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1031877', 'n_tokens_mistral': 719, 'n_tokens_neox': 664, 'n_words': 174}