Truth tables: How can I fill a table with auto generated data (inputs) and data from an array (output)?

Hello, I’m sorry for the confusing title.
I’m currently building a function to display truth tables for a school project. I’m giving the function the following data:

#truthTable(
  inputs: ("A", "B"),
  outputs: ("Y": (0,1,1,0))
)

The output shoud lock like this:
image
to geet the doubleline, i found the best why is to

    table.vline(x:input.len()-1, position: right),
    table.vline(x:input.len(), position: left),

Setting the column-gutter in between output and input higher.
Is there a better why?

I’m currently stuck with displaying the date (output and binary cout)

Would love some help
Thanks Sam

Hello. Have you looked at truthfy – Typst Universe? There is no best way at the moment, but in certain situations gutter hack is probably the perfect workaround. Double lines and tables: a feature request?

#let generate-binary-columns(n) = {
  let ith-row = i => ("0" * (n - 1) + str(i, base: 2)).slice(-n)
  let rows = range(calc.pow(2, n)).map(ith-row).map(row => row.clusters())
  array.zip(..rows)
}

#let truth-table(inputs: (:), outputs: (:)) = table(
  columns: inputs.len() + outputs.len(),
  column-gutter: 3pt,
  stroke: none,
  table.hline(y: 1),
  table.vline(x: inputs.len() - 1, position: right),
  table.vline(x: inputs.len(), position: left),
  ..array
    .zip(
      ..inputs
        .enumerate()
        .map(((i, x)) => (x, ..generate-binary-columns(inputs.len()).at(i))),
      ..outputs.pairs().map(x => x.flatten().map(str)),
    )
    .enumerate()
    .map(((i, row)) => if i == 0 { table.header(..row) } else { row })
    .flatten()
)

#truth-table(inputs: ("A", "B"), outputs: ("Y": (0, 1, 1, 0)))

So what’s up with the title? If you are just asking about table double line, then it’s a duplicate of Double lines and tables: a feature request?.

Hi @Sam1, welcome and thank you for your question! I have changed your post’s title to hopefully give a better overview of your problem. If you don’t think it fits, feel free to edit it again or message me.
Also, if you feel the response you got has sufficiently answered your question, be sure to give it a checkmark :ballot_box_with_check:. This will help others find the solution in the future. If something is missing, please let us know what so we can resolve your issue. Thanks!