REPOSITORY CODING · MEDIUM
Add ordered page-range selection to the print planner
The planner currently ignores explicit page selections. Implement inclusive one-based ranges, preserving the order in which they are requested and removing repeated pages after their first occurrence. Empty and invalid selections must follow the contract.
Repository ImplementationBooklet print planner
Work through a real codebase.
Choose an environment, investigate the existing implementation and use the tests to check your change. Sign in to open a workspace; execution and Ono usage follow your plan’s allowances.
Task requirements and environments
C++ · 50 minute session
- Each page has a unique nonempty ID, integer width and height in millimeters. Dimensions must be 1–2000. Accept at most 500 pages. The application produces a sheet plan, not printer control instructions.
- Optional selection is a list of inclusive, ascending one-based ranges. Keep range order and retain only the first occurrence of any page. Missing selection means all pages; an empty selection means no pages.
- Signature size is divisible by four, from 4 to 32. Split the selected sequence at that size and pad each nonempty final group to the smallest multiple of four. A complete group gains no blank pages.
- Within a signature, emit outer sheets before inner sheets. For left binding, front is [last, first], back is [second, second-last], then continue inward. Blank pages are null. Right binding swaps the two slots on every side.
- Long-edge duplex leaves both back pages at rotation zero. Short-edge duplex rotates the whole back side: swap its slots and rotate each nonblank back page by 180 degrees. Apply binding first, duplex second.
- Center each page in its slot. Printable width is sheetWidth minus two margins and one gutter, divided equally. Printable height excludes both margins. Shrink proportionally when needed, never enlarge. Round coordinates and scale to four decimals.
- The result reports selected IDs, blank page count, total sheet count and numbered signatures. Return clear validation errors without producing a partial plan.