From e737486b668164d437c67e05f95d32c94e946e6a Mon Sep 17 00:00:00 2001 From: Daniel Hader Date: Sun, 16 Aug 2026 21:52:55 -0500 Subject: initial commit, rectangular grid placement enumeration --- examples/puzzle-a-day.rs | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 examples/puzzle-a-day.rs (limited to 'examples/puzzle-a-day.rs') 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!(""); + } + } +} -- cgit v1.2.3