<commit_before>String.prototype.replaceAt=function(index, character) 
{
	return this.substr(0, index) + character + this.substr(index+character.length);
}

//"Tape class"
function Tape(alphabet, blank, pos, tapeContent)
{
	//data
	this.alphabet= alphabet;
	this.blankSymbol= blank;
	this.pos= pos;
	this.tapeContent= tapeContent;
	
	this.alphabetCopy= alphabet;
	this.blankSymbolCopy= blank;
	this.posCopy= pos;
	this.tapeContentCopy= tapeContent;
	
	this.reset = function()
	{
		this.alphabet= this.alphabetCopy;
		this.blankSymbol= this.blankSymbolCopy;
		this.pos= this.posCopy;
		this.tapeContent= this.tapeContentCopy;
	}
	
	//methods
	this.moveRight= function (){
		var tapeLength= (this.tapeContent).length;
		if(this.pos == tapeLength - 1)
			this.tapeContent= this.tapeContent.concat(this.blankSymbol);
		this.pos= this.pos + 1;
			
	}
	this.moveLeft= function (){
		if(this.pos == 0)
			this.tapeContent= this.blankSymbol.concat(this.tapeContent);
		else
			this.pos= this.pos - 1;
							
	}
	//Writes symbol on the tape, at the current position
	//TODO: check if "Symbol" exists in "this.alphabet"
	this.write= function(Symbol){
		this.tapeContent= this.tapeContent.replaceAt(this.pos, Symbol);
	}
	//returns current position tape contents
	this.read= function(){
		return this.tapeContent.charAt(this.pos);
	}
	//Show Tape
	this.show= function(){
		document.write("Tape Alphabet: <br>");
		for(var j= 0; j < alphabet.length; j++)
		{
		
			document.write(j + ": " + alphabet[j] + "; " + "<br>");
		}
		document.write("Blank Symbol: " + this.blankSymbol + "<br>" );
		document.write("Current Pos: " + this.pos + "<br>" );
		document.write("Tape Content: ")
		for(var i= 0; i < tapeContent.length; i++)
		{
			document.write(tapeContent[i]);
			
		}
		document.write("<br>");
	}
	
}

var stepReturn = 2;

var steper = null;

var time = 0;

var timer = null;

var running = false;

//"TuringMachine class"
function TuringMachine(tape, transitionsTable, initialState, finalStates)
{
	this.tape= tape;
	this.transitionsTable= transitionsTable;
	this.initialState= initialState;
	this.finalStates= finalStates;
	//this.blankSymbol= blank; // Necessary???
	this.currentState= initialState;
	this.stepNumber= 0;
	
	this.tapeCopy= tape;
	this.transitionsTableCopy= transitionsTable;
	this.initialStateCopy= initialState;
	this.finalStatesCopy= finalStates;
	this.currentStateCopy= initialState;
	
	this.reset = function()
	{
		this.tape= this.tapeCopy;
		this.transitionsTable= this.transitionsTableCopy;
		this.initialState= this.initialStateCopy;
		this.finalStates= this.finalStatesCopy;
		this.currentState= this.currentStateCopy;
		this.stepNumber= 0;
		
		stepReturn = 2;
		
		
		(this.tape).reset();
	}
	
	this.stop = function()
	{
		clearInterval(steper);
		
		clearInterval(timer);
		
		time = 0;
		
		this.reset();
		
		running = false;

		document.getElementById("runButton").disabled = false;
		document.getElementById("stopButton").disabled = true;		
		document.getElementById("pauseButton").disabled = true;
	}
	
	this.pause = function()
	{
		clearInterval(steper);
		
		clearInterval(timer);
		
		running = false;

		document.getElementById("pauseButton").disabled = true;	
		document.getElementById("resumeButton").disabled = false;
	}
	
	this.resume = function()
	{
		this.run();
		
		running = true;
		
		document.getElementById("pauseButton").disabled = false;
		document.getElementById("resumeButton").disabled = true;
	}
	
	this.step= function(){
	
		stepReturn = 2;
		
		var stepResult = document.getElementById('output');
		
		var stepString= "";
		for(var k= 0; k < (this.tape).tapeContent.length; k++)
		{
			if(k == (this.tape).pos)
				stepString += "<font color='red'>" + (this.tape).tapeContent[k] + "</font>";
			else
				stepString += "<font color='black'>" + (this.tape).tapeContent[k] + "</font>";
		}
		stepString += "<br>";
				
		stepResult.insertAdjacentHTML('beforeend', stepString);
		
		var i;
		document.getElementById('animation').innerHTML ="";
		var elements = new Array();
		elements = stepString.split("</font>");
		//console.log(elements);
		var size = 40;
		var padding = '';
		var anim = true;
		if(elements.length>21 && elements.length<42){
			size = 20;
			padding = "padding-left:5px;padding-bottom:5px;"
		}
		else if(elements.length>42){
			anim = false;
			console.log("anim false");
		}
		if(anim == false){
			document.getElementById('animation').style.fontSize="large";
			document.getElementById('animation').innerHTML="Input to long!";}
		else{
			for(i=0;i<elements.length-1;i++){
				//console.log(i+ ": "+elements[i]);
				if(elements[i].indexOf("red")> -1) 
					document.getElementById('animation').innerHTML += '<div class="tapeanim bs-example1" style="width:'+ size + 'px;'+padding+'outline: 1px dotted #EEA236;background-color:#F0AD4E;font-weight:bolder;" id="anim'+i +'">' + elements[i] +'</font></div>';
				else
					document.getElementById('animation').innerHTML += '<div class="tapeanim bs-example1" style="width:'+size + 'px;'+padding+'outline: 1px dotted #DDC;background-color:#DDD" id="anim'+i +'">' + elements[i] +'</font></div>';
				
			};
		}
		//obtain symbol on the current tape position
		var currentSymbolOnTape= (this.tape).read();
			
		var nextState;
		var nextSymbol;
		var nextDirection;
		
		var transitionFound= false;
		
		for(var i= 0; i < transitionsTable.length; i++)
		{
			if((transitionsTable[i].currentState == this.currentState) &&  (transitionsTable[i].scanSymbol == currentSymbolOnTape))
			{
				nextState= transitionsTable[i].nextState;
				nextSymbol= transitionsTable[i].printSymbol;
				nextDirection= transitionsTable[i].direction;
								<commit_msg>Fixed too long print<commit_after>String.prototype.replaceAt=function(index, character) 
{
	return this.substr(0, index) + character + this.substr(index+character.length);
}

//"Tape class"
function Tape(alphabet, blank, pos, tapeContent)
{
	//data
	this.alphabet= alphabet;
	this.blankSymbol= blank;
	this.pos= pos;
	this.tapeContent= tapeContent;
	
	this.alphabetCopy= alphabet;
	this.blankSymbolCopy= blank;
	this.posCopy= pos;
	this.tapeContentCopy= tapeContent;
	
	this.reset = function()
	{
		this.alphabet= this.alphabetCopy;
		this.blankSymbol= this.blankSymbolCopy;
		this.pos= this.posCopy;
		this.tapeContent= this.tapeContentCopy;
	}
	
	//methods
	this.moveRight= function (){
		var tapeLength= (this.tapeContent).length;
		if(this.pos == tapeLength - 1)
			this.tapeContent= this.tapeContent.concat(this.blankSymbol);
		this.pos= this.pos + 1;
			
	}
	this.moveLeft= function (){
		if(this.pos == 0)
			this.tapeContent= this.blankSymbol.concat(this.tapeContent);
		else
			this.pos= this.pos - 1;
							
	}
	//Writes symbol on the tape, at the current position
	//TODO: check if "Symbol" exists in "this.alphabet"
	this.write= function(Symbol){
		this.tapeContent= this.tapeContent.replaceAt(this.pos, Symbol);
	}
	//returns current position tape contents
	this.read= function(){
		return this.tapeContent.charAt(this.pos);
	}
	//Show Tape
	this.show= function(){
		document.write("Tape Alphabet: <br>");
		for(var j= 0; j < alphabet.length; j++)
		{
		
			document.write(j + ": " + alphabet[j] + "; " + "<br>");
		}
		document.write("Blank Symbol: " + this.blankSymbol + "<br>" );
		document.write("Current Pos: " + this.pos + "<br>" );
		document.write("Tape Content: ")
		for(var i= 0; i < tapeContent.length; i++)
		{
			document.write(tapeContent[i]);
			
		}
		document.write("<br>");
	}
	
}

var stepReturn = 2;

var steper = null;

var time = 0;

var timer = null;

var running = false;

//"TuringMachine class"
function TuringMachine(tape, transitionsTable, initialState, finalStates)
{
	this.tape= tape;
	this.transitionsTable= transitionsTable;
	this.initialState= initialState;
	this.finalStates= finalStates;
	//this.blankSymbol= blank; // Necessary???
	this.currentState= initialState;
	this.stepNumber= 0;
	
	this.tapeCopy= tape;
	this.transitionsTableCopy= transitionsTable;
	this.initialStateCopy= initialState;
	this.finalStatesCopy= finalStates;
	this.currentStateCopy= initialState;
	
	this.reset = function()
	{
		this.tape= this.tapeCopy;
		this.transitionsTable= this.transitionsTableCopy;
		this.initialState= this.initialStateCopy;
		this.finalStates= this.finalStatesCopy;
		this.currentState= this.currentStateCopy;
		this.stepNumber= 0;
		
		stepReturn = 2;
		
		
		(this.tape).reset();
	}
	
	this.stop = function()
	{
		clearInterval(steper);
		
		clearInterval(timer);
		
		time = 0;
		
		this.reset();
		
		running = false;

		document.getElementById("runButton").disabled = false;
		document.getElementById("stopButton").disabled = true;		
		document.getElementById("pauseButton").disabled = true;
	}
	
	this.pause = function()
	{
		clearInterval(steper);
		
		clearInterval(timer);
		
		running = false;

		document.getElementById("pauseButton").disabled = true;	
		document.getElementById("resumeButton").disabled = false;
	}
	
	this.resume = function()
	{
		this.run();
		
		running = true;
		
		document.getElementById("pauseButton").disabled = false;
		document.getElementById("resumeButton").disabled = true;
	}
	
	this.step= function(){
	
		stepReturn = 2;
		
		var stepResult = document.getElementById('output');
		
		var stepString= "";
		for(var k= 0; k < (this.tape).tapeContent.length; k++)
		{
			if(k == (this.tape).pos)
				stepString += "<font color='red'>" + (this.tape).tapeContent[k] + "</font>";
			else
				stepString += "<font color='black'>" + (this.tape).tapeContent[k] + "</font>";
		}
		stepString += "<br>";
				
		stepResult.insertAdjacentHTML('beforeend', stepString);
		
		var i;
		document.getElementById('animation').innerHTML ="";
		var elements = new Array();
		elements = stepString.split("</font>");
		//console.log(elements);
		var size = 40;
		var padding = '';
		var anim = true;
		if(elements.length>21 && elements.length<42){
			size = 20;
			padding = "padding-left:5px;padding-bottom:5px;"
		}
		else if(elements.length>42){
			anim = false;
			console.log("anim false");
		}
		if(anim == false){
			document.getElementById('animation').style.fontSize="large";
			document.getElementById('animation').innerHTML="Input too long!";}
		else{
			for(i=0;i<elements.length-1;i++){
				//console.log(i+ ": "+elements[i]);
				if(elements[i].indexOf("red")> -1) 
					document.getElementById('animation').innerHTML += '<div class="tapeanim bs-example1" style="width:'+ size + 'px;'+padding+'outline: 1px dotted #EEA236;background-color:#F0AD4E;font-weight:bolder;" id="anim'+i +'">' + elements[i] +'</font></div>';
				else
					document.getElementById('animation').innerHTML += '<div class="tapeanim bs-example1" style="width:'+size + 'px;'+padding+'outline: 1px dotted #DDC;background-color:#DDD" id="anim'+i +'">' + elements[i] +'</font></div>';
				
			};
		}
		//obtain symbol on the current tape position
		var currentSymbolOnTape= (this.tape).read();
			
		var nextState;
		var nextSymbol;
		var nextDirection;
		
		var transitionFound= false;
		
		for(var i= 0; i < transitionsTable.length; i++)
		{
			if((transitionsTable[i].currentState == this.currentState) &&  (transitionsTable[i].scanSymbol == currentSymbolOnTape))
			{
				nextState= transitionsTable[i].nextState;
				nextSymbol= transitionsTable[i].printSymbol;
				nextDirection= transitionsTable[i].direction;
								
{'fraction_non_alphanumeric': 0.1596683133380381, 'fraction_numerical': 0.007057163020465773, 'mean_word_length': 4.134510869565218, 'pattern_counts': {'":': 4, '<': 49, '<?xml version=': 0, '>': 43, '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': '5897198', 'n_tokens_mistral': 4316, 'n_tokens_neox': 3748, 'n_words': 727}