Bläddra i källkod

digit/letter finders

Will 4 månader sedan
förälder
incheckning
4a2a604674
18 ändrade filer med 110 tillägg och 174 borttagningar
  1. 21 0
      MyApp.k
  2. 3 0
      SS.csv
  3. 30 0
      SS.k
  4. 7 0
      SStest.k
  5. 0 0
      compiled_ss.k
  6. 0 80
      compiler.k
  7. 0 3
      fname
  8. 10 0
      hint.csv
  9. 0 1
      st.k
  10. 19 0
      tST.k
  11. 0 16
      tempDT.k
  12. 0 25
      tempST.csv
  13. 0 8
      tempST.k
  14. 0 1
      test
  15. 0 20
      test.k
  16. 0 20
      testST.k
  17. 12 0
      uDT.k
  18. 8 0
      vSS.k

+ 21 - 0
MyApp.k

@@ -0,0 +1,21 @@
+// We'll only use tST - tST itself will use other tables
+\l tST.k
+
+balance: 0; // amount of money inserted
+selection: 0; // selection - 0 is no selection
+dispensed: 0; // 1 if machine has dispensed successfully
+cancelBtn: 0; // 1 if user pressed cancel button
+
+// 1. money inserted
+balance+: 3;
+
+// tST -> start selecting, na: next action
+na: tST[(balance;selection;dispensed;cancelBtn);0N]; // 0N no args // This will update the state
+na[];
+
+// 2. select item
+selection: 1;
+na: tST[(balance;selection;dispensed;cancelBtn);0N];
+na[];
+
+// Here the machine must have dispensed, the stocks SS updated and machine is back to Idle again

+ 3 - 0
SS.csv

@@ -0,0 +1,3 @@
+price,coin1,+/self[;1],"""balance"""
+,coin2,self[2;0]-self[0;0],"""Remaining after purchase"""
+,coin3,self[2;2]>=0,"""Anything to return?"""

+ 30 - 0
SS.k

