Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1b73889fd9 | ||
![]() |
2e199e8f1c | ||
![]() |
358290cfa5 | ||
![]() |
018b6aa8ed |
5 changed files with 214 additions and 222 deletions
128
.github/workflows/rust.yml
vendored
128
.github/workflows/rust.yml
vendored
|
@ -2,99 +2,95 @@ name: Rust -> Build & Test & Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "main" ]
|
branches: ["main"]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
PROJECT_NAME: ${{ github.event.repository.name }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_linux:
|
build_linux:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --release --verbose
|
run: cargo build --release --verbose
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cargo test --verbose
|
run: cargo test --verbose
|
||||||
|
|
||||||
- name: Upload Linux Binary
|
- name: Upload Linux Binary
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: banker_algorithm_linux_x64_86
|
name: ${{ env.PROJECT_NAME }}-linux-x64_86
|
||||||
path: target/release/banker-algorithm
|
path: target/release/${{ env.PROJECT_NAME }}
|
||||||
|
|
||||||
build_windows:
|
build_windows:
|
||||||
|
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --release --verbose
|
run: cargo build --release --verbose
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cargo test --verbose
|
run: cargo test --verbose
|
||||||
|
|
||||||
- name: Upload Windows Binary
|
- name: Upload Windows Binary
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: banker_algorithm_windows_x64_86
|
name: ${{ env.PROJECT_NAME }}-windows-x64_86
|
||||||
path: target/release/banker-algorithm.exe
|
path: target/release/${{ env.PROJECT_NAME }}.exe
|
||||||
|
|
||||||
build_macos:
|
build_macos:
|
||||||
|
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --release --verbose
|
run: cargo build --release --verbose
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cargo test --verbose
|
run: cargo test --verbose
|
||||||
|
|
||||||
- name: Upload MacOS Binary
|
- name: Upload MacOS Binary
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: banker_algorithm_macos_x64_86
|
name: ${{ env.PROJECT_NAME }}-macos-arm64
|
||||||
path: target/release/banker-algorithm
|
path: target/release/${{ env.PROJECT_NAME }}
|
||||||
|
|
||||||
release:
|
release:
|
||||||
needs: [build_linux, build_windows, build_macos]
|
needs: [build_linux, build_windows, build_macos]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Forge a Folder
|
||||||
|
run: mkdir Downloads
|
||||||
|
working-directory: /home/runner/work/${{ env.PROJECT_NAME }}/${{ env.PROJECT_NAME }}/
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/download-artifact@v4
|
||||||
- name: Forge a Folder
|
name: Download
|
||||||
run: mkdir Downloads
|
with:
|
||||||
working-directory: /home/runner/work/banker-algorithm/banker-algorithm/
|
path: Downloads/
|
||||||
|
|
||||||
- uses: actions/download-artifact@v4
|
- name: Rename Binaries
|
||||||
name: Download
|
run: |
|
||||||
with:
|
tree Downloads/
|
||||||
path: Downloads/
|
mv Downloads/${{ env.PROJECT_NAME }}-linux-x64_86/${{ env.PROJECT_NAME }} Downloads/${{ env.PROJECT_NAME }}-linux-x64_86/${{ env.PROJECT_NAME }}-linux-x64_86
|
||||||
|
mv Downloads/${{ env.PROJECT_NAME }}-windows-x64_86/${{ env.PROJECT_NAME }}.exe Downloads/${{ env.PROJECT_NAME }}-windows-x64_86/${{ env.PROJECT_NAME }}-windows-x64_86.exe
|
||||||
- name: Rename Binaries
|
mv Downloads/${{ env.PROJECT_NAME }}-macos-arm64/${{ env.PROJECT_NAME }} Downloads/${{ env.PROJECT_NAME }}-macos-arm64/${{ env.PROJECT_NAME }}-macos-arm64
|
||||||
run: |
|
- name: Git Commit SHA
|
||||||
mv Downloads/banker_algorithm_linux_x64_86/banker-algorithm Downloads/banker_algorithm_linux_x64_86/banker-algorithm-linux_x64_86
|
id: vars
|
||||||
mv Downloads/banker_algorithm_windows_x64_86/banker-algorithm.exe Downloads/banker_algorithm_windows_x64_86/banker-algorithm-windows_x64_86.exe
|
run: |
|
||||||
mv Downloads/banker_algorithm_macos_x64_86/banker-algorithm Downloads/banker_algorithm_macos_x64_86/banker-algorithm-macos_x64_86
|
calculatedSha=$(git rev-parse --short ${{ github.sha }})
|
||||||
|
echo "short_sha=$calculatedSha" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Git Commit SHA
|
- uses: softprops/action-gh-release@v2
|
||||||
id: vars
|
name: Release
|
||||||
run: |
|
with:
|
||||||
calculatedSha=$(git rev-parse --short ${{ github.sha }})
|
tag_name: ${{ steps.vars.outputs.short_sha }}
|
||||||
echo "short_sha=$calculatedSha" >> $GITHUB_OUTPUT
|
generate_release_notes: true
|
||||||
|
files: |
|
||||||
- uses: softprops/action-gh-release@v2
|
Downloads/*linux*/${{ env.PROJECT_NAME }}*
|
||||||
name: Release
|
Downloads/*windows*/${{ env.PROJECT_NAME }}*
|
||||||
with:
|
Downloads/*macos*/${{ env.PROJECT_NAME }}*
|
||||||
tag_name: ${{ steps.vars.outputs.short_sha }}
|
|
||||||
generate_release_notes: true
|
|
||||||
files: |
|
|
||||||
Downloads/*linux*/*banker*
|
|
||||||
Downloads/*windows*/*banker*
|
|
||||||
Downloads/*macos*/*banker*
|
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
>When you run the program, it will ask you to give resource capacity for A, B and C.
|
>When you run the program, it will ask you to give resource capacity for A, B and C.
|
||||||
|
|
||||||

|
<img src=assets/matrix.png>
|
||||||
|
|
||||||
|
|
||||||
>Program will create solvable matrixses and waits for you to give process queue correctly then checks your result.
|
>Program will create solvable matrixses and waits for you to give process queue correctly then checks your result.
|
||||||
|
|
||||||

|
<img src=assets/interaction.png>
|
||||||
|
|
||||||
|
|
||||||
>At the end you can check your answers.
|
>At the end you can check your answers.
|
||||||
|
|
BIN
assets/interaction.png
Normal file
BIN
assets/interaction.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 126 KiB |
BIN
assets/matrix.png
Normal file
BIN
assets/matrix.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 135 KiB |
304
src/main.rs
304
src/main.rs
|
@ -3,65 +3,33 @@ use std::io;
|
||||||
|
|
||||||
const PROCESS_COUNT: usize = 5;
|
const PROCESS_COUNT: usize = 5;
|
||||||
const RESOURCE_COUNT: usize = 3;
|
const RESOURCE_COUNT: usize = 3;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
|
|
||||||
let mut restart: bool = true;
|
let mut restart: bool = true;
|
||||||
while restart {
|
while restart {
|
||||||
println!("Max A Resource");
|
println!("Max A Resource");
|
||||||
let a: u8;
|
let a = match get_u8_input() {
|
||||||
let b: u8;
|
Some(resource_input) => resource_input,
|
||||||
let c: u8;
|
None => return,
|
||||||
let mut resource_input: String = String::new();
|
};
|
||||||
if let Err(err_val) = io::stdin().read_line(&mut resource_input) {
|
|
||||||
println!("Failed to Read: {}", err_val);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
match resource_input.trim().parse::<u8>() {
|
|
||||||
Ok(value) => {
|
|
||||||
a = value;
|
|
||||||
}
|
|
||||||
Err(err_val) => {
|
|
||||||
println!("Failed to Convert: {}", err_val);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Max B Resource");
|
println!("Max B Resource");
|
||||||
let mut resource_input: String = String::new();
|
let b = match get_u8_input() {
|
||||||
if let Err(err_val) = io::stdin().read_line(&mut resource_input) {
|
Some(resource_input) => resource_input,
|
||||||
println!("Failed to Read: {}", err_val);
|
None => return,
|
||||||
return;
|
};
|
||||||
}
|
|
||||||
match resource_input.trim().parse::<u8>() {
|
|
||||||
Ok(value) => {
|
|
||||||
b = value;
|
|
||||||
}
|
|
||||||
Err(err_val) => {
|
|
||||||
println!("Failed to Convert: {}", err_val);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Max C Resource");
|
println!("Max C Resource");
|
||||||
let mut resource_input: String = String::new();
|
let c = match get_u8_input() {
|
||||||
if let Err(err_val) = io::stdin().read_line(&mut resource_input) {
|
Some(resource_input) => resource_input,
|
||||||
println!("Failed to Read: {}", err_val);
|
None => return,
|
||||||
return;
|
};
|
||||||
}
|
|
||||||
match resource_input.trim().parse::<u8>() {
|
|
||||||
Ok(value) => {
|
|
||||||
c = value;
|
|
||||||
}
|
|
||||||
Err(err_val) => {
|
|
||||||
println!("Failed to Convert: {}", err_val);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("\n\tA = {}\n\tB = {}\n\tC = {}", a, b, c);
|
println!("\n\tA = {}\n\tB = {}\n\tC = {}", a, b, c);
|
||||||
if a == 0 || b == 0 || c == 0 {
|
if a == 0 || b == 0 || c == 0 {
|
||||||
println!("Exit: Zero as a Input Invalid");
|
eprintln!("Exit: Zero as a Input is Invalid");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,36 +37,13 @@ fn main() {
|
||||||
let mut assigned_resources_matrix = [[0_u8; RESOURCE_COUNT]; PROCESS_COUNT];
|
let mut assigned_resources_matrix = [[0_u8; RESOURCE_COUNT]; PROCESS_COUNT];
|
||||||
let mut info: (bool, Vec<u8>) = (false, Vec::with_capacity(PROCESS_COUNT));
|
let mut info: (bool, Vec<u8>) = (false, Vec::with_capacity(PROCESS_COUNT));
|
||||||
while !info.0 {
|
while !info.0 {
|
||||||
for i in 0..PROCESS_COUNT {
|
assign_resource_matrix(
|
||||||
let mut rng = rand::thread_rng();
|
&mut max_needs_matrix,
|
||||||
let random = rng.gen_range(0..a);
|
&mut assigned_resources_matrix,
|
||||||
max_needs_matrix[i][0] = random;
|
a,
|
||||||
if random != 0 {
|
b,
|
||||||
assigned_resources_matrix[i][0] = rng.gen_range(0..random);
|
c,
|
||||||
} else {
|
);
|
||||||
assigned_resources_matrix[i][0] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for i in 0..PROCESS_COUNT {
|
|
||||||
let mut rng = rand::thread_rng();
|
|
||||||
let random = rng.gen_range(0..b);
|
|
||||||
max_needs_matrix[i][1] = random;
|
|
||||||
if random != 0 {
|
|
||||||
assigned_resources_matrix[i][1] = rng.gen_range(0..random);
|
|
||||||
} else {
|
|
||||||
assigned_resources_matrix[i][1] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for i in 0..PROCESS_COUNT {
|
|
||||||
let mut rng = rand::thread_rng();
|
|
||||||
let random = rng.gen_range(0..c);
|
|
||||||
max_needs_matrix[i][2] = random;
|
|
||||||
if random != 0 {
|
|
||||||
assigned_resources_matrix[i][2] = rng.gen_range(0..random);
|
|
||||||
} else {
|
|
||||||
assigned_resources_matrix[i][2] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
info = banker(a, b, c, max_needs_matrix, assigned_resources_matrix);
|
info = banker(a, b, c, max_needs_matrix, assigned_resources_matrix);
|
||||||
}
|
}
|
||||||
println!("Max Needs Matrix");
|
println!("Max Needs Matrix");
|
||||||
|
@ -106,34 +51,34 @@ fn main() {
|
||||||
println!("Assigned Resources Matrix");
|
println!("Assigned Resources Matrix");
|
||||||
print_matrix(assigned_resources_matrix);
|
print_matrix(assigned_resources_matrix);
|
||||||
let mut answers: [u8; PROCESS_COUNT] = [0; PROCESS_COUNT];
|
let mut answers: [u8; PROCESS_COUNT] = [0; PROCESS_COUNT];
|
||||||
for i in 0..PROCESS_COUNT {
|
for (answer, correct_answer) in answers.iter_mut().zip(&info.1) {
|
||||||
println!("Which Process Should be Done Now ?");
|
println!("Which Process Should be Done Now ?");
|
||||||
let mut input = String::new();
|
match get_u8_input() {
|
||||||
io::stdin().read_line(&mut input).unwrap();
|
Some(input) => {
|
||||||
let input: u8 = input.trim().parse().unwrap();
|
*answer = input;
|
||||||
answers[i] = input;
|
if *correct_answer == input {
|
||||||
if info.1[i] == input {
|
println!("Correct");
|
||||||
println!("Correct");
|
} else {
|
||||||
} else {
|
println!("Wrong it should be = {}", correct_answer);
|
||||||
println!("Wrong it should be = {}", info.1[i]);
|
}
|
||||||
|
}
|
||||||
|
None => return,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("Your Answers");
|
println!("Your Answers");
|
||||||
for i in 0..PROCESS_COUNT {
|
for answer in answers {
|
||||||
println!("P{}", answers[i]);
|
println!("P{}", answer);
|
||||||
}
|
}
|
||||||
println!("Correct Answers");
|
println!("Correct Answers");
|
||||||
for i in 0..PROCESS_COUNT {
|
for correct_answer in info.1 {
|
||||||
println!("P{}", info.1[i]);
|
println!("P{}", correct_answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut resource_input: String = String::new();
|
|
||||||
println!("Press 'r' to Restart");
|
println!("Press 'r' to Restart");
|
||||||
if let Err(err_val) = io::stdin().read_line(&mut resource_input) {
|
let resource_input = match get_input() {
|
||||||
println!("Failed to Read: {}", err_val);
|
Some(input) => input,
|
||||||
return;
|
None => return,
|
||||||
}
|
};
|
||||||
resource_input = resource_input.trim().to_string();
|
|
||||||
match resource_input.as_str() {
|
match resource_input.as_str() {
|
||||||
"r" => {
|
"r" => {
|
||||||
restart = true;
|
restart = true;
|
||||||
|
@ -146,18 +91,70 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_input() -> Option<String> {
|
||||||
|
let mut input: String = String::new();
|
||||||
|
if let Err(err_val) = io::stdin().read_line(&mut input) {
|
||||||
|
eprintln!("Error: Failed to Read | {}", err_val);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(input.trim_end().to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_u8_input() -> Option<u8> {
|
||||||
|
match get_input() {
|
||||||
|
Some(input) => match input.parse::<u8>() {
|
||||||
|
Ok(input) => Some(input),
|
||||||
|
Err(err_val) => {
|
||||||
|
eprintln!("Error: Failed to Convert | {}", err_val);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn assign_resource_matrix_column(
|
||||||
|
max_needs_matrix: &mut [[u8; RESOURCE_COUNT]; PROCESS_COUNT],
|
||||||
|
assigned_resources_matrix: &mut [[u8; RESOURCE_COUNT]; PROCESS_COUNT],
|
||||||
|
random_limit: u8,
|
||||||
|
which_resource: usize,
|
||||||
|
) {
|
||||||
|
for i in 0..PROCESS_COUNT {
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
let random = rng.gen_range(0..random_limit);
|
||||||
|
max_needs_matrix[i][which_resource] = random;
|
||||||
|
if random != 0 {
|
||||||
|
assigned_resources_matrix[i][which_resource] = rng.gen_range(0..random);
|
||||||
|
} else {
|
||||||
|
assigned_resources_matrix[i][which_resource] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn assign_resource_matrix(
|
||||||
|
max_needs_matrix: &mut [[u8; RESOURCE_COUNT]; PROCESS_COUNT],
|
||||||
|
assigned_resources_matrix: &mut [[u8; RESOURCE_COUNT]; PROCESS_COUNT],
|
||||||
|
a: u8,
|
||||||
|
b: u8,
|
||||||
|
c: u8,
|
||||||
|
) {
|
||||||
|
assign_resource_matrix_column(max_needs_matrix, assigned_resources_matrix, a, 0);
|
||||||
|
assign_resource_matrix_column(max_needs_matrix, assigned_resources_matrix, b, 1);
|
||||||
|
assign_resource_matrix_column(max_needs_matrix, assigned_resources_matrix, c, 2);
|
||||||
|
}
|
||||||
|
|
||||||
fn print_matrix(matrix: [[u8; RESOURCE_COUNT]; PROCESS_COUNT]) {
|
fn print_matrix(matrix: [[u8; RESOURCE_COUNT]; PROCESS_COUNT]) {
|
||||||
for i in 0..5 {
|
for (i, matrix_column) in matrix.iter().enumerate() {
|
||||||
print!("\n\t Process {}: ", i);
|
print!("\n\t Process {}: ", i);
|
||||||
for j in 0..3 {
|
for matrix_value in matrix_column {
|
||||||
if matrix[i][j] > 99 {
|
if *matrix_value > 99 {
|
||||||
print!(" ");
|
print!(" ");
|
||||||
} else if matrix[i][j] > 9 {
|
} else if *matrix_value > 9 {
|
||||||
print!(" ");
|
print!(" ");
|
||||||
} else {
|
} else {
|
||||||
print!(" ");
|
print!(" ");
|
||||||
}
|
}
|
||||||
print!("{}", matrix[i][j]);
|
print!("{}", *matrix_value);
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
@ -217,63 +214,62 @@ fn banker(
|
||||||
infinite_detection -= 1;
|
infinite_detection -= 1;
|
||||||
|
|
||||||
for i in 0..PROCESS_COUNT {
|
for i in 0..PROCESS_COUNT {
|
||||||
if !done[i] {
|
if !done[i]
|
||||||
if a_remaining >= remaining_needs_matrix[i][0]
|
&& a_remaining >= remaining_needs_matrix[i][0]
|
||||||
&& b_remaining >= remaining_needs_matrix[i][1]
|
&& b_remaining >= remaining_needs_matrix[i][1]
|
||||||
&& c_remaining >= remaining_needs_matrix[i][2]
|
&& c_remaining >= remaining_needs_matrix[i][2]
|
||||||
{
|
{
|
||||||
match a_remaining.checked_sub(remaining_needs_matrix[i][0]) {
|
match a_remaining.checked_sub(remaining_needs_matrix[i][0]) {
|
||||||
Some(result) => {
|
Some(result) => {
|
||||||
a_remaining = result;
|
a_remaining = result;
|
||||||
}
|
|
||||||
None => {
|
|
||||||
return (false, vec![]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
match a_remaining.checked_add(max_needs_matrix[i][0]) {
|
None => {
|
||||||
Some(result) => {
|
return (false, vec![]);
|
||||||
a_remaining = result;
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
return (false, vec![]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
match b_remaining.checked_sub(remaining_needs_matrix[i][1]) {
|
|
||||||
Some(result) => {
|
|
||||||
b_remaining = result;
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
return (false, vec![]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
match b_remaining.checked_add(max_needs_matrix[i][1]) {
|
|
||||||
Some(result) => {
|
|
||||||
b_remaining = result;
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
return (false, vec![]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
match c_remaining.checked_sub(remaining_needs_matrix[i][2]) {
|
|
||||||
Some(result) => {
|
|
||||||
c_remaining = result;
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
return (false, vec![]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
match c_remaining.checked_add(max_needs_matrix[i][2]) {
|
|
||||||
Some(result) => {
|
|
||||||
c_remaining = result;
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
return (false, vec![]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
done[i] = true;
|
|
||||||
q.push(i as u8);
|
|
||||||
infinite_detection = 2;
|
|
||||||
}
|
}
|
||||||
|
match a_remaining.checked_add(max_needs_matrix[i][0]) {
|
||||||
|
Some(result) => {
|
||||||
|
a_remaining = result;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
return (false, vec![]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match b_remaining.checked_sub(remaining_needs_matrix[i][1]) {
|
||||||
|
Some(result) => {
|
||||||
|
b_remaining = result;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
return (false, vec![]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match b_remaining.checked_add(max_needs_matrix[i][1]) {
|
||||||
|
Some(result) => {
|
||||||
|
b_remaining = result;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
return (false, vec![]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match c_remaining.checked_sub(remaining_needs_matrix[i][2]) {
|
||||||
|
Some(result) => {
|
||||||
|
c_remaining = result;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
return (false, vec![]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match c_remaining.checked_add(max_needs_matrix[i][2]) {
|
||||||
|
Some(result) => {
|
||||||
|
c_remaining = result;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
return (false, vec![]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
done[i] = true;
|
||||||
|
q.push(i as u8);
|
||||||
|
infinite_detection = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if infinite_detection == 0 {
|
if infinite_detection == 0 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue