# Constraint-satisfaction logic puzzle — Claude XML example

> Solve a puzzle by enumerating constraints inside <thinking> and concluding in <answer>.
>
> Source: https://claudexml.com/examples/logic-puzzle/ · Last updated 2026-05-25

Home / Examples / Constraint-satisfaction logic puzzle
    Reasoning · intermediate

# Constraint-satisfaction logic puzzle

    Solve a puzzle by enumerating constraints inside <thinking> and concluding in <answer>.

    Zebra-style puzzles, scheduling problems, or any task that needs explicit constraint tracking.


## The prompt

    Copy this verbatim. Replace the `{{ … }}` placeholders with your values.


```xml
<instructions>
Solve the puzzle. Inside <thinking>:
1. List the entities and possible values.
2. List each constraint explicitly.
3. Deduce, eliminating possibilities; note any branches you tried.

Inside <answer>, give the final assignment as a JSON object.
</instructions>

<puzzle>{{ puzzle_text }}</puzzle>
```


## Sample input


```xml
Three friends — Alex, Blair, Casey — each ordered a different drink (coffee, tea, juice). Alex didn't order coffee. Blair didn't order tea. Casey ordered tea. What did each person order?
```


## Expected output


```xml
<thinking>
Entities: {Alex, Blair, Casey} → drinks {coffee, tea, juice}.
Constraints: Alex ≠ coffee; Blair ≠ tea; Casey = tea.
With Casey = tea, remaining {coffee, juice} for {Alex, Blair}.
Alex ≠ coffee → Alex = juice → Blair = coffee.
</thinking>
<answer>
{ "Alex": "juice", "Blair": "coffee", "Casey": "tea" }
</answer>
```


## Notes & tuning tips


- Numbered procedure beats free-form reasoning — Claude follows the structure.
- JSON-in-answer makes downstream verification trivial.
- For larger constraint problems (10+ entities), prefer a real solver (Z3, MiniZinc) called via tool use.


## What this example uses

    Tags: <instructions> <thinking> <answer>

    Patterns: chain of thought structured output


## More like this


      reasoning
### Chain-of-thought math word problem
Reason step-by-step inside <thinking>, isolate the final number in <answer>.

      reasoning
### Natural language → SQL with a schema
Translate plain-English questions into SQL against a provided schema. Few-shot.

      reasoning
### Code review with severity levels
Review a diff and produce structured findings (bug, perf, style) with severities.




Cite this page

`Constraint-satisfaction logic puzzle. claudexml.com. https://claudexml.com/examples/logic-puzzle/`
