adventofcode-2017/day16/part1.js
2017-12-16 12:12:56 +00:00

12 lines
517 B
JavaScript

var items = "abcdefghijklmnop".split("");
s = (i) => {items = items.splice(-i).concat(items);}
x = (a,b) => {[items[a], items[b]] = [items[b], items[a]]}
p = (a,b) => {x(items.indexOf(a), items.indexOf(b))}
var input = require("fs").readFileSync("input.txt").toString().replace("\n", "");
var input = "," + input + ",";
var expr = input.replace(/,/g, ");").replace(/;([sxp])/g, ";$1(").replace(/([a-z])\/([a-z])/g, "'$1'/'$2'").replace(/\//g, ",");
expr = expr.substring(2);
eval(expr);
console.log(items.join(""));