> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/d/decision_tables.md).

# Decision tables

```ruby
func decide (q, s) {

    var bits = q.map { |p|
        read("#{p.value}? ", String) ~~ /^y/i ? 1 : 0
    }

    var n = with (0) { |t|
        bits.each { |b|
            t <<= 1
            t |= b
        }
        1 << t
    }

    s.grep { .key & n }.map{ .value }.each { |ans|
        say "   #{ans}"
    }
}

loop {
    decide(
      [
        Pair("Y Y Y Y N N N N", "Printer does not print"),
        Pair("Y Y N N Y Y N N", "A red light is flashing"),
        Pair("Y N Y N Y N Y N", "Printer is unrecognised"),
      ],
      [
        Pair(0b0_0_1_0_0_0_0_0, "Check the power cable"),
        Pair(0b1_0_1_0_0_0_0_0, "Check the printer-computer cable"),
        Pair(0b1_0_1_0_1_0_1_0, "Ensure printer software is installed"),
        Pair(0b1_1_0_0_1_1_0_0, "Check/replace ink"),
        Pair(0b0_1_0_1_0_0_0_0, "Check for paper jam"),
      ]
    )
    say ''
}
```

## Output:

```
Printer does not print? y
A red light is flashing? n
Printer is unrecognised? n
   Check for paper jam

Printer does not print? n
A red light is flashing? n
Printer is unrecognised? y
   Ensure printer software is installed

Printer does not print? y
A red light is flashing? y
Printer is unrecognised? n
   Check/replace ink
   Check for paper jam

Printer does not print? n
A red light is flashing? y
Printer is unrecognised? y
   Ensure printer software is installed
   Check/replace ink

Printer does not print? ^C
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/d/decision_tables.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
