123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- // TODO: clean this up
- \d u
- \l utils.k
- / :`i$"A"; // 65
- / :`i$"Z"; // 90
- / :`i$"0"; // 48
- / :`i$"9"; // 57
- / :`i$":"; // 58
- / :`i$"$"; // 36
- \d pat
- testAtZ: { i:`i$x; $[(i>64) & (i<91);1;0] };
- test0t9: { i:`i$x; $[(i>47) & (i<58);1;0] };
- testcol: { i:`i$x; $[i=58;1;0] };
- testend: { i:`i$x; $[i=36;1;0] };
- s0: ((testAtZ; 1);(test0t9; 2));
- s1: ((test0t9; 2);(testcol; 3));
- s2: ((testend; 7); (testcol; 3));
- s3: ((test0t9; 5);(testAtZ; 5));
- s4: ((testAtZ; 5); (test0t9; 5));
- s5: (,(test0t9; 5));
- // 7 is done
- states:: (s0;s1;s2;s3;s4;s5);
- i: 1;
- runS: {[c;s]
- :{
- :$[x[0][y];x[1];0]
- }[;c]'states[s]
- };
- // blk 1 stuff ===============================
- blk1: {[a;c]
- / u.ppr "blk1";
- activeidx: 0;
- active: (0;a[3]+1);
- s: 0;
- r: runS[c;s];
- r: *($[(+/r)>0;r^0;0]);
- / u.ppr (c;r;a[2]);
- a0: $[s>4;s;r];
- :((,active);activeidx;r;a[3])
- };
- // blk 2 stuff ===============================
- e:{[a;c;r]
- / u.ppr ("edge";r;a;c);
- // add indices
- indices: a[0],(,(a[3];a[3]));
- a[2]: r;
- a[1] +: 1;
- :(indices; a[1]; a[2]; a[3])
- };
- ne:{[a;c;r]
- / u.ppr "no edge";
- ai: a[1];
- a[0;ai;0]: $[a[2]>0;a[0;ai;0];a[3]];
- a[0;ai;1]: a[3]+1;
- a[2]: r;
- :a
- };
- blk2: {[a;c]
- / u.ppr ("blk2"; a);
- s: a[2];
- r: runS[c;s];
- r: *($[(+/r)>0;r^0;0]);
- / u.ppr (c;r;a[2]);
- edge: (s=((#states) - 1))&(r=0);
- a[3] +: 1;
- :$[edge;e[a;c;r];ne[a;c;r]]
- };
- run: {[str]
- / u.ppr ("finding pattern in: ", str);
- // ((0),-1,0) -> 0: list of start/end indices, 1: active index, 2: state the machine stopped on, 3: idx
- o:((0),-1,0,0) {[a;c]
- // if activeidx = -1 => blk1
- // else blk2
- / u.ppr " ";
- :$[a[1]=-1;blk1[a;c];blk2[a;c]]
- }/str;
- :o
- };
- // 012345678901
- / u.ppr (run[" C1:C1-A1:A1"])
- \d .
|