diff options
| author | Daniel Hader <[email protected]> | 2026-08-16 21:52:55 -0500 |
|---|---|---|
| committer | Daniel Hader <[email protected]> | 2026-08-16 21:52:55 -0500 |
| commit | e737486b668164d437c67e05f95d32c94e946e6a (patch) | |
| tree | 37e4d1434a80ee162102703851aedd5334b46925 /examples | |
initial commit, rectangular grid placement enumeration
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/puzzle-a-day.rs | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/examples/puzzle-a-day.rs b/examples/puzzle-a-day.rs new file mode 100644 index 0000000..6577ede --- /dev/null +++ b/examples/puzzle-a-day.rs @@ -0,0 +1,86 @@ +use calendar_puzzle::{CalanderPuzzle, rectangular::{Coords, Piece, Puzzle}}; + +fn main() { + // construct board coordinates + let mut coords = Vec::new(); + for row in 0..7 { + for col in 0..7 { + if (row >= 5 && col == 6) || (row == 0 && col >= 3) { + continue; + } + coords.push(Coords::new(row, col)) + } + } + + let puzzle = Puzzle::new(coords).unwrap() + .with_piece(Piece::new([ + Coords::new(0, 0), + Coords::new(0, 1), + Coords::new(0, 2), + Coords::new(1, 0), + Coords::new(1, 1), + Coords::new(1, 2), + ]).unwrap()) + .with_piece(Piece::new([ + Coords::new(0, 0), + Coords::new(0, 1), + Coords::new(0, 2), + Coords::new(1, 0), + Coords::new(1, 1), + ]).unwrap()) + .with_piece(Piece::new([ + Coords::new(0, 0), + Coords::new(0, 1), + Coords::new(0, 2), + Coords::new(1, 0), + Coords::new(1, 2), + ]).unwrap()) + .with_piece(Piece::new([ + Coords::new(0, 0), + Coords::new(0, 1), + Coords::new(0, 2), + Coords::new(0, 3), + Coords::new(1, 1), + ]).unwrap()) + .with_piece(Piece::new([ + Coords::new(0, 0), + Coords::new(0, 1), + Coords::new(0, 2), + Coords::new(0, 3), + Coords::new(1, 0), + ]).unwrap()) + .with_piece(Piece::new([ + Coords::new(0, 0), + Coords::new(0, 1), + Coords::new(0, 2), + Coords::new(1, 2), + Coords::new(1, 3), + ]).unwrap()) + .with_piece(Piece::new([ + Coords::new(0, 0), + Coords::new(1, 0), + Coords::new(1, 1), + Coords::new(1, 2), + Coords::new(2, 2), + ]).unwrap()) + .with_piece(Piece::new([ + Coords::new(0, 0), + Coords::new(0, 1), + Coords::new(0, 2), + Coords::new(1, 0), + Coords::new(2, 0), + ]).unwrap()); + + let placements = puzzle.placements(true); + let placements_no_flip = puzzle.placements(false); + + for (i, _piece) in puzzle.pieces().enumerate() { + println!("piece {} has {} placements allowing flips", i, placements[i].len()); + println!("piece {} has {} placements without flips", i, placements_no_flip[i].len()); + + for placement in &placements_no_flip[i] { + puzzle.print_placement(placement); + println!(""); + } + } +} |
