<commit_before>﻿(function($) {
  var levels = 6,
      nodeNum = Math.pow(2, levels) - 1,
      keyToFind,
      initialData = [],
      jsavBinaryTree,
      $key = $('#keyToFind'),
      av = new JSAV($(".avcontainer"));


  // auxillary function for creating a perfect binary tree
  // inserts the values in the initialData[] array in level order
  function calculateInitialData(level, min, max, levelsInTotal, arrayIndex) {
    diff = max - min;
    var value = JSAV.utils.rand.numKey(min + Math.floor(diff / 3), max - Math.floor(diff / 3))
    initialData[arrayIndex - 1] = value;
    if (level < levelsInTotal) {
      calculateInitialData(level + 1, min, value - 1, levelsInTotal, 2 * arrayIndex);
      calculateInitialData(level + 1, value + 1, max, levelsInTotal, 2 * arrayIndex + 1);
    }
  }

  function getIndex(node, root) {
    if (node === root) {
      return 0;
    }

    if (node.parent().left() === node) {
      return (getIndex(node.parent(), root) + 1) * 2 - 1;
    } else {
      return (getIndex(node.parent(), root) + 1) * 2;
    }
  }

  av.recorded(); // we are not recording an AV with an algorithm

  function initialize() {
    if (jsavBinaryTree) {
      jsavBinaryTree.clear();
    }
    jsavBinaryTree = av.ds.bintree({center: true, visible: true, nodegap: 15});
    jsavBinaryTree.root("?");
    jsavBinaryTree.root().addClass("emptynode");
    jsavBinaryTree.click(clickHandler);
    jsavBinaryTree.layout();

    calculateInitialData(1, 100, 1000, levels, 1);
    keyToFind = initialData[JSAV.utils.rand.numKey(Math.floor(nodeNum / 2), nodeNum)];
    $key.html("<li>" + keyToFind + "</li>");
    av.ds.array($key, {indexed: false}).css(0, {"background-color": "#ddf"}).toggleArrow(0);

    return jsavBinaryTree;
  }

  function modelSolution(jsav) {
    jsav.ds.array([keyToFind], {indexed: false}).css(0, {"background-color": "#ddf"});
    var modelTree = jsav.ds.bintree({center: true, visible: true, nodegap: 15});
    jsav._undo = [];

    modelTree.root("?");
    modelTree.root().addClass("emptynode");
    modelTree.layout();

    var node = modelTree.root();

    while (node.value() !== keyToFind) {
      var index = getIndex(node, modelTree.root());
      node.removeClass("emptynode");
      node.value(initialData[index]);
      node.highlight();
      if ((index + 1) * 2 < nodeNum) {
        node.left("?");
        node.left().addClass("emptynode");
        node.right("?");
        node.right().addClass("emptynode");
        if (node.value() > keyToFind) {
          node = node.left();
        } else {
          node = node.right();
        }
      }
      modelTree.layout();
      jsav.stepOption("grade", true);
      jsav.step();
    }

    return modelTree;
  }

  function clickHandler() {
    if (!this.isHighlight()) {
      var index = getIndex(this, jsavBinaryTree.root());
      this.removeClass("emptynode");
      this.value(initialData[index]);
      this.highlight();
      if ((index + 1) * 2 < nodeNum) {
        BST.turnAnimationOff();
        this.left("?");
        this.left().addClass("emptynode");
        this.right("?");
        this.right().addClass("emptynode");
        BST.restoreAnimationState();
      }
      jsavBinaryTree.layout();
      exercise.gradeableStep();
    }
  }

  var exercise = av.exercise(modelSolution, initialize,
    { "css": "background-color" },
    { controls: $(".jsavexercisecontrols") });
  exercise.reset();
}(jQuery));<commit_msg>Fixed a bug with BST-search-proficiency where it considered every answer incorrect<commit_after>﻿(function($) {
  var levels = 6,
      nodeNum = Math.pow(2, levels) - 1,
      keyToFind,
      initialData = [],
      jsavBinaryTree,
      $key = $('#keyToFind'),
      av = new JSAV($(".avcontainer"));


  // auxillary function for creating a perfect binary tree
  // inserts the values in the initialData[] array in level order
  function calculateInitialData(level, min, max, levelsInTotal, arrayIndex) {
    diff = max - min;
    var value = JSAV.utils.rand.numKey(min + Math.floor(diff / 3), max - Math.floor(diff / 3))
    initialData[arrayIndex - 1] = value;
    if (level < levelsInTotal) {
      calculateInitialData(level + 1, min, value - 1, levelsInTotal, 2 * arrayIndex);
      calculateInitialData(level + 1, value + 1, max, levelsInTotal, 2 * arrayIndex + 1);
    }
  }

  function getIndex(node, root) {
    if (node === root) {
      return 0;
    }

    if (node.parent().left() === node) {
      return (getIndex(node.parent(), root) + 1) * 2 - 1;
    } else {
      return (getIndex(node.parent(), root) + 1) * 2;
    }
  }

  av.recorded(); // we are not recording an AV with an algorithm

  function initialize() {
    if (jsavBinaryTree) {
      jsavBinaryTree.clear();
    }
    jsavBinaryTree = av.ds.bintree({center: true, visible: true, nodegap: 15});
    jsavBinaryTree.root("?");
    jsavBinaryTree.root().addClass("emptynode");
    jsavBinaryTree.click(clickHandler);
    jsavBinaryTree.layout();

    calculateInitialData(1, 100, 1000, levels, 1);
    keyToFind = initialData[JSAV.utils.rand.numKey(Math.floor(nodeNum / 2), nodeNum)];
    $key.html("<li>" + keyToFind + "</li>");
    av.ds.array($key, {indexed: false}).css(0, {"background-color": "#ddf"}).toggleArrow(0);

    av.forward();
    av._undo = [];

    return jsavBinaryTree;
  }

  function modelSolution(jsav) {
    jsav.ds.array([keyToFind], {indexed: false}).css(0, {"background-color": "#ddf"});
    var modelTree = jsav.ds.bintree({center: true, visible: true, nodegap: 15});
    jsav._undo = [];

    modelTree.root("?");
    modelTree.root().addClass("emptynode");
    modelTree.layout();

    var node = modelTree.root();

    while (node.value() !== keyToFind) {
      var index = getIndex(node, modelTree.root());
      node.removeClass("emptynode");
      node.value(initialData[index]);
      node.highlight();
      if ((index + 1) * 2 < nodeNum) {
        node.left("?");
        node.left().addClass("emptynode");
        node.right("?");
        node.right().addClass("emptynode");
        if (node.value() > keyToFind) {
          node = node.left();
        } else {
          node = node.right();
        }
      }
      modelTree.layout();
      jsav.stepOption("grade", true);
      jsav.step();
    }

    return modelTree;
  }

  function clickHandler() {
    if (!this.isHighlight()) {
      var index = getIndex(this, jsavBinaryTree.root());
      this.removeClass("emptynode");
      this.value(initialData[index]);
      this.highlight();
      if ((index + 1) * 2 < nodeNum) {
        BST.turnAnimationOff();
        this.left("?");
        this.left().addClass("emptynode");
        this.right("?");
        this.right().addClass("emptynode");
        BST.restoreAnimationState();
      }
      jsavBinaryTree.layout();
      exercise.gradeableStep();
    }
  }

  var exercise = av.exercise(modelSolution, initialize,
    [{ "css": "background-color" }, {}],
    { controls: $(".jsavexercisecontrols") });
  exercise.reset();
}(jQuery));
{'fraction_non_alphanumeric': 0.1696848709539427, 'fraction_numerical': 0.011407386282617995, 'mean_word_length': 2.8098859315589353, 'pattern_counts': {'":': 6, '<': 13, '<?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': '3419431', 'n_tokens_mistral': 2347, 'n_tokens_neox': 2229, 'n_words': 473}