How Amazon Ergo Helped Me Cut 152 Cookbook Pages
Amazon Ergo helped me cut the print layout for soviet.recipes from 728 to 576 pages (a reduction of 152 pages or 20.9%). Working with the model, we reordered recipes within their sections and dynamically selected denser layouts for each recipe. All recipes keep their ingredients and steps, and each recipe fits on one page by design so that nobody cooking needs to touch the book or turn a page mid-way.
Why the original order wasted space
The original recipe order followed The Book of Tasty and Healthy Food, the Soviet cookbook that inspired the project. The order left many pages partly empty, making the book lengthier and therefore costlier to produce.
For example, page 18 in book order held only Red Cabbage Salad and was 46% full. White Cabbage Salad came next in the book, and it was too tall to share the page. Book order had 680 recipe pages. The median recipe page was 61% full, and 325 recipe pages were less than 60% full.
Compact order puts Red Cabbage Salad and Vegetable Vinaigrette on one page and fills 96% of it.
How constrained bin packing condenses a section
Section packing is a constrained bin-packing problem. A page is a bin with a fixed usable height. A recipe is an indivisible item with a measured height. The measurement for the first recipe in a section includes the section heading. The goal is to minimize the page count subject to these constraints:
- Each recipe fits on one page. The cook does not turn a page in the middle of the steps.
- Chapters and sections keep their order and boundaries.
- A section heading stays with the first recipe in the section.
- Every recipe appears exactly once. The ingredients and steps stay unchanged.
- Only the recipe order within a section can change.
General bin packing is NP-hard, and I didn't try to set up an AI agent swarm to solve P = NP despite the recent AI-assisted work on VP versus VNP work that's renewed speculation about the larger question. P versus NP remains open and Ergo uses Best-Fit Decreasing as checking all recipes is computationally impractical. A heuristic packs one section at a time thusly:
- Sort the recipes in the section from tallest to shortest. Recipes with equal heights keep their book order.
- Put the first recipe on an empty page.
- Put each next recipe on the page where it fits with the least unused space after placement. Start a new page if it fits nowhere.
- Sort the pages by their earliest recipe, and restore book order among the recipes on each page.
Best fit selects the page with the smallest sufficient gap. This choice preserves larger gaps for recipes that still need them. Small recipes can fill the smaller gaps. The heuristic does not guarantee the global minimum page count.
In this example, A and B cannot share a page. Book order uses three pages: A, then B with C, then D. Best-Fit Decreasing puts C with A and D with B, so two pages hold all four recipes.
Ergo helped me implement the measurements and the packing algorithm that reduced the book from 728 to 665 pages.
How per-recipe layouts reduce the page count further
Section packing treats each recipe height as fixed. Layout refinement can reduce that height. Some recipes do not fit the normal two-column grid, so the build measures three layouts for every recipe:
- The normal layout uses two columns for the ingredients and method.
- The float layout puts the ingredients beside the method and lets the method wrap below them.
- The wide layout puts the ingredients in three full-width columns and the method below.
The build uses the shortest layout for each recipe. Kulich uses the float layout and fits on one page. Preparation of the Filling uses the wide layout and fits on one page.
Layout refinement reduced the compact book from 665 to 576 pages. Recipe pages fell from 617 to 528. Together, section packing and layout refinement removed 152 pages, or 20.9%, while all 883 recipes kept their ingredients, steps, and section order.
The resulting book has 576 pages and costs less to print than the 728-page version. Ergo performed quite well in this exercise, on par with other state-of-the-art models such as Opus 5.5 (in my opinion).
