-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogic-function.js
More file actions
63 lines (43 loc) · 1.19 KB
/
Copy pathlogic-function.js
File metadata and controls
63 lines (43 loc) · 1.19 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
//const f1 = (d, c, b, a) => !a && !c && d || b && !c && !d || !a && b && !c || !a && b && d || a && c && !d || a && !b && c || a && !b && !d;
const f1 = (d, c, b, a) => {
return (
!d * !c * !b * !a +
// !d * !c * !b * a +
!d * !c * b * !a +
!d * !c * b * a +
// !d * c * !b * !a +
!d * c * !b * a +
!d * c * b * !a +
!d * c * b * a +
d * !c * !b * !a +
d * !c * !b * a
) ? 1 : 0;
}
const f2 = (d, c, b, a) => {
return (a && c || b || d || !a && !c) ? 1 : 0;
}
// or(
// and(!a, !c, d),
// and(b, !c, !d),
// and(!a, b, d),
// )
const table = binTable(16)
const res1 = table.map(vals => f1(...vals));
const res2 = table.map(vals => f2(...vals));
console.log(table)
console.log(res1)
console.log(res2)
for (let i = 0, I = table.length; i < I; i++) {
console.log(`${i}: ${table[i].join(' ')}` )
}
function binTable(size) {
const table = [];
const padSize = (size - 1).toString(2).length;
for (let i = 0; i < size; i++) {
table.push(i.toString(2)
.padStart(padSize, '0')
.split('')
.map(x => +x));
}
return table;
}