# Sudoku & Star Battle Puzzle Generator (unique, graded) (`ars-technis/logic-puzzle-generator`) Actor

Generates original sudoku and Star Battle puzzles, each proven to have exactly one solution and graded easy to expert by the techniques a logic solver needs. JSON, optional SVG, printable worksheets, or a 6x9 / 8.5x11 paperback book interior PDF with answer key.

- **URL**: https://apify.com/ars-technis/logic-puzzle-generator.md
- **Developed by:** [Ars Technis](https://apify.com/ars-technis) (community)
- **Categories:** Developer tools, Other
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $20.00 / 1,000 puzzle generateds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Sudoku & Star Battle Puzzle Generator

Generate **original logic puzzles** on demand, with answer keys:

- **Sudoku**: the classic 9x9 puzzle. Fill every row, column and 3x3 box with the digits 1 to 9.
- **Star Battle**: place one crown (or star) in every row, every column and every outlined region, so that no two crowns touch, not even diagonally. Grids from 6x6 to 10x10.

Every puzzle this Actor returns is:

- **Proven unique.** An exhaustive search confirms exactly one solution before the puzzle is delivered.
- **Solved by a fixed set of techniques.** A human-style logic solver finishes every puzzle, and the hardest technique it needs sets the grade.
- **Graded by technique**, not by counting clues:
  - Sudoku: *easy* needs only singles, *medium* pointing/claiming, *hard* pairs and triples, *expert* X-wing or swordfish. Sudoku never needs trial and error.
  - Star Battle: *easy* = singles and covers (a cell that sees every candidate of a row, column or region is ruled out), *medium* adds region/row counting sets, *hard* needs a counting set of three or more regions (or rows or columns), three or more counting steps in one puzzle, or one lookahead (most hard puzzles need no lookahead), *expert* needs two or more lookaheads (up to 18 in a test sample). A lookahead is a one-step trial: assume a crown, follow singles and covers, and rule the cell out if a row, column or region is left empty. Easy and medium Star Battle never need a lookahead, hard needs at most one, and expert uses two or more of these short trials.
- **Well-shaped Star Battle regions.** Every region has at least 3 cells (so no region gives its crown away) and covers at most 28% of the grid, at every size and grade. Region numbers and letters are assigned at random, so they say nothing about where the crowns are.
- **Fresh.** It is generated in your run, and puzzles never repeat within a run. Set a `seed` if you want the same puzzles again.

### Who it is for

- **Newsletters, blogs and apps** that want a daily logic puzzle without licensing fees
- **Teachers and activity-sheet makers** who need printable logic puzzles with answer keys
- **Puzzle book creators** who want a print-ready paperback interior (6x9 or 8.5x11 in) with graded puzzles and an answer key, to pair with their own cover
- **Worksheet creators** who need graded content with solutions
- **Game developers** who want a stream of verified levels as JSON
- **AI agents** that need a puzzle, its solution and a picture of it in one call

### What you get

One dataset item per puzzle.

Fields for every puzzle:

| Field | Meaning |
| --- | --- |
| `index`, `id` | Position in the run, and a stable 12-character ID |
| `type` | `sudoku` or `star-battle` |
| `size` | Grid size N (sudoku is always 9) |
| `difficulty` | `easy`, `medium`, `hard` or `expert` |
| `techniques` | How often the solver used each technique |
| `solutionText` | The solution as strings (when `includeSolution` is on) |
| `svg`, `solutionSvg` | Ready-to-embed SVG images (only when `svg` is on; off by default) |

Sudoku only:

| Field | Meaning |
| --- | --- |
| `grid` | 9x9 array, `0` = empty cell |
| `gridText` | The same as 9 strings, `.` = empty |
| `clues` | Number of given digits |
| `solution` | The full 9x9 solution |

Star Battle only:

| Field | Meaning |
| --- | --- |
| `regions` | N x N array of region numbers 0..N-1 (assigned at random; a number says nothing about the crown's row or column) |
| `regionsText` | The same grid as strings, one letter per region (A, B, C, ...) |
| `solution` | `[row, column]` of each crown |
| `solutionText` | `*` = crown |

With `pdf` on, the run also saves **`puzzles.pdf`** to its key-value store. The link is in the `OUTPUT` record as `pdfUrl`. Choose the layout with `pdfLayout`:

- **`sheets`** (default): US Letter worksheets with a rules page, two large puzzles per page and all solutions at the back (the answer key; left out when `includeSolution` is off). Fonts are embedded (IBM Plex Sans), so a title in Latin, Greek or Cyrillic letters prints, symbols such as № included, and a long title wraps onto up to three lines.
- **`book-6x9`** or **`book-8.5x11`**: a paperback **book interior**:
  - a title page and a "How to play" page, then one puzzle per page with its number, size and difficulty, then the solutions (4 per page at 6x9, 6 per page at 8.5x11)
  - page numbers, grayscale, an even page count, and fonts embedded (IBM Plex Sans)
  - no bleed, with every mark inside the margins: the inside (gutter) margin follows the page-count table in KDP's paperback guidelines (0.375 in up to 150 pages, 0.5 in up to 300, and so on), and the top and outside margins are 0.5 in or more. The page numbers sit in the bottom margin, at least 0.35 in from the bottom edge (KDP asks for 0.25 in); the puzzles and text above them stay 0.5 in or more from it
  - `OUTPUT.pdfPages` gives the page count, which you need for your cover's spine width. KDP paperbacks need at least 24 pages, so ask for 20 puzzles or more with answer keys on (`includeSolution`), or 22 or more without them. The 500-puzzle maximum stays under KDP's limit of about 828 pages.
  - The cover is yours to make. You may sell books made from the puzzles you generate (see "Rights" below).

Sudoku example (shortened; a real output, seed 7, medium):

```json
{
  "index": 1,
  "id": "6640c2d99dfa",
  "type": "sudoku",
  "size": 9,
  "difficulty": "medium",
  "clues": 30,
  "gridText": [".......1.", "2..48...5", "5941.7...", "3162...5.", ".........", ".5...1923", "...5.6374", "7...43..2", ".4......."],
  "solutionText": ["687352419", "231489765", "594167238", "316294857", "972835641", "458671923", "829516374", "765943182", "143728596"],
  "uniqueSolution": true
}
```

Star Battle example (shortened; a real output, `puzzleType` star-battle, seed 7, size 6, easy):

```json
{
  "index": 1,
  "id": "53430ec9f1e4",
  "size": 6,
  "difficulty": "easy",
  "regionsText": ["AAACCC", "ADADEC", "ADDDEE", "BBFFFE", "BFFFFE", "BBBFFF"],
  "solutionText": ["....*.", "*.....", "..*...", ".....*", "...*..", ".*...."],
  "uniqueSolution": true
}
```

### Input

| Field | Default | Notes |
| --- | --- | --- |
| `puzzleType` | `sudoku` | `sudoku` or `star-battle` |
| `count` | 10 | 1 to 500 puzzles |
| `sizes` | `[8]` | Star Battle only: any of 6, 7, 8, 9, 10 |
| `difficulties` | `["easy","medium","hard"]` | Any of easy, medium, hard, expert |
| `includeSolution` | true | |
| `svg` | false | Adds SVG images to each item (about 2.5 to 12 KB each; measured: Star Battle 6x6 about 2.9 KB, 10x10 with crowns about 8.8 KB, sudoku solution about 11 KB) |
| `palette` | `color` | Star Battle SVG colours: `color` or `grayscale` |
| `pdf` | false | Adds `puzzles.pdf` |
| `pdfLayout` | `sheets` | `sheets`, `book-6x9` or `book-8.5x11` (see above) |
| `title` | Sudoku Puzzles / Star Battle Puzzles | Up to 80 characters, printed on the PDF's first page (the title page in a book interior) |
| `seed` | empty | Same seed + same settings = same puzzles |

Puzzles cycle through every combination of the sizes and difficulties you pick.

### Pricing

You pay **per delivered puzzle** (see the pricing tab), once: the Actor charges one `puzzle` event per puzzle, and Apify's default per-dataset-item event is removed from the pricing, so you are not billed a second time for the same item. (If that default event were ever priced, the Actor would bill each puzzle through it alone and skip its own event.) Each puzzle has a limit of 90 seconds of CPU time; one that cannot be finished within it is skipped and not charged. The limit counts CPU time, not waiting time, so a low memory setting slows a run down but does not cause skips. If you set a maximum cost per run that covers fewer puzzles than you asked for, the Actor makes only as many as it covers, and the PDF holds all of them.

Speed (CPU time per puzzle, measured): sudoku easy to hard takes under a second and expert about 4 s on average (at most about 10 s). Star Battle up to 8x8 takes well under a second; 9x9 and 10x10 take about 0.5 to 2.5 seconds on average, and 10x10 expert about 2 to 5 s (at most about 18 s seen), far below the 90 s limit. More memory gives more CPU and faster runs.

### Rules (for your readers)

**Sudoku:** fill every row, every column and every 3x3 box with the digits 1 to 9, each exactly once.

**Star Battle:**

1. Place one crown in every row, every column and every outlined region.
2. Two crowns may never touch, not even diagonally.

Tip for solvers: mark every cell that cannot hold a crown with a dot. When you place a crown, dot its row, its column, its region and the eight cells around it.

### Rights

The puzzles are generated in your run by this Actor's own code. You may use, print, publish and sell the puzzles you generate, including in commercial products. There is no attribution requirement.

### How it works

Sudoku: a random full grid is drawn first. Clues are removed in symmetric pairs while the solution stays unique and the grade stays within the level you asked for.

Star Battle: a random crown placement is drawn first. Regions are grown around it (each to at least 3 cells, none past 28% of the grid) and then repaired cell by cell, within the same limits, until the intended placement is the only solution. To reach a wanted grade, single border cells are then moved between regions, keeping each move only if the puzzle stays unique, logic-solvable and within the region limits. A human-style logic solver then solves the puzzle, and the hardest technique it needs sets the grade. Before delivery each puzzle is checked again, independently, including its region shapes. The Actor is plain Python code; it calls no AI model and no external service.

# Actor input Schema

## `puzzleType` (type: `string`):

sudoku = classic 9x9 sudoku. star-battle = place one crown per row, column and region, no two touching.

## `count` (type: `integer`):

How many puzzles to generate. You are charged per delivered puzzle.

## `sizes` (type: `array`):

Star Battle grid sizes to use (6 to 10). Puzzles cycle through the sizes and difficulties you choose. Sudoku is always 9x9.

## `difficulties` (type: `array`):

Any of easy, medium, hard, expert, graded by the hardest technique a logic solver needs. Sudoku: easy = singles only; medium = pointing/claiming; hard = pairs and triples; expert = X-wing or swordfish. Star Battle: easy = singles and covers (a cell that sees every candidate of a row, column or region is ruled out); medium = adds region/row counting sets; hard = a counting set of three or more regions (or rows or columns), three or more counting steps, or one lookahead (most hard puzzles need no lookahead); expert = two or more lookaheads. A lookahead is a one-step trial: assume a crown, follow singles and covers, and rule the cell out if a row, column or region is left empty. Easy and medium never need a lookahead, hard at most one. Every Star Battle region has at least 3 cells and at most 28% of the grid.

## `includeSolution` (type: `boolean`):

Add the solution (coordinates, text and SVG) to every puzzle.

## `svg` (type: `boolean`):

Add a ready-to-embed SVG of the puzzle (and of the solution) to every item. Off by default: each SVG adds about 2.5 to 12 KB to the dataset item (up to about 17 KB with the solution image).

## `palette` (type: `string`):

Region colours in the SVG images.

## `pdf` (type: `boolean`):

Also build a printable PDF (layout below) and save it to the run's key-value store as puzzles.pdf.

## `pdfLayout` (type: `string`):

Worksheets: US Letter, two puzzles per page, solutions at the back. Book interior: a paperback interior with no bleed at 6x9 in or 8.5x11 in: title page, rules page, one puzzle per page, solutions at the back, page numbers, embedded fonts, grayscale, an even page count, and an inside margin set from the page count by KDP's paperback table. KDP paperbacks need at least 24 pages, so ask for 20 puzzles or more. You add your own cover.

## `title` (type: `string`):

Title printed on the first page of the PDF. Default: 'Sudoku Puzzles' or 'Star Battle Puzzles'.

## `seed` (type: `integer`):

Optional. The same seed and settings give the same puzzles again. Leave empty for fresh puzzles every run.

## Actor input object example

```json
{
  "puzzleType": "sudoku",
  "count": 5,
  "sizes": [
    8
  ],
  "difficulties": [
    "easy",
    "medium",
    "hard"
  ],
  "includeSolution": true,
  "svg": false,
  "palette": "color",
  "pdf": false,
  "pdfLayout": "sheets"
}
```

# Actor output Schema

## `puzzles` (type: `string`):

No description

## `pdf` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "puzzleType": "sudoku",
    "count": 5,
    "sizes": [
        8
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("ars-technis/logic-puzzle-generator").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "puzzleType": "sudoku",
    "count": 5,
    "sizes": [8],
}

# Run the Actor and wait for it to finish
run = client.actor("ars-technis/logic-puzzle-generator").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "puzzleType": "sudoku",
  "count": 5,
  "sizes": [
    8
  ]
}' |
apify call ars-technis/logic-puzzle-generator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,ars-technis/logic-puzzle-generator"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/rd29bftYqHzRjafYA/builds/ydAKLfeoHKfMfsbJf/openapi.json
