Rust-powered command-line utility for generating and printing classic coding challenge patterns in the terminal.
Inspired by the fundamental logic questions frequently asked in technical interviews, pattern-forge-rust is a practical way to master nested loops, control flow, and modular code organization in Rust.
- Versatile Patterns: Generates various geometrical patterns (Diamonds, Triangles, Cross Boxes, etc.)
- Interactive Menu: User-friendly menu-driven interface for pattern selection
- Customizable Size: Easily control the size of the pattern (1-5)
- Modular Design: Clean, organized code structure with separate modules for each pattern
- Idiomatic Rust: Built using modern Rust conventions, focusing on safety, performance, and clean code
- Interview Prep: A hands-on resource for practicing core programming logic
This project uses only Rust standard library:
std::io: Standard library utilities for efficient terminal input/output
No external dependencies required! The project is lightweight and focuses on core Rust concepts.
You must have Rust and Cargo installed on your system. The easiest way is via rustup.
- Clone the Repository:
git clone https://github.com/ajay-develops/pattern-forge-rust.git
cd pattern-forge-rust- Build and Run:
cargo run- Build for Release (Optional):
cargo build --release
./target/release/patternsThe program features an interactive menu system. Simply run the program and follow the prompts:
cargo runWhen you run the program, you'll see a menu:
Which pattern would you like to print?
1. Barfi (rotated square/diamond)
2. Triangle
3. Cross Box
Enter your choice (1-3):
After selecting a pattern, you'll be prompted for the size (1-5).
A diamond pattern created using Manhattan distance calculations.
Example (size 3):
*
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
An isosceles triangle pattern pointing upward.
Example (size 3):
*
* * *
* * * * *
An X pattern with a border around it.
Example (size 3):
* * * * * * *
* * * *
* * * *
* * *
* * * *
* * * *
* * * * * * *
patterns/
├── src/
│ ├── main.rs # Main entry point with menu logic
│ └── patterns/
│ ├── mod.rs # Module declarations
│ ├── barfi.rs # Diamond pattern implementation
│ ├── triangle.rs # Triangle pattern implementation
│ └── cross_box.rs # Cross box pattern implementation
├── Cargo.toml # Project dependencies and metadata
└── README.md # This file
This project is open source, and contributions are highly welcome! Whether you are a Rust beginner or a seasoned pro, your help is valuable.
- Fork the repository
- Clone your fork
- Create a new branch for your feature or fix (e.g.,
feat/add-new-pattern) - Implement a new pattern or refactor an existing one, placing the logic in
src/patterns/ - Write tests for your new functionality (if applicable)
- Commit your changes and push to your fork
- Open a Pull Request (PR) against the main branch of this repository
- Implement new patterns (e.g., Spiral Matrix, Number Pyramid, Hollow Square)
- Add color support using the
coloredcrate - Refactor input parsing using a Factory Pattern for creating pattern objects
- Improve error handling and validation
- Add unit tests for pattern generation functions
- Extend size range beyond 1-5
- Add command-line argument support using
clapfor non-interactive usage
This project is licensed under the MIT License. See the LICENSE file for details.
ajay-develops
- GitHub: @ajay-develops
⭐ If you find this project helpful, please consider giving it a star!