@@ -0,0 +1,30 @@
+/helpers
+/ e exclusive
+slice: {[l;s;e] s_(e-1)#l};
+listize: {1_(,/(";",)'{"(",x,")"}'x)};
+iscl: {i: `i$x; ((i>64) & (i<91))}; // is capital letter
+isdig: {i: `i$x; ((i>47) & (i<58))}; // is digit
+/ :`i$"A"; // 65
+/ :`i$"Z"; // 90
+/ :`i$"0"; // 48
+/ :`i$"9"; // 57
+
+tstkey: "States/Events"; / key indicating start of transition section
+cstkey: "Events"; / key indicating start of events condition section
+astkey: "Actions"; / key indicating start of actions section
+sectionkeys: (tstkey;cstkey;astkey);
+
+lines: 0: "SS.csv";
+
+/csv parser
+parsel: {[l] comi: &l=",";comi+:1;r: 2':!#comi;r: comi@r;r: (1 2#(0;r[0;0])),r;slice[l].'r};
+csv: parsel'lines;
+
+:letters: &''(iscl'''csv);
+:digits: &''(isdig'''csv);
+
+csv@''letters
+
+/ initialize data
+/ f:<`"compiled_ss.k";
+/ f 0: kcode;

+ 7 - 0
SStest.k

@@ -0,0 +1,7 @@
+hasloops: {deps:&'x; d:deps; #,/((#deps)(,/'deps@)/d)>0};
+order: {deps: {$[+/x>0;&x;()]}'x; ?,/deps};
+
+dm: ((0 0 0 0 0);(1 0 0 0 0);(0 0 0 0 1);(1 1 0 0 0);(0 0 1 1 0));
+
+:hasloops[dm];
+:order[dm];

+ 0 - 0
compiled_ss.k


+ 0 - 80
compiler.k

@@ -1,80 +0,0 @@
-/helpers
-/ e exclusive
-slice: {[l;s;e] s_(e-1)#l};
-listize: {1_(,/(";",)'{"(",x,")"}'x)};
-
-tstkey: "States/Events"; / key indicating start of transition section
-cstkey: "Events"; / key indicating start of events condition section
-astkey: "Actions"; / key indicating start of actions section
-sectionkeys: (tstkey;cstkey;astkey);
-
-lines: 0: "tempST.csv";
-
-/csv parser
-parsel: {[l] comi: &l=",";comi+:1;r: 2':!#comi;r: comi@r;r: (1 2#(0;r[0;0])),r;slice[l].'r};
-tempST: parsel'lines;
-tname: tempST[0;0];
-
-/ st compile
-/ separate sections
-si: (*'&'{(y~)'x}[*'tempST]'sectionkeys),(#tempST-1); / sections line numbers
-slices: si@(2':!#si);
-(t;c;a):1_'slice[tempST;] .'slices;
-
-/ postprocess sections
-s:*'t;
-t:2_'t;
-a:*'a;
-c:*'c;
-
-/ TODO: make dynamic
-args: `isOff `T ! `i `i;
-
-fname: tname,".k";
-kcode: "/ ",fname,".csv compiled\n\n";
-tstr: "";
-
-/a TODO: make dynamic
-avars: ("A",'$((!#a)+1))
-a:,[;"\"};\n"]'((,[;":{\""]'avars),'a);
-a: ,/a;
-avars: 1_,/(";",'avars);
-
-/c
-vars: {x,":args["}'$'!args;
-cargs:,[;"];"]'(vars,'($!#vars));
-cargs: ,/cargs;
-c:"{[args]",cargs,"(",listize[c],")}";
-
-/s
-s:,[;"\""]'("\"",'s);
-s:listize[s];
-
-/at
-at: ,/("`",'$:args@!args);
-
-/ t
-t:listize[listize't];
-
-kcode ,: a;
-kcode ,: ("a:(",avars,");\n");
-kcode ,: ("c:",c,";\n");
-kcode ,: ("s:(",s,");\n");
-kcode ,: ("t:(",t,");\n");
-kcode ,: ("at:",at,";\n");
-
-
-/ initialize data
-f:<`"tempST.k";
-f 0: kcode;
-
-/ -======== notes ========-
-/ / how the parser works
-/ t: lines[0];
-/ comi: &t=","; / commas idx
-/ comi+:1; / help exlude commas (later use -1 on upper)
-/
-/ r: 2':!#comi; / ranges of comma separated parts
-/ r: comi@r; / apply ranges to comma idx
-/ r: (1 2#(0;r[0;0])),r; / add 0-first comma range
-/ slice[t].'r

+ 0 - 3
fname

@@ -1,3 +0,0 @@
-/ tempST.k.csv compiled
-
-

+ 10 - 0
hint.csv

@@ -0,0 +1,10 @@
+Cell,Formula,Description
+A1,=SUM(B1:B10),Total balance
+A2,=A1 - C1,Remaining balance
+B1,[Input from coin slot],Inserted coin value
+C1,[Selected item price],Price of the selected item
+D1,=IF(A2>=0; A2; 0),Change to return
+E1,=SUM(F1:F10),Total sales
+F1,=IF(G1>0; C1; 0),Sale amount for item 1
+G1,[Stock for item 1],Current stock of item 1
+H1,=G1 - IF(F1>0; 1; 0),Updated stock after dispensing

+ 0 - 1
st.k

@@ -1 +0,0 @@
-evalST: {[args] (c;a;t;args):args; eidx:*&c[args]; ts: t[0;eidx]; (a[ts[0]];ts[1])};

+ 19 - 0
tST.k

@@ -0,0 +1,19 @@
+// tST.k -> State Table Definition
+\l uDT.k
+
+err: {:"err";};
+
+tSTAt: (
+ ((1 2);(0N 1);(err 1);(0N 1));
+ ((0N 2);(2 3);(err 1);(3 1));
+ ((0N 3);(0N 3);(3 1);(0N 3))
+);
+
+// sample actions - These should be DTs in a real example
+tSTA1:: {:"Start Selecting\n";};
+tSTA2:: uDT; // this is an actual DT
+tSTA3:: {:"Finished\n";};
+tSTa:: (tSTA1;tSTA2;tSTA3);
+
+tSTs:: 0;
+tST: {[e;args] };

+ 0 - 16
tempDT.k

@@ -1,16 +0,0 @@
-/ tempDT.k.csv compiled
-tempDTat: `i`i
-
-tempDT: {[args]
- cr:((1 0N 0 0N 0);(0 1 0 0N 0);(0 0 1 0 0N);(1 1 1 0 0);(1 0 0 1 0);(0 0 1 0 1);(0 0 0 0 0));
- R1:{heater[1];ac[0];};
- R2:{heater[0];ac[0];};
- R3:{heater[0];ac[1];};
- R4:{heater[1];ac[0];};
- R5:{heater[0];ac[1];};
- r:(R1;R2;R3;R4;R5);
- c:(args[0]<20;args[0]<26;args[0]>25;args[1]=0;args[1]=1;args[1]=2);
- cr@&c
-};
-
-tempDT[(0 0)]

+ 0 - 25
tempST.csv

@@ -1,25 +0,0 @@
-tempST,State Table,,,,,,,
-States/Events,,E1,E2,E3,E4,E5,E6,
-Off,S1,0N 1,4 5,1 2,2 3,3 4,5 6,
-FanLow,S2,6 1,4 5,0N 2,2 3,3 4,5 6,
-FanMedium,S3,6 1,4 5,1 2,0N 3,3 4,5 6,
-FanHigh,S4,6 1,4 5,1 2,2 3,0N 4,5 6,
-Heating,S5,6 1,0N 5,1 2,2 3,3 4,5 6,
-Cooling,S6,6 1,4 5,1 2,2 3,3 4,0N 6,
-Events,,,,,,,,
-isOff,E1,,,,,,,
-T < 18,E2,,,,,,,
-T < 22,E3,,,,,,,
-T < 26,E4,,,,,,,
-T < 30,E5,,,,,,,
-T > 30,E6,,,,,,,
-Actions,,,,,,,,
-setFan[`l],A1,,,,,,,set fan to low
-setFan[`m],A2,,,,,,,// to medium
-setFan[`h],A3,,,,,,,// to high
-heaterPower[1],A4,,,,,,,
-ACPower[1],A5,,,,,,,
-allPower[0],A6,,,,,,,
-next,A7,,,,,,,
-exit,A8,,,,,,,
-error,A9,,,,,,,

+ 0 - 8
tempST.k

@@ -1,8 +0,0 @@
-/ tempST.k.csv compiled
-tempSTs:(("Off");("FanLow");("FanMedium");("FanHigh");("Heating"));
-tempSTat:`i`i;
-tempSTstate: 0;
-
-tempST: {[args] isOff:args[0]; T:args[1]; c:((isOff);(T < 18);(T < 22);(T < 26);(T < 30)); a:("fan low";"fan med";"fan hig";"heat on"; "ac on"; "all off"; "next"; "exit"; "err"); t:(((0N 1);(4 5);(1 2);(2 3);(3 4);(5 6));((6 1);(4 5);(0N 2);(2 3);(3 4);(5 6));((6 1);(4 5);(1 2);(0N 3);(3 4);(5 6));((6 1);(4 5);(1 2);(2 3);(0N 4);(5 6));((6 1);(0N 5);(1 2);(2 3);(3 4);(5 6))); eidx: *&c; ts: t[args[2];eidx]; (a[ts[0]];ts[1])};
-
-tempST[(0;0;tempSTstate)]

+ 0 - 1
test

@@ -1 +0,0 @@
-tempST.k

+ 0 - 20
test.k

@@ -1,20 +0,0 @@
-/ example compiled tempST
-/ compiled table into data
-/ calling evalST and passing 
-/ the data generated by tempST
-/ will be passed to evalST
-/ to get executable action
-
-/ Actions
-A1: {[] "fan low"};
-A2: {[] "fan med"};
-A3: {[] "fan hig"};
-A4: {[] "heat on"};
-A5: {[] "acpw on"};
-A6: {[] "allp of"};
-
-// condition vector, action vector, transition table, args types
-c: {[T;isOff] (isOff;T<18;T<22;T<26;T<30;T>30)};
-a: A1 A2 A3 A4 A5 A6;
-t: (((0N;1);(4;5);(1;2);(2;3);(3;4);(5;6));((6;1);(4;5);(0N;2);(2;3);(3;4);(5;6));((6;1);(4;5);(1;2);(0N;3);(3;4);(5;6));((6;1);(4;5);(1;2);(2;3);(0N;4);(5;6));((6;1);(0N;5);(1;2);(2;3);(3;4);(5;6));((6;1);(4;5);(1;2);(2;3);(3;4);(0N;6)));
-at: (`i;`i;`i);

+ 0 - 20
testST.k

@@ -1,20 +0,0 @@
-/ example compiled tempST
-/ compiled table into data
-/ calling evalST and passing 
-/ the data generated by tempST
-/ will be passed to evalST
-/ to get executable action
-
-/ Actions
-A1: {[] "fan low"};
-A2: {[] "fan med"};
-A3: {[] "fan hig"};
-A4: {[] "heat on"};
-A5: {[] "acpw on"};
-A6: {[] "allp of"};
-
-// condition vector, action vector, transition table, args types
-c: {[T;isOff] (isOff;T<18;T<22;T<26;T<30;T>30)};
-a: A1 A2 A3 A4 A5 A6;
-t: (((0N;1);(4;5);(1;2);(2;3);(3;4);(5;6));((6;1);(4;5);(0N;2);(2;3);(3;4);(5;6));((6;1);(4;5);(1;2);(0N;3);(3;4);(5;6));((6;1);(4;5);(1;2);(2;3);(0N;4);(5;6));((6;1);(0N;5);(1;2);(2;3);(3;4);(5;6));((6;1);(4;5);(1;2);(2;3);(3;4);(0N;6)));
-at: (`i;`i);

+ 12 - 0
uDT.k

@@ -0,0 +1,12 @@
+\l vSS.k
+
+// uDT.k -> Decision Table
+uDTr: (
+ (1 0 1);
+ (0 1 0N);
+ (1 0N 0);
+ (0 0N 1)
+);
+uDTR1: {[e;args] selection:e[1]; stock:args[0]; :"dispense"; vSS[selection;]}
+
+uDT: {[e;args]};

+ 8 - 0
vSS.k

@@ -0,0 +1,8 @@
+// vSS.k -> Spread Sheet
+vSSHead:: `name`price`stock;
+vSSData:: +`chips`candy`pepsi!((1;5);(3;5);(2;5));
+
+vSSUpdateDeps: {[]}; // updates dependencies (no deps in this SS)
+
+// This will update the value going through the dependency table
+vSS: {[idx;nv] vSSData[idx]: nv;};