Histafinder is a Rust application that uses a Satisfiability (SAT) solver to determine which ingredients in a list of meals are likely to cause a reaction. It's designed to help users with dietary restrictions or allergies identify potential trigger ingredients based on their meal logs.
The program takes a structured list of meals and ingredients, along with an indicator of whether a reaction occurred after consuming each meal. It then translates this problem into a SAT problem.
- Each unique ingredient is represented by a boolean variable.
- A variable being
truemeans the ingredient is a potential allergen. - A variable being
falsemeans the ingredient is not an allergen.
The program constructs a Conjunctive Normal Form (CNF) formula with clauses that represent the following logic:
- For meals where a reaction occurred: At least one of the ingredients in that meal must be an allergen. This is represented by a clause like
(ingredient1 ∨ ingredient2 ∨ ... ). - For meals where no reaction occurred: None of the ingredients in that meal can be an allergen. This is represented by a set of clauses, one for each ingredient, like
(¬ingredient1) ∧ (¬ingredient2) ∧ ....
The SAT solver then finds a valid assignment of true or false to each ingredient variable that satisfies all the clauses. The ingredients assigned true are the potential allergens.
- Rust programming language: You can install it from rustup.rs.
-
Clone the repository:
git clone https://github.com/Unaimend/Histafinder cd Histafinder -
Create an input file eg.
file.txt: This file should contain your meal data in the following format:Meal 1: ingredient1, ingredient2, ingredient3 | 1 Meal 2: ingredient4, ingredient5 | 0 Meal 3: ingredient1, ingredient4, ingredient6 | 1 Meal 4: ingredient2, ingredient5, ingredient7 | 0Meal 1:The name of the meal.ingredient1, ingredient2, ...: A comma-separated list of ingredients.| 1or| 0: A1indicates a reaction occurred; a0indicates no reaction.
-
Run the program:
cargo run -- file.txt
The program will print the identified allergens to the console.
This README was written by ChatGPT, the code was not.