Write a program or a function that accepts the list of outputs from a logic function and outputs the LaTeX code for its truth table.
The inputs should be labeled as lowercase letters a-z
, and the output should be labelled as F
. The length of list of inputs will always be shorter than 2^25
, which means that number of inputs will always be less than 25, so you can use letters from lowercase alphabet for input names.
Input
A number n
of inputs and list of length 2^n
of binary numbers which represents the outputs of a logical function.
Output
LaTeX code that produces the truth table for that function. Input and output values should be centered in rows. There must be a line between table header and its values and between inputs and output, so the code should be similar to that below.
\begin{tabular}{c * <NUMBER OF INPUTS>|c}
<INPUTS>&F\\
\hline
<INPUT VECTOR i>&<OUTPUT>\\
\end{tabular}
Example
Input:
2
[0, 0, 0, 1]
Output:
\begin{tabular}{cc|c}
a & b & F \\
\hline
0 & 0 & 0 \\
0 & 1 & 0 \\
1 & 0 & 0 \\
1 & 1 & 1 \\
\end{tabular}
Which when displayed in LaTeX shows the following truth table
General rules
- This is code-golf, so shortest answer in bytes wins.
- Default Loopholes are forbidden.
ccccc
instead ofcc
, but leave|c
alone... And yes, in this table, all spaces and newlines are optional, but I would avoid blank lines. \$\endgroup\$