120 lines
3.0 KiB
JavaScript
120 lines
3.0 KiB
JavaScript
let output = document.getElementById("output");
|
|
let input;
|
|
let linesArr;
|
|
let parsedArr = [];
|
|
let cmdArr = [];
|
|
|
|
function readFile(input) {
|
|
let file = input.files[0];
|
|
let fileReader = new FileReader();
|
|
fileReader.readAsText(file);
|
|
fileReader.onload = function() {
|
|
input = fileReader.result;
|
|
linesArr = input.split("\n");
|
|
};
|
|
fileReader.onerror = function() {
|
|
alert(fileReader.error);
|
|
};
|
|
}
|
|
|
|
let start = document.getElementById("start");
|
|
start.addEventListener("mouseover", () => {
|
|
start.innerHTML = "pwease pwess mee hawwd mastaaa! ~^o^~"
|
|
});
|
|
start.addEventListener("mouseout", () => {
|
|
start.innerHTML = "sowwy mastaa! Ow0;"
|
|
});
|
|
start.addEventListener("click", () => {
|
|
parseArr();
|
|
parseCmd();
|
|
for(let i=0; i<cmdArr.length; i++) {
|
|
move(cmdArr[i][0], cmdArr[i][1], cmdArr[i][2]);
|
|
}
|
|
let answer = "";
|
|
for(let i=0; i<parsedArr.length; i++) {
|
|
answer += parsedArr[i][getTopPos(i)];
|
|
}
|
|
console.log("parsedArr after move()", parsedArr);
|
|
console.log("ANSWER UwU", answer);
|
|
});
|
|
|
|
function parseArr() { //parsing is hard
|
|
let stackArr = [];
|
|
let cleanArr = [];
|
|
|
|
for(let l=0; l<9; l++) {
|
|
let tmpLine = [];
|
|
for(let i=0; i<linesArr[l].length; i++) {
|
|
if(linesArr[l].charAt(i)=='[') tmpLine[i+1] = linesArr[l].charAt(i+1);
|
|
if(l==8) {
|
|
if(typeof(parseInt(linesArr[l].charAt(i)))=="number") tmpLine[i] = linesArr[l].charAt(i);
|
|
if(tmpLine[i] == ' ') tmpLine[i]=undefined;
|
|
}
|
|
}
|
|
stackArr[l] = tmpLine;
|
|
}
|
|
console.log("stackArr", stackArr);
|
|
|
|
for(let i=0; i<stackArr.length; i++) {
|
|
let tmpLine = [];
|
|
let c=0;
|
|
for(let j=0; j<stackArr[i].length; j++) {
|
|
if(stackArr[8][j]!=undefined) {
|
|
tmpLine[c] = stackArr[i][j]
|
|
c++;
|
|
}
|
|
}
|
|
cleanArr[i] = tmpLine;
|
|
}
|
|
console.log("cleanArr", cleanArr);
|
|
|
|
for(let i=0; i<cleanArr.length-1; i++) {
|
|
tmpLine = [];
|
|
let c=7;
|
|
for(let j=0; j<8; j++) {
|
|
if(cleanArr[j][i] != undefined) {
|
|
tmpLine[c] = cleanArr[j][i];
|
|
}
|
|
c--;
|
|
}
|
|
parsedArr[i] = tmpLine;
|
|
}
|
|
console.log("parsedArr", parsedArr);
|
|
}
|
|
|
|
function move(a, s, d) {
|
|
for(let i=0; i<a; i++) {
|
|
parsedArr[d-1][getTopPos(d-1)] = parsedArr[s-1][getTopPos(s-1)];
|
|
}
|
|
}
|
|
|
|
function getTopPos(s) {
|
|
let o=0;
|
|
for(let i=0; i<parsedArr[s].length; i++) {
|
|
if(parsedArr[s][i]==undefined) {
|
|
o=i-1;
|
|
break;
|
|
}
|
|
}
|
|
return o;
|
|
}
|
|
|
|
function parseCmd() {
|
|
for(let i=10; i<linesArr.length; i++) {
|
|
let tmpLine = [];
|
|
let tmpBool = true;
|
|
for(let j=0; j<linesArr[i].length; j++) {
|
|
if(linesArr[i].charAt(j)=='m' && tmpBool) {
|
|
let tmp = 1;
|
|
tmpBool = false;
|
|
if(linesArr[i][j+1]!=' ') tmp = 2
|
|
tmpLine[tmpLine.length] = linesArr[i].substr(j+5,tmp);
|
|
}
|
|
if(linesArr[i].charAt(j)=='f') tmpLine[tmpLine.length] = linesArr[i].substr(j+5,1);
|
|
if(linesArr[i].charAt(j)=='t') tmpLine[tmpLine.length] = linesArr[i].substr(j+3,1);
|
|
}
|
|
cmdArr[i-10] = tmpLine;
|
|
}
|
|
console.log("cmdArr", cmdArr);
|
|
}
|