Construct Magic Rectangles and Nearly Magic Rectangles
Overview
Constructs a magic rectangle or a nearly magic rectangle of order p x q for every order for which one exists, together with existence classification and verification utilities. A magic rectangle arranges the integers 1 to p*q so that all row sums are equal and all column sums are equal; it exists exactly when p and q have the same parity, excluding 2 x 2 and degenerate single-row/column cases (Hagedorn, 1999, doi:10.1016/S0012-365X(99)00041-2). When p and q have opposite parity a nearly magic rectangle exists instead, with constant sums along one direction and sums differing by at most one along the other (Chai, Singh and Stufken, 2019, Journal of Combinatorial Designs 27(6), 368-376). Implements the constructions of De Los Reyes, Das, Midha and Vellaisamy (2009) for even by even orders, Chai, Das and Midha (2013) for odd by odd orders, and Chai, Singh and Stufken (2019) for the nearly magic (even by odd) case.
- Initial release.
magic_rectangle(p, q)constructs a magic rectangle (p, q of equal parity; De Los Reyes et al. 2009 for even orders, Chai-Das-Midha 2013 for odd orders) or a nearly magic rectangle (opposite parity; Chai-Singh-Stufken 2019) for every order for which one exists.rectangle_type(p, q)classifies existence ("magic", "nearly magic", "none").verify_rectangle(M)checks the defining properties from first principles.- Exhaustive test suite over all orders up to 40 x 40.
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-05
- NOTE12 OK, 1 NOTE2026-08-01
- OK6 OK2026-07-20
Documentation
- Help pages
- 3
- Examples that run
- 100%3 run in a plain check
- Exported functions with examples
- 100%
- Documented parameters
- 100%
- Return-value docs
- 100%
- Help pages citing references
- 33%
Downloads
Repository
2 development-tooling and community-health practices detected across 2 families in the upstream repository
Checks run against github.com/arijitray2/magic-rectangles on 2026-10-21.
GitHub Pages site last deployed 2026-07-11
This repository shows signs of AI coding tools.
- Claude Codefirst seen 2026-07-10Commits: at least 6 crediting it in the message
Dependencies
Installing magicrect adds no packages beyond those that come with R.
Code & Tests
People & History
- 1.0.0Latest2026-07-19 · current release
- RR 4.6.0 released · 2026-04-24
Package metadata
- First published
- 2026-07-19
- Total releases
- 1 / 1 yrs
- License
- MIT + file LICENSE OSI
- Download size
- 8.8 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("magicrect")This package has no citation file, so citation() returns this entry built from DESCRIPTION.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-25, which the citation names so these numbers can be found later. More on citing and the projects behind them.