Created
March 7, 2021 01:39
-
-
Save jdan/790cca61b165f7f2a480f1640839ad00 to your computer and use it in GitHub Desktop.
seven-segment.pl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
word(0, [0, 0, 0, 0]). | |
word(1, [0, 0, 0, 1]). | |
word(2, [0, 0, 1, 0]). | |
word(3, [0, 0, 1, 1]). | |
word(4, [0, 1, 0, 0]). | |
word(5, [0, 1, 0, 1]). | |
word(6, [0, 1, 1, 0]). | |
word(7, [0, 1, 1, 1]). | |
word(8, [1, 0, 0, 0]). | |
word(9, [1, 0, 0, 1]). | |
% count the nodes in the circuit | |
count(a, 1). | |
count(b, 1). | |
count(c, 1). | |
count(d, 1). | |
count(nand(L, R), C) :- | |
Cl #> 0, Cr #> 0, | |
C #= Cl + Cr, | |
count(L, Cl), count(R, Cr). | |
nand(0, 0, 1). | |
nand(0, 1, 1). | |
nand(1, 0, 1). | |
nand(1, 1, 0). | |
four_bit(A, a, A, _, _, _). | |
four_bit(B, b, _, B, _, _). | |
four_bit(C, c, _, _, C, _). | |
four_bit(D, d, _, _, _, D). | |
four_bit(R, nand(U, V), W, X, Y, Z) :- | |
four_bit(RU, U, W, X, Y, Z), | |
four_bit(RV, V, W, X, Y, Z), | |
nand(RU, RV, R). | |
a_segment(Circuit) :- | |
length(_, L), count(Circuit, L), | |
four_bit(0, Circuit, 0, 0, 0, 0), | |
four_bit(0, Circuit, 0, 0, 0, 1), | |
four_bit(1, Circuit, 0, 0, 1, 0), | |
four_bit(1, Circuit, 0, 0, 1, 1), | |
four_bit(0, Circuit, 0, 1, 0, 0), | |
four_bit(1, Circuit, 0, 1, 0, 1), | |
four_bit(1, Circuit, 0, 1, 1, 0), | |
four_bit(1, Circuit, 0, 1, 1, 1), | |
four_bit(1, Circuit, 1, 0, 0, 0), | |
four_bit(1, Circuit, 1, 0, 0, 1). | |
% ?- a_segment(Circuit). | |
% Circuit = nand(nand(a, a), nand(nand(a, a), nand(nand(b, d), nand(c, c)))) ; | |
% Circuit = nand(nand(a, a), nand(nand(a, a), nand(nand(c, c), nand(b, d)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment