|
const seg7_bcd = ([a, b, c, d, e, f, g]) => { |
|
const w = (a & b & f & g) | (!b & !c & e) | (!a & e); |
|
const x = (!a & b & g) | (a & !f & !g) | (a & !b); |
|
const y = (!b & e & g) | (!d & e) | (a & !f); |
|
const z = (!c & !d & g) | (c & !f) | (a & !e) | (!a & e); |
|
return [w, x, y, z]; |
|
}; |
|
|
|
const TRUTH_TABLE = [ |
|
["0000000", "0000", " "], |
|
["1111110", "0000", "0"], |
|
["0110000", "0001", "1"], |
|
["1101101", "0010", "2"], |
|
["1111001", "0011", "3"], |
|
["0110011", "0100", "4"], |
|
["1011011", "0101", "5"], |
|
["1011111", "0110", "6"], |
|
["1110000", "0111", "7"], |
|
["1111111", "1000", "8"], |
|
["1110011", "1001", "9"], |
|
["1110111", "1010", "A"], |
|
["0011111", "1011", "b"], |
|
["1001110", "1100", "C"], |
|
["0111101", "1101", "d"], |
|
["1001111", "1110", "E"], |
|
["1000111", "1111", "F"], |
|
] |
|
.map(([i, o, l]) => [i, o, l]) |
|
.map(([[a, b, c, d, e, f, g], [w, x, y, z], l]) => [ |
|
...[a, b, c, d, e, f, g, w, x, y, z].map(Number), |
|
l, |
|
]) |
|
.map(([a, b, c, d, e, f, g, w, x, y, z, l]) => ({ |
|
i: { a, b, c, d, e, f, g }, |
|
o: { w, x, y, z }, |
|
l, |
|
})); |
|
|
|
for (const { i, o, l } of TRUTH_TABLE) { |
|
const result = seg7_bcd(Object.values(i)); |
|
|
|
const comparison = result.every((v, i) => v === o[["w", "x", "y", "z"][i]]); |
|
|
|
console.log( |
|
`${comparison ? "✅" : "❌"} Letter ${l}: Input ${Object.values( |
|
i |
|
)} expected ${Object.values(o)} got ${result}` |
|
); |
|
} |