Logic puzzles (nonfiction)

From Gnomon Chronicles
A logic puzzle grid, with the information that only Simon is 15 and Jane does not like green filled in.

A logic puzzle is a puzzle deriving from the mathematical field of deduction.

History

The logic puzzle was first produced by Charles Lutwidge Dodgson, who is better known under his pen name Lewis Carroll, the author of Alice's Adventures in Wonderland. In his book The Game of Logic he introduced a game to solve problems such as confirming the conclusion "Some greyhounds are not fat" from the statements "No fat creatures run well" and "Some greyhounds run well". Puzzles like this, where we are given a list of premises and asked what can be deduced from them, are known as syllogisms. Dodgson goes on to construct much more complex puzzles consisting of up to 8 premises.

In the second half of the 20th century mathematician Raymond M. Smullyan continued and expanded the branch of logic puzzles with books such as The Lady or the Tiger?, To Mock a Mockingbird and Alice in Puzzle-Land. He popularized the "knights and knaves" puzzles, which involve knights, who always tell the truth, and knaves, who always lie.

There are also logic puzzles that are completely non-verbal in nature. Some popular forms include:

  • Sudoku, which involves using deduction to correctly place numbers in a grid;
  • The nonogram, also called "Paint by Numbers", which involves using deduction to correctly fill in a grid with black-and-white squares to produce a picture
  • Logic mazes, which involve using deduction to figure out the rules of a maze

Logic grid puzzles

Another form of logic puzzle, popular among puzzle enthusiasts and available in magazines dedicated to the subject, is a format in which the set-up to a scenario is given, as well as the object (for example, determine who brought what dog to a dog show, and what breed each dog was), certain clues are given ("neither Misty nor Rex is the German Shepherd"), and then the reader fills out a matrix with the clues and attempts to deduce the solution. These are often referred to as "logic grid" puzzles. The most famous example may be the so-called Zebra Puzzle, which asks the question Who Owned the Zebra?.

Common in logic puzzle magazines are derivatives of the logic grid puzzle called "table puzzles" that are deduced in the same manner as grid puzzles, but lack the grid either because a grid would be too large, or because some other visual aid is provided. For example, a map of a town might be present in lieu of a grid in a puzzle about the location of different shops.

Google AI notes

Logic grid puzzles and formal languages

Yes, formal languages and structural patterns exist for representing logic grid puzzles. To translate human-language clues into a formal machine-readable syntax, computer scientists and logicians rely on specific mathematical frameworks. Depending on whether you want to solve them computationally, generate them, or build an interface, you can adopt or adapt several existing formal paradigms. 

1. The Core Mathematical Framework: Relation Matrices

Before looking at syntax, the underlying data structure must be defined. A standard logic puzzle with dimensions \(D_1, D_2, \dots, D_n\) (e.g., Names, Colors, Pets) is formally a set of binary relations between pairs of dimensions. If every dimension has \[k\] items, the puzzle state is a collection of \[{n \choose 2}\] matrices of size \(k \times k\). Let \(R_{A,B}(x, y) \in \{0, 1\}\) represent the intersection between item \[x\] from dimension \[A\] and item \[y\] from dimension \[B\].Bijective Constraint: Every item maps to exactly one item in every other dimension:\[\forall x\in A,\sum _{y\in B}R_{A,B}(x,y)=1\quad \text{and}\quad \forall y\in B,\sum _{x\in A}R_{A,B}(x,y)=1\] 2. Formal Languages for Logic CluesTo formalize the clues themselves, you can map standard English logic puzzle clues directly to First-Order Logic (FOL) or Constraint Satisfaction Problem (CSP) formalisms. Option A: Constraint Satisfaction Problem (CSP) / MiniZinc The most practical formal language for this is a constraint modeling language like MiniZinc. It treats items as variables and clues as mathematical constraints. Clue TypeEnglish ExampleFormal MiniZinc / CSP RepresentationDirect Match"Alice owns the Red house."Alice == Red;Direct Negative"Bob does not own the Dog."Bob != Dog;Relative Ordering"The Cat owner lives immediately to the left of the Blue house."Index(Cat) == Index(Blue) - 1;Exclusive Or"Either Charlie or the Zebra owner bought the sedan."(Charlie == Sedan) \/ (Zebra == Sedan); Charlie != Zebra;Conditional"If David has the Bird, then Frank has the Green house."(David == Bird) -> (Frank == Green);Option B: First-Order Logic (FOL) If you want a pure logic specification, you define a single predicate Is(x, y) which means \[x\] and \[y\] share the same entity profile (the transitivity property). Clue: "The person who wears the Red hat does not own the Dog."Formal Language: \(\forall x (\text{Hat}(x, \text{Red}) \rightarrow \neg \text{Pet}(x, \text{Dog}))\) Option C: Abstract Syntax Tree (AST) Pattern Language If you are designing a custom domain-specific language (DSL) for a puzzle engine, you can formalize clues into a JSON-based or LISP-like functional pattern language. This maps perfectly to grid actions (True/False marks). 

