<commit_before>"use strict";

var assert = require('assert');

var MovesEnum = {
  Up: 0,
  Down: 1,
  Left: 2,
  Right: 3
};

// Canned fisher yates shuffle from bost.ocks.org/mike/shuffle
var shuffle = function(array) {
  var m = array.length, t, i;

  // While there remain elements to shuffle
  while (m) {

    // Pick a remaining element
    i = Math.floor(Math.random() * m--);

    // And swap it with the current element.
    t = array[m];
    array[m] = array[i];
    array[i] = t;
  }

  return array;
};

var fillGrid = function(size, fill, isBlank) {
  var grid = [];
  for (var i=0;i<size;++i) {
    var row = [];
    for (var j=0;j<size;++j) {
      if (isBlank(i,j)) {
        row.push('*');
      } else {
        row.push(fill(i,j));
      }
    }
    grid.push(row);
  }
  return grid;
};

var createElementsOfGrid = function(size) {
  var elements = [];
  for (var i=1;i<size*size;++i) {
    elements.push(i);
  }
  return elements;
};

var MagicSquare = function(size) {

  var isBlank = function(x,y) { return x === (size-1) && y === (size-1); };

  var elements = createElementsOfGrid(size);
  var fill = function(x,y) { var n = elements.shift(); return n; };

  var grid = fillGrid(size, fill, isBlank);


  var onNearEdge = function(i) { return (i === size-1); };
  var onFarEdge =  function(i) { return i === 0; };

  var findBlank = function() {
    for (var i=0;i<size;++i) {
      for (var j=0;j<size;++j) {
        if (grid[i][j] === '*') {
          return { x: j, y: i };
        }
      }
    }
  };

  return {
    
    display: function() {
      var s = '';
      for (var i=0;i<size;++i) {
        for (var j=0;j<size;++j) {
          s += grid[i][j];
        }
        s+='\n';
      }
      return s;
    },

    makeMove: function(move) {
      var blankPos = findBlank();

      switch (move) {
        case MovesEnum.UP:
          this.swap(blankPos, { x: blankPos.x, y: blankPos.y - 1});
          break;
        case MovesEnum.DOWN:
          this.swap(blankPos, { x: blankPos.x, y: blankPos.y + 1});
          break;
        case MovesEnum.LEFT:
          this.swap(blankPos, { x: blankPos.x + 1, y: blankPos.y});
          console.log('SWAPPED');
	  break;
        case MovesEnum.RIGHT:
          this.swap(blankPos, { x: blankPos.x - 1, y: blankPos.y});
          break;
      }
    },

    shuffle: function() {
      var blankX = (Math.random() * size)|0;
      var blankY = (Math.random() * size)|0;
 
      var isBlank = function(x,y) { return x === blankX && y === blankY; };
      shuffle(elements);

      grid = fillGrid(size, fill, isBlank);
    },
    
    solved: function() {
      var counter = 1;
      for (var i=0;i<size;++i) {
        for (var j=0;j<size;++j) {<commit_msg>make a bit more sense and now the tests pass<commit_after>"use strict";

var assert = require('assert');

var MovesEnum = {
  Up: 0,
  Down: 1,
  Left: 2,
  Right: 3
};

// Canned fisher yates shuffle from bost.ocks.org/mike/shuffle
var shuffle = function(array) {
  var m = array.length, t, i;

  // While there remain elements to shuffle
  while (m) {

    // Pick a remaining element
    i = Math.floor(Math.random() * m--);

    // And swap it with the current element.
    t = array[m];
    array[m] = array[i];
    array[i] = t;
  }

  return array;
};

var fillGrid = function(size, fill, isBlank) {
  var grid = [];
  for (var i=0;i<size;++i) {
    var row = [];
    for (var j=0;j<size;++j) {
      if (isBlank(i,j)) {
        row.push('*');
      } else {
        row.push(fill(i,j));
      }
    }
    grid.push(row);
  }
  return grid;
};

var createElementsOfGrid = function(size) {
  var elements = [];
  for (var i=1;i<size*size;++i) {
    elements.push(i);
  }
  return elements;
};

var MagicSquare = function(size) {

  var isBlank = function(x,y) { return x === (size-1) && y === (size-1); };

  var elements = createElementsOfGrid(size);
  var fill = function(x,y) { var n = elements.shift(); return n; };

  var grid = fillGrid(size, fill, isBlank);


  var onNearEdge = function(i) { return (i === size-1); };
  var onFarEdge =  function(i) { return i === 0; };

  var findBlank = function() {
    for (var i=0;i<size;++i) {
      for (var j=0;j<size;++j) {
        if (grid[i][j] === '*') {
          return { x: j, y: i };
        }
      }
    }
  };

  return {
    
    display: function() {
      var s = '';
      for (var i=0;i<size;++i) {
        for (var j=0;j<size;++j) {
          s += grid[i][j];
        }
        s+='\n';
      }
      return s;
    },

    makeMove: function(move) {
      var blankPos = findBlank();

      switch (move) {
        case MovesEnum.Up:
          this.swap(blankPos, { x: blankPos.x, y: blankPos.y - 1});
          break;
        case MovesEnum.Down:
          this.swap(blankPos, { x: blankPos.x, y: blankPos.y + 1});
          break;
        case MovesEnum.Left:
          this.swap(blankPos, { x: blankPos.x - 1, y: blankPos.y});
	  break;
        case MovesEnum.Right:
          this.swap(blankPos, { x: blankPos.x + 1, y: blankPos.y});
          break;
      }
    },

    shuffle: function() {
      var blankX = (Math.random() * size)|0;
      var blankY = (Math.random() * size)|0;
 
      var isBlank = function(x,y) { return x === blankX && y === blankY; };
      shuffle(elements);

      grid = fillGrid(size, fill, isBlank);
    },
    
    solved: function() {
      var counter = 1;
      for (var i=0;i<size;++i) {
        for (var j=0;j<size;++j) {
{'fraction_non_alphanumeric': 0.17693291902760008, 'fraction_numerical': 0.008773533174922318, 'mean_word_length': 2.0985277463193657, 'pattern_counts': {'":': 0, '<': 21, '<?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': '1848194', 'n_tokens_mistral': 2083, 'n_tokens_neox': 2015, 'n_words': 492}