-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsheets script.gs
99 lines (91 loc) · 2.57 KB
/
sheets script.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function myFunction() {
sheet=SpreadsheetApp.getActiveSpreadsheet()
var cell = sheet.getRange('B1');
sheet.getRange('B1:CU1').setValue(0);
sheet.getRange('c1:CU1').setBackground("LightGrey");
sheet.getRange('B1').setBackground("Red")
var out = sheet.getRange('G3');
sheet.getRange("B5").setValue(sheet.getRange("B3").getValue())
var inp = sheet.getRange("B5")
code = sheet.getRange("B2").getValue()
out.setValue("")
opPtr =-1
while(code.length>opPtr){
if(cell.getValue()=="#NUM!"){
cell.setValue("0")}
opPtr++
op = code.substring(opPtr,opPtr+1)
if(opPtr >code.length){
break}
switch(op) {
//--------------index move--------------
case ">":
cell.setBackground("lightGrey")
cell = cell.offset(0, 1)
cell.setBackground("red")
break;
case "<":
try{
if(cell==sheet.getRange('A1')){
continue}
if(cell.getValue()=="Data:"){
out.setValue("ERROR")
return
}
cell.setBackground("LightGrey ")
cell = cell.offset(0, -1)
cell.setBackground("red")
}catch(e){
out.setValue("TOO LOW")
}
break;
//--------------change data--------------
case "+":
cell.setValue((cell.getValue()+1))
break;
case "-":
if(cell.getValue()<0){
//out.setValue("Below 0")
}else{
cell.setValue((cell.getValue()-1))
}
break;
//--------------input output--------------
case ".":
out.setValue(out.getValue()+""+(String.fromCharCode(cell.getValue())))
break;
case ",":
if(inp.getValue().length==0){
break
}
cell.setValue(inp.getValue().charCodeAt(0))
inp.setValue(inp.getValue().substring(1,inp.getValue().length))
break;
//--------------logic--------------
case "[":
try{
if (cell.getValue() ==0){
opPtr = code.indexOf("]",opPtr)
}
}catch(e){
out.setValue("No ]")
}
break;
case "]":
try{
if(cell.getValue() !=0){
opPtr = code.lastIndexOf("[",opPtr)
}
}catch(e){
out.setValue(e)
}
break;
}
if(sheet.getRange('A1').getValue() != "Data:"||cell==sheet.getRange('CT1')||sheet.getRange('CU1').getValue()!=0){
out.setValue("ERROR")
break
}else if(sheet.getRange('A1') == cell){
cell = cell.offset(0, 1)
}
}
}