-
Input File Format:
- The first line specifies the number of rows in the grid.
- The subsequent lines represent the grid itself, where each line has the same length (number of columns).
Example:
4 ..o. .o.. .... ...o
-
Dynamic Programming:
- A 1D
dp
array is used to store the size of the largest square ending at each cell. - The algorithm iterates through the grid, updating the
dp
array based on the values of the left, top, and diagonal neighbors.
- A 1D
-
Output:
- It displays the grid with the largest square replaced by
x
.
- It displays the grid with the largest square replaced by
- Rust installed on your system. If not, install it from rustup.rs.
-
Clone the Repository:
git clone https://github.com/GodlyJaaaj/bsq-rs.git cd largest-square-finder
-
Prepare the Input File: Create a text file (e.g.,
input.txt
) with the grid data. Example:4 ..o. .o.. .... ...o
-
Run the Program:
cargo run --release -- input.txt
-
Output: The program will display:
- The grid with the largest square replaced by
x
.
Example output:
..o. .o.. .xx. .xxo
- The grid with the largest square replaced by
- Get rid of unnecessary UTF-8 encoding of rust string
- Print the whole result as a single string (1 write) instead of printing each line one by one