diff options
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!(""); + } + } +} |
