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.findBracketFunction
findBracket(test, ::BCPuzzle)::Vector{Bracket}

Returns a vector of Bracket objects that match test, which can be a predicate or a substring to match.

source
BracketCityPuzzle.parse_puzzleFunction
parse_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.

source
BracketCityPuzzle.set_answerMethod
set_answer(parsed::BCPuzzle, bracket_id::Int, answer::AbstractString)

Find the Bracket with the specified bracket_id and set its answer to answer.

source
BracketCityPuzzle.show_puzzleMethod
show_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.

source
BracketCityPuzzle.tokenize_puzzleMethod
tokenize_puzzle(::AbstractString)

Tokenizes the string to produce a Vector of tokens consisting of strings, :openbracket and :closebracket symbols.

source