json// Clue: "Alice is older than the person who loves Blue." {

 "clue_type": "relative_ordering",
 "property": "Age",
 "operator": "greater_than",
 "entity_1": {"dimension": "Name", "value": "Alice"},
 "entity_2": {"dimension": "Color", "value": "Blue"}

}

3. Existing Systems to Look IntoIf you want to use pre-existing tools rather than inventing a language from scratch, look at these domains: Answer Set Programming (ASP) / Clingo: ASP is a declarative scripting language heavily used in academic AI to solve and generate logic puzzles. You define facts (items) and rules (clues), and the ASP solver computes the grid intersections. SMT-LIB: The standard language for Satisfiability Modulo Theories (SMT) solvers like Z3. It is incredibly robust for evaluating whether a set of clues is valid, redundant, or leads to a unique solution. 

Logic grids and role-playing games

Integrating logic grid puzzles into tabletop RPGs like Dungeons & Dragons is a brilliant way to gamify investigation, tracking, and dungeon crawling. It bridges the gap between abstract narrative clues ("The ancient diary says the ruby wasn't buried in the crypt...") and mechanical game progression.In game design, this effectively turns the logic grid into a dynamic shroud/fog-of-war map and a victory condition engine.Here is how you can formalize and employ logic grids as an active game design framework for both Game Masters (DMs) and players.1. The Core Mechanical AdaptationInstead of sitting at a table passively reading clues from a book, players earn matrix intersections through in-game actions. The grid itself becomes the "Quest Tracker."

The Matrix Elements:

The axes of the grid represent the structural variables of the dungeon adventure:

Axis A (The Rooms): Hall of Doom, Whispering Crypt, Alchemist's Lab, Foyer.Axis B (The Threats): The Dragon, The Lich, The Mimic, The Trapped Chest.

Axis C (The Loot/Objectives): The Sunsword, The Phylactery, The Key, The Prisoner.The Gameplay Loop:Players explore a room or interrogate an NPC.

