BracketCityPuzzle
Documentation for BracketCityPuzzle.
These are some software tools for working with "Bracket City" puzzles as appear onnthe web site for The Atlantic Monthly.
Example
using BracketCityPuzzle
# Puzzle from 2025-09-07:
puzzle = """ "Gari[like Larry [underdog vs. Goliath] or Ma[wearing one [elp[ out your credit card (bad idea, usually)]e rof ,eulc siht] is a good way to connect with the [[fancy kind of pen 🖋️] of (👵 ➡️ 👧)]]ma Gandhi 🦅]i enters [time resisted by a t[weird or not di[able to be [\"As on TV\" 📺]] by [customary number of weeks of [see and re[to \"get the \" of something is to under[\"I [word that will appear if you get this clue right]ed\"] the basic idea]er] given before leaving a job]]ler, maybe 💤]les" """
parsed = parse_puzzle(puzzle)
show_puzzle(parsed)
"Gari
[1
like Larry
[2
underdog vs. Goliath
]
or Ma
[3
wearing one
[4
elp
[5
out your credit card (bad idea, usually)
]
e rof ,eulc siht
]
is a good way to connect with the
[6
[7
fancy kind of pen 🖋️
]
of (👵 ➡️ 👧)
]
]
ma Gandhi 🦅
]
i enters
[8
time resisted by a t
[9
weird or not di
[10
able to be
[11
"As on TV" 📺
]
]
by
[12
customary number of weeks of
[13
see and re
[14
to "get the " of something is to under
[15
"I
[16
word that will appear if you get this clue right
]
ed"
]
the basic idea
]
er
]
given before leaving a job
]
]
ler, maybe 💤
]
les"
Add some answers:
only(findBracket("kind of pen", parsed)).answer = "fountain"
only(findBracket("Goliath", parsed)).answer = "David"
only(findBracket("on TV", parsed)).answer = "seen"
only(findBracket("able to", parsed)).answer = "visible"
only(findBracket("out your", parsed)).answer = "max"
only(findBracket("👧", parsed)).answer = "youth"
only(findBracket(",eulc", parsed)).answer = "backwards"
only(findBracket("wearing", parsed)).answer = "hat"
only(findBracket("Larry", parsed)).answer = "bald"
only(findBracket("clue right", parsed)).answer = "corrected"
show_puzzle(preduce(parsed))
"Garibaldi enters
[8
time resisted by a t
[9
weird or not divisible by
[12
customary number of weeks of
[13
see and re
[14
to "get the " of something is to under
[15
"I correcteded"
]
the basic idea
]
er
]
given before leaving a job
]
]
ler, maybe 💤
]
les"
only(findBracket(15, parsed)).answer = "stand"
only(findBracket(14, parsed)).answer = "gist"
only(findBracket(13, parsed)).answer = "notice"
only(findBracket(12, parsed)).answer = "two"
only(findBracket(9, parsed)).answer = "odd"
only(findBracket(8, parsed)).answer = "nap"
show_puzzle(preduce(parsed))
BracketCityPuzzle.Bracket
BracketCityPuzzle.all_brackets
BracketCityPuzzle.findBracket
BracketCityPuzzle.hasanswer
BracketCityPuzzle.issolved
BracketCityPuzzle.parse_puzzle
BracketCityPuzzle.preduce
BracketCityPuzzle.set_answer
BracketCityPuzzle.show_puzzle
BracketCityPuzzle.to_string
BracketCityPuzzle.tokenize_puzzle
BracketCityPuzzle.walkBrackets
BracketCityPuzzle.Bracket
— TypeBracket(clue, answer)
Represents a bracketed clue, and possibly its answer.
BracketCityPuzzle.all_brackets
— Methodall_brackets(parsed::BCPuzzle)
Returns a vector of all of the Bracket
s within parsed
.
BracketCityPuzzle.findBracket
— FunctionfindBracket(test, ::BCPuzzle)::Vector{Bracket}
Returns a vector of Bracket
objects that match test
, which can be a predicate or a substring to match.
BracketCityPuzzle.hasanswer
— Methodhasanswer(::Bracket)
Returns true if the Bracket has an answer.
BracketCityPuzzle.issolved
— Methodissolved(::PuzzleElement)::Bool
Returns true if the puzzle element is solved.
A Bracket
is solved only if it and all descendents are solved.
BracketCityPuzzle.parse_puzzle
— Functionparse_puzzle(string_or_token_vector)
Parses the string representation of a Bracket City puzzle. The result is a vector of strings and nested Bracket objects.
BracketCityPuzzle.preduce
— Functionpreduce(::BCPuzzle)::BCPuzzle
Simplifies the puzzle to a new puzzle by substituting in any Bracket
answers that are known.
BracketCityPuzzle.set_answer
— Methodset_answer(parsed::BCPuzzle, bracket_id::Int, answer::AbstractString)
Find the Bracket
with the specified bracket_id
and set its answer to answer
.
BracketCityPuzzle.show_puzzle
— Methodshow_puzzle(parsed::BCPuzzle)
Outputs the puzzle in a more readable format with lines indented proportional to bracket nesting.
If a Bracket
has an answer then it is printed immediately before the close braclet.
BracketCityPuzzle.to_string
— Functionto_string(puzzle::BCPuzzle)::AbstractString
Convert the puzzle to its textual representation. This is the inverse of parse_puzzle
.
BracketCityPuzzle.tokenize_puzzle
— Methodtokenize_puzzle(::AbstractString)
Tokenizes the string to produce a Vector of tokens consisting of strings, :openbracket
and :closebracket
symbols.
BracketCityPuzzle.walkBrackets
— MethodwalkBrackets(f::Function, thing)
Calls the function on eqch Bracket
nested within thing
.