Skip to content

Commit

Permalink
feat: add ex07
Browse files Browse the repository at this point in the history
  • Loading branch information
leogaudin committed Aug 31, 2024
1 parent 6eeff56 commit 12d8ec1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ex07.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::ex04::generate_truth_table;

pub fn sat(formula: &str) -> bool {
let truth_table: String = generate_truth_table(formula);
let lines = truth_table.lines();
for line in lines {
if line.ends_with("true") {
return true;
}
}
return false;
}
28 changes: 28 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ use ex05::negation_normal_form;
mod ex06;
use ex06::conjunctive_normal_form;

mod ex07;
use ex07::sat;

fn main() {
println!("\n{}", "EX00 - ADDER".normal().bold());
for _ in 0..42 {
Expand Down Expand Up @@ -226,6 +229,31 @@ fn main() {
);
println!();
}
println!("\n{}", "EX07 - SAT".normal().bold());
let formulas = [
("AB|", true),
("AB&", true),
("AA!&", false),
("AA^", false),
("AA!&BB!&|", false),
];

for formula in formulas {
println!(
"{}\t{} {}",
if sat(formula.0) == formula.1 {
"OK".green().bold()
} else {
"KO".red().bold()
},
formula.0,
if sat(formula.0) {
"can be satisfied"
} else {
"cannot be satisfied"
},
);
}
}

fn check_conjunctions(formula: &str) -> bool {
Expand Down

0 comments on commit 12d8ec1

Please sign in to comment.