The DM rewards them with a structural clue (e.g., "You find a dead adventurer holding an empty potion vial. The Alchemist's Lab was clearly looted by something else.")The players fill out their grid (marking an X at Alchemist's Lab/Phylactery).Solving the grid reveals the exact location of the Boss and the Treasure, allowing them to bypass dangerous dead-ends.

2. Translating Grid Mechanics into TTRPG SystemsTo make this feel like an RPG rather than a math textbook, you can map standard logic puzzle mechanics directly to tabletop mechanics:Logic Grid ConceptRPG / Narrative EquivalentMechanical ImpactThe Grid MatrixThe "Dungeon Rumor / Intel Tracker"A physical handout given to the players at the start of the dungeon adventure.A Negative Clue (X)Environmental Evidence / Ruined Rooms"You find scorched walls in the Foyer, but no body. The Dragon does not reside here."A Positive Clue (O)Direct Confrontation / Undeniable Proof"You peek through the keyhole. The Lich is definitely chanting in the Whispering Crypt."Transitive DeductionDivination Magic / Deductive Reasoning"If the Mimic is in the Foyer, and the Foyer holds no treasure, then the Mimic isn't guarding the Sunsword."Grid Completion (Solution)The Perfect Strategy / Safe PassageThe players know exactly which room to storm for the boss, letting them bypass remaining traps.

3. Advanced Design Mechanics for DMsIf you are designing a game flow around this framework, you can inject traditional RPG tension into the static grid:

A. The "Living Grid" (Dynamic Threats)In a standard logic puzzle, the truth is static. In a game, the DM can introduce conditional clues or hidden variables.The Clue: "The Orc Chieftain is always one room away from the Shaman."The Twist: If the players trigger an alarm, the Chieftain moves, shifting the entire axis of the grid by +1 column, forcing players to re-evaluate their deductions in real-time.

B. Mechanizing the Clues via Skill ChecksInstead of just handing clues out, tie the quality of the clue to player stats:

Low Success (DC 10 History): "You recall that the Lich hid its Phylactery in either the Crypt or the Lab." (An OR logic gate constraint).High Success (DC 20 Investigation): "You find dust patterns showing the heavy iron chest was dragged directly from the Hall of Doom to the Vault." (A Direct Link constraint).C. Grid Failures as Combat TriggersWhat happens if the players guess incorrectly or make a false deduction on their grid?If they march into the Vault expecting the Treasure, but their faulty logic accidentally places the Dragon there, they trigger an Ambush Encounter with negative status effects because they were unprepared.4. Structuring a Quest TemplateHere is a quick framework a designer can use to build a "Logic Dungeon":

[DIMENSIONS]

Rooms: [Crypt, Laboratory, Armory, Throne] Monsters: [Vampire, Wraith, Golem, Cultist] Items: [Holy Water, Cursed Ring, Shield, Spellbook]

[DM'S SECRET SOLUTION KEY]

Crypt -> Wraith -> Cursed Ring Laboratory -> Cultist -> Spellbook Armory -> Golem -> Shield Throne -> Vampire -> Holy Water

[DUNGEON CLUES DISTRIBUTED AS INTEL]

1. Room 1 Loot (Crypt): "The Wraith floats over a chest, but it refuses to touch the ring inside." (Crypt = Wraith, Crypt != Shield/Spellbook) 2. Interrogation (Cultist): "We Cultists set up our ritual altars near the alchemical beakers!" (Laboratory = Cultist) 3. Visual Clue (Armory): "The massive stone statue in the armory holds a matching stone shield." (Armory = Golem, Armory = Shield) By framing the dungeon this way, the players feel like genuine fantasy detectives. The grid becomes a tangible representation of their growing mastery over the dungeon environment.

Domain-Specific Language (DSL)

To design a Domain-Specific Language (DSL) that handles a dynamic logic grid inside an RPG, we need to move beyond static constraint languages like MiniZinc. We need a language that can handle states, events, and dynamic context.

In an RPG, clues aren't just true or false; they are discovered (state change), they can be falsified by events (e.g., a monster moves if a trap is sprung), or they can be conditional based on player choices.Let’s name this conceptual DSL "QuestGrid".

Here is a blueprint for designing its syntax, compiler logic, and runtime engine.

1. Architectural Anatomy of QuestGrid

A dynamic logic puzzle DSL requires three main blocks:

Schema: Defines the physical objects/dimensions of the game.

WorldState: Tracks variables that can change (traps, player location, alerts).Clues: Expresses the logic constraints, which can be hooked into WorldState triggers.2. Conceptual Syntax Definition

Here is an example of what QuestGrid looks like when defining a dungeon where triggering a trap alerts the boss and forces them to relocate, which dynamically rewrites the matrix constraints.questgrid

// --- 1. THE SCHEMA (The dimensions of our logic grid) ---

dimension Room = [Crypt, Lab, Armory, Throne] dimension Enemy = [Vampire, Wraith, Golem, Cultist] dimension Asset = [HolyWater, Ring, Shield, Spellbook]

// --- 2. THE WORLDSTATE (Dynamic variables that change during gameplay) ---

state {

   bool trap_sprung = false;
   bool alarm_raised = false;
   string player_location = "Entrance";

}

// --- 3. DYNAMIC CLUES & CONSTRAINTS ---

clues {

   // Static Clue: Unchanging baseline fact
   clue C1: Armory == Golem;
   // Direct Link Clue: Always active
   clue C2: Cultist == Spellbook;
   // State-Dependent Conditional Clue
   // If the trap hasn't been sprung, the Wraith is hiding in the Crypt.
   clue C3: when (!trap_sprung) {
       Wraith == Crypt;
   } 
   // If the trap IS sprung, the Wraith panics and flees to the Lab!
   else {
       Wraith == Lab;
       invalidate(C5); // The movement breaks previous environmental clues!
   }
   // Proximity Clue
   clue C4: Vampire != Throne;
   // Discovered Evidence (Hidden until players find it in-game)
   hidden clue C5: Room(Ring) != Crypt;

}

// --- 4. GAMEPLAY EVENTS (How the TTRPG triggers the state changes) --- event on_trigger_trap() {

   trap_sprung = true;
   notify("A loud click echoes! The layout of the puzzle has shifted...");

}

event on_investigate_body() {

   reveal(C5); // Players find a note revealing Clue 5

}

3. How the DSL Engine Works (Under the Hood)To turn this DSL into a functioning game mechanic, the engine evaluates the script using a Reactive Constraint Satisfaction Problem (Reactive CSP) workflow.

[Player Action] ──> [Triggers Event] ──> [Mutates WorldState]

                                              │
 ┌────────────────────────────────────────────┘
 ▼

[Re-evaluate 'when' Blocks] ──> [Filter Active Clues] ──> [Recompute Matrix Solution]

                                                                 │
                                                                 ▼
                                                     [Update Player UI / Grid]

Step A: Abstract Syntax Tree (AST) Parsing

The QuestGrid compiler converts the text code into an AST.

A static clue is compiled directly into a boolean constraint matrix.

A dynamic clue (when block) is compiled into a conditional node that listens to the WorldState registry.

Step B: The Rule Engine EvaluationEvery time a player takes a significant action in the game, the DM or game engine flags an event (e.g., on_trigger_trap()).

The engine updates trap_sprung = true.It loops through all constraints. C3 evaluates its new condition.The old constraint Wraith == Crypt is detached from the grid solver.

The new constraint Wraith == Lab is injected into the grid solver.

The solver re-checks if the puzzle is still mathematically solvable.

4. Handling Game Design "Edge Cases"Designing a dynamic puzzle DSL introduces mathematical risks that don't exist in standard logic puzzles. Your compiler engine must handle these natively:

Paradox Prevention (Contradictions)

The Risk: If a player activates a trap and the puzzle introduces a clue that contradicts an existing baseline clue, the game crashes mathematically (the grid becomes unsolvable).

The DSL Solution: The keyword invalidate(ClueID) or prioritizing constraints. In our example, when the Wraith moves to the Lab, it automatically nullifies C5, preventing a logic deadlock.

Non-Deterministic Solutions (Branching)

The Risk: Dynamic shifts might temporarily remove too many constraints, leaving the players with multiple valid solutions (ambiguity).

The DSL Solution: The engine can run a background simulation on every state change. If a state change creates multiple solutions, it can automatically prompt the DM: System Message: Matrix ambiguity detected. Please provide the players with an emergency clue.

5. Benefits for Game Design and VTTsIf implemented in a Virtual Tabletop (VTT) like Roll20 or Foundry, or wrapped in a custom indie game engine, this DSL allows for incredible emergent gameplay:

Schrödinger's Dungeon: The DM doesn't have to pre-program what is in every room. They just write the logic parameters. The dungeon dynamically decides where the loot and monsters are based purely on the path the players take.

Information as Currency: Spies, divination spells, and successful interrogation rolls literally unlock hidden clue lines in the DSL engine, organically updating the player's UI grid with new checkmarks.

In the News

Fiction cross-reference

Nonfiction cross-reference

  • Category:Logic puzzles, a list of different logic puzzles
  • List of puzzle video games
  • Logic programming
  • Mechanical puzzle
  • Recreational mathematics

External links

  • Logic puzzle @ Wikipedia
  • LogicalSolver - "LogicalSolver supports you in solving a logic grid puzzle that is also known as logical, logigram or logiquiz."
  • Grok @ X: "Software for creating logic puzzles / prefer library that can be incorporated into application"
  • Dungeons & Diagrams