Last active
June 10, 2019 21:21
-
-
Save engelsdamien/903f8b81926647a00303249a294ad43e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let lineNumber = +readline() | |
let input = []; | |
while (lineNumber--) { | |
input.push(readline()) | |
} | |
writeline(UltraCISC(input)) | |
function UltraCISC(commands) { | |
let result = new Array(32).fill("?"); | |
commands.forEach(cmd => { | |
const tokens = cmd.split(" "); | |
const i = tokens[0]; | |
const arg1 = tokens[1]; | |
let arg2; | |
switch (i) { | |
case "SET": | |
result[arg1] = "1"; | |
break; | |
case "CLEAR": | |
result[arg1] = "0"; | |
break; | |
case "AND": | |
arg2 = tokens[2]; | |
if (result[arg1] === "0" || result[arg2] === "0") { | |
result[arg1] = "0"; | |
} else if (result[arg1] === "?" || result[arg2] === "?") { | |
result[arg1] = "?"; | |
} else { | |
result[arg1] = "1"; | |
} | |
break; | |
case "OR": | |
arg2 = tokens[2]; | |
if (result[arg1] === "1" || result[arg2] === "1") { | |
result[arg1] = "1"; | |
} else if (result[arg1] === "?" || result[arg2] === "?") { | |
result[arg1] = "?"; | |
} else { | |
result[arg1] = "0"; | |
} | |
break; | |
} | |
}) | |
return result.reverse().join(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment