logic-puzzles / README.md
jiteshkprasad's picture
Udgam Logic Puzzles v1: 92,507 puzzles, generator and checker
df805d1 verified
|
Raw History Blame Contribute Delete
13 kB
---
license: cc-by-4.0
language:
- en
pretty_name: Udgam Logic Puzzles
size_categories:
- 10K<n<100K
task_categories:
- question-answering
- text-generation
tags:
- udgamlabs
- logic
- reasoning
- puzzles
- synthetic
- procedurally-generated
- verifiable-rewards
configs:
- config_name: default
data_files:
- split: train
path: data/train.parquet
- split: test
path: data/test.parquet
---
![Logic Puzzles · Udgam Labs](./banner.png)
**UDGAM LABS** · Dataset · 92,507 puzzles
# Udgam Logic Puzzles
92,507 logic and reasoning puzzles in 17 families (knights and knaves, height orderings, zebra houses,
cryptarithms, water jugs, knight moves, task schedules, calendars and more), each with one short answer that can be
checked by exact match. Every question and every answer was produced by a Python program; no language model was used
to write, solve or filter the puzzles. The generator is included, so you can make as many more as you need. Built for reinforcement learning
with checkable rewards and for testing small models.
| | |
|---|---|
| Puzzles | 90,807 train, 1,700 test (100 per family); no question appears twice |
| Families | 17 |
| Answer | a number, a name, a weekday or a comma-separated list of names |
| Checks | a second, independent program re-solved all 92,507 from the question text alone: 100% agreement |
| Licence | data CC-BY-4.0; code (generator and checker) Apache-2.0 |
## Quick start
```python
from datasets import load_dataset
ds = load_dataset("udgamlabs/logic-puzzles")
row = ds["test"][0]
print(row["family"], row["question"], row["answer"], sep="\n")
```
Grading a model's reply (copy `is_correct` from `logic_puzzles.py` in this repo; it needs only the standard library):
```python
from logic_puzzles import is_correct # download logic_puzzles.py from this repo first
is_correct("lars,ana.", "Lars, Ana") # True: case, spacing, quotes and a final full stop are ignored
is_correct("17.50", "17.5") # True: numbers compare by value
is_correct("Ana, Lars", "Lars, Ana") # False: order matters where the question asks for an order
```
Extract the final answer from the reply first (for example, ask for it on a last line `Answer: ...`). Each question
says what form the answer takes ("Answer with the number only", "in alphabetical order, comma-separated", and so on).
## The 17 families
| Family | What it asks | How the answer is computed | Train | Test |
|---|---|---|---:|---:|
| `knights_knaves` | Who are the knights, given what each islander says? | every truth assignment tried; exactly one fits | 6,000 | 100 |
| `height_order` | Order 4 to 6 people by height from pairwise clues | every order tried; exactly one fits | 6,000 | 100 |
| `grid_paths` | Count right/down paths through a grid with blocked cells | dynamic programming | 6,000 | 100 |
| `variable_chain` | Value of a variable defined through a shuffled chain of definitions with distractors | direct evaluation | 6,000 | 100 |
| `calendar` | Weekday of a date, or the number of days between two dates | calendar arithmetic with leap years | 6,000 | 100 |
| `water_jugs` | Fewest fill, empty and pour steps to measure a volume with two jugs | breadth-first search over jug states | 187 | 100 |
| `cryptarithm` | Letter-for-digit addition: what number is the sum? | every digit assignment tried; exactly one fits | 6,000 | 100 |
| `shortest_route` | Shortest road distance between two towns | Dijkstra's algorithm | 6,000 | 100 |
| `venn` | Two or three overlapping groups: how many like none, or only one | inclusion-exclusion | 6,000 | 100 |
| `number_sequence` | Next number of a sequence | the rule that built it (one of six kinds) | 6,000 | 100 |
| `clock_angle` | Smaller angle between the hands of a clock | exact arithmetic | 620 | 100 |
| `task_schedule` | Shortest time to finish tasks with prerequisites, run in parallel | critical path | 6,000 | 100 |
| `ages` | One person's age from a sum of ages and a past or future ratio | every pair of ages tried; exactly one fits | 6,000 | 100 |
| `digit_count` | How many numbers can be made from given digits under a condition | exhaustive count | 6,000 | 100 |
| `knight_moves` | Fewest knight moves on a small board with forbidden squares | breadth-first search | 6,000 | 100 |
| `zebra` | Houses in a row: who owns, drinks or lives where, from clues | every arrangement tried; clues added until one fits | 6,000 | 100 |
| `balance_scale` | Chain two balance-scale equalities into a third | exact ratios | 6,000 | 100 |
Some families have only a few hundred distinct puzzles at these settings, so they have fewer rows (see *Where it falls
short*). Three examples from the test split:
> **knights_knaves** · On an island, knights always tell the truth and knaves always lie. Juan says: "Prakash is a knight." Carlos says: "Lakshmi and I are different kinds." Lakshmi says: "Carlos and I are the same kind." Prakash says: "Juan and I are different kinds." Who are the knights? Answer with their names in alphabetical order, comma-separated, or 'none'.
> Answer: `Carlos`
> **water_jugs** · You have an empty 5-litre jug and an empty 8-litre jug, and a tap. In one step you can fill a jug completely, empty a jug completely, or pour from one jug into the other until the first is empty or the second is full. What is the smallest number of steps needed to have exactly 1 litres in one of the jugs? Answer with the number only.
> Answer: `8`
> **task_schedule** · A project has these tasks: task A takes 3 hours; task B takes 5 hours; task C takes 6 hours; task D takes 1 hours and can start only after A is finished; task E takes 5 hours. Any number of tasks can run at the same time. What is the shortest time, in hours, to finish the whole project? Answer with the number only.
> Answer: `6`
## What we checked
- **Every answer, twice.** The generator computes each answer while it builds the puzzle. A second program,
`verify.py`, written separately and not importing the generator, parses only the question text and solves it again,
often with a different method (Floyd-Warshall instead of Dijkstra, listing every grid path instead of dynamic
programming, algebra instead of search for ages, counting every number instead of combining digits). It agrees with
the published answer on **92,507 of 92,507** puzzles. Run `python verify.py data/train.parquet
data/test.parquet` to repeat this. To test the checker itself, we changed every answer in a 5,087-puzzle sample; it
rejected all 5,087.
- **One answer per puzzle.** For the families where a second solution could exist (knights and knaves, height orders,
zebra houses, cryptarithms, ages), both programs search all possibilities and keep a puzzle only if exactly one
solution fits. For number sequences, the checker tries six kinds of rule (constant difference, constant second
difference, sum of the previous two, multiply-and-add, constant ratio, two interleaved sequences); on every puzzle,
all rules that fit the shown terms predict the same next number.
- **Exact match works.** All answers are short canonical strings: integers (70,403), lists of names (10,437), single names (6,100), weekdays (3,084), the word `none` (1,763), decimal or whole numbers (clock angles) (720). The longest answer is
47 characters.
- **No duplicates, no leaks between splits.** Each question text appears once in the whole dataset; no test question
appears in train.
- **Overlap with public benchmarks.** We compared every question with BIG-Bench Hard (all 27 tasks), the Knights and
Knaves benchmark and ZebraLogic, which use similar puzzle types. No question matches a benchmark item, and none shares a run of 13 words with one (the standard contamination test). The only shared 8-word runs are stock phrases such as "knights always tell the truth and knaves always lie" and "numbered 1 to 4 from left to right".
- **Secret scan.** Every file and every text cell was scanned for credentials, keys and email addresses: none found.
## Where it falls short
- **Templates, not free text.** Each family uses one fixed wording. Variety comes from the numbers, names and structure,
not the phrasing, so a model can learn the template rather than the skill. Paraphrase the questions if you need
robustness to wording.
- **Some families are small.** At these settings there are only 287 distinct water-jug puzzles (100 test, 187 train)
and about 720 clock-angle puzzles; number sequences repeat often for some rule kinds. A model can memorise these
families; read their test scores with that in mind.
- **Modest and unlabelled difficulty.** Puzzles are small (3 to 6 people, grids up to 6 by 6, up to 8 tasks, boards up
to 8 by 8). They separate small models but are easy for large ones, and there is no difficulty label. Raise the
ranges in the generator for harder puzzles.
- **Answers only, no worked solutions.** There is no step-by-step reasoning. For supervised fine-tuning you need to
write or sample solutions yourself and keep the ones whose final answer matches.
- **Sequences assume a simple rule.** "Next number" puzzles follow one of six simple rules, and our checker found no
puzzle where two of those rules disagree. Some other rule could still fit the shown terms.
- **Exact match is strict.** `is_correct` forgives case, spacing, quotes, a final full stop and number formatting, but
not other wording ("Lars and Ana" is marked wrong). Ask for the answer in the stated form.
- **Look-alike benchmarks.** Public benchmarks such as BIG-Bench Hard (date understanding, logical deduction, web of
lies), Knights and Knaves and ZebraLogic test similar skills. Training on this data can raise scores there without an
equal gain in general reasoning; say so when you report such scores.
- **English only.** Names come from a list of 197 first names from many cultures.
## How it was made
`logic_puzzles.py` holds one function per family. Each draws random parameters, builds the puzzle text from a
template, computes the answer by exhaustive search, breadth-first search, dynamic programming or exact arithmetic, and
discards draws that do not give a well-posed puzzle (for example, clues that allow two orders). Each family has its own
random stream, seeded by a string and the family name, so the same seed always gives the same puzzles on any machine.
`make_release.py` rebuilds these exact files: the test split first (100 per family, seed
`udgam-logic-puzzles-v1/test`), then the train split (up to 6,000 per family, seed `udgam-logic-puzzles-v1/train`),
skipping any question already used. A family stops early when 3,000 draws in a row give nothing new.
### Make more
```bash
python logic_puzzles.py --seed my-seed --per-family 1000 --out more.jsonl
python logic_puzzles.py --seed my-seed --per-family 500 --families zebra,cryptarithm --out hard.jsonl
python verify.py more.jsonl # optional: re-solve every new puzzle independently
```
Standard library only, Python 3.9 or newer. Use a new seed to get puzzles that are not in this dataset (questions can
still repeat by chance in the small families; drop any that appear here if you need a clean held-out set).
### Fields
| Field | Type | Meaning |
|---|---|---|
| `id` | string | family name and the first 12 hex characters of the SHA-256 of the question |
| `family` | string | one of the 17 family names above |
| `question` | string | the puzzle, including the form the answer must take |
| `answer` | string | the one correct answer, in canonical form |
| `answer_type` | string | `integer`, `number`, `weekday`, `name`, `names` or `none` |
## Intended use and limitations
Use it to train or test reasoning with rewards that a program can check: reinforcement learning with verifiable rewards,
rejection sampling, curricula of growing difficulty, or a quick held-out test of small models (the test split). Do not
use scores on it alone as evidence of general reasoning ability; the families are narrow and templated.
## Licence
The puzzles (the files in `data/`) are licensed under
[CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/): reuse them for any purpose, including commercial, with
attribution to "Udgam Logic Puzzles by Udgam Labs". The code (`logic_puzzles.py`, `verify.py`, `make_release.py`) is
licensed under Apache-2.0 (see `LICENSE-CODE`).
## Citation
```bibtex
@misc{udgamlabs2026logicpuzzles,
title = {Udgam Logic Puzzles: 17 families of generated logic puzzles with exactly checkable answers},
author = {Prasad, Jitesh K and {Udgam Labs}},
year = {2026},
howpublished = {\url{https://huggingface.co/datasets/udgamlabs/logic-puzzles}}
}
```
---
**About Udgam Labs.** Udgam Labs is an independent AI research lab. We work from first principles: before we build, we understand why things work, whether we are training a model, fine-tuning one or applying AI to a new problem. Udgam (उद्गम) is Sanskrit for origin. [udgamlabs.com](https://udgamlabs.com)