Repository navigation
Expand file tree
/
Copy pathlibpt24.js
More file actions
94 lines (77 loc) · 1.52 KB
/
Copy pathlibpt24.js
File metadata and controls
94 lines (77 loc) · 1.52 KB
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
function Expr(a, b, c, d) {
this.types = [
"fxfxfxx",
"fffxxxx",
"ffxxfxx",
"fxxffxx",
""
];
this.currentTypeIndex = 0;
this.fs = [];
var operators = ["+", "-", "*", "/"];
for (var i = 0; i < 4; i++) {
for (var j = 0; j < 4; j++) {
for (var k = 0; k < 4; k++) {
this.fs.push(operators[i] + operators[j] + operators[k])
}
}
}
this.currentFIndex = 0;
this.xarr = [a, b, c, d];
}
Expr.prototype.shiftType = function() {
if (this.currentTypeIndex == this.types.length) {
return false;
}
this.currentTypeIndex += 1;
return true;
}
Expr.prototype.reset = function(a, b, c, d) {
this.currentTypeIndex = 0;
this.currentFIndex = 0;
this.x = [a, b, c, d];
}
Expr.prototype.shiftOperators = function() {
if (this.currentFIndex == this.fs.length) {
return false; // not shiftable
}
this.currentFIndex += 1;
return true;
}
Expr.prototype.calc = function() {
var stack = [];
var currentType = this.types[this.currentTypeIndex];
var operators = this.fs[this.currentFIndex];
var f = 3;
var x = 4;
for (var i = 6; i >= 0; i--) {
switch (currentType[i]) {
case 'x':
stack.push(this.x[x]);
break;
case 'f':
var r = stack.pop();
var l = stack.pop();
stack.push(({ // todo : use if-else.
"+": l + r,
"-": l - r,
"*": l * r,
"/": l / r
})[operators[f]]);
}
}
}
Expr.prototype.toString = function(fmt) {
}
function calculateTree(tree) {
// {}
}
function findExpr(a, b, c, d) {
var e = new Expr(a, b, c, d);
while () {
while () {
while () {
}
}
}
}