master
1function(context, args) { // t:#s.usr.loc
2 const l=#s.scripts.lib();
3 const c=["red","purple","blue","cyan","green","lime","yellow","orange"];
4 const ez=["open","unlock","release"];
5 const triad={[c[0]]:[c[5],c[3]],[c[1]]:[c[6],c[4]],[c[2]]:[c[5],c[7]],[c[3]]:[c[6],c[0]],[c[4]]:[c[7],c[1]],[c[5]]:[c[0],c[2]],[c[6]]:[c[1],c[3]],[c[7]]:[c[6],c[0]]}
6 const k={
7 EZ_25:ez,
8 EZ_35:ez,
9 EZ_40:ez,
10 c001:c,
11 c002:c,
12 c003:c,
13 digit:[0,1,2,3,4,5,6,7,8,9],
14 prime:[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,73,79,83,89,97],
15 color_digit:{[c[0]]:3,[c[1]]:6,[c[2]]:4,[c[3]]:4,[c[4]]:5,[c[5]]:4,[c[6]]:6,[c[7]]:6},
16 complement:{[c[0]]:c[4],[c[1]]:c[5],[c[2]]:c[6],[c[3]]:c[7],[c[4]]:c[0],[c[5]]:c[1],[c[6]]:c[2],[c[7]]:c[3]},
17 c003_triad_1: pc => triad[pc][0],
18 c003_triad_2: pc => triad[pc][1],
19 };
20 const locks = Object.keys(k);
21 const t = a => args.t.call(a);
22 function* ul(al, kv, opts) {
23 for(const v of opts) {
24 al[kv] = v;
25 yield [al, t(al)];
26 }
27 }
28 const crack = (al, kv, opts, lr) => {
29 for(const [na, res] of ul(al, kv, opts)) {
30 if(lr !== res) {
31 return [na, res];
32 }
33 }
34 return [al, null];
35 }
36 let a = {};
37 let res = t(a);
38 let q = false;
39 let c00x = null;
40 while(!q && !res.contains("LOCK_UNLOCKED")) {
41 for(const lt of locks) {
42 if(res.contains(lt)) {
43 switch(lt) {
44 "color_digit":
45 "complement":
46 a[lt]=k[lt][a[c00x]];
47 res = t(a);
48 break;
49 "c003_triad_1":
50 "c003_triad_2":
51 a[lt]=k[lt](a[c00x]);
52 res = t(a);
53 break;
54 default:
55 if(lt === "c001" || lt === "c003" || lt === "c003") c00x=lt;
56 [a, res] = crack(a, lt, k[lt], res);
57 if(!res) return {ok:false, msg:`Unable to find key for ${lt}\nfound: ${l.dump(a)}`}
58 break;
59 }
60 }
61 }
62 }
63
64 return l.ok();
65}