Skip to content

Instantly share code, notes, and snippets.

@Zelakolase
Created September 13, 2021 21:36
Show Gist options
  • Save Zelakolase/3583d3a8df2c9b529e32840386ca2e28 to your computer and use it in GitHub Desktop.
Save Zelakolase/3583d3a8df2c9b529e32840386ca2e28 to your computer and use it in GitHub Desktop.
This program makes a AI Logical network for 2 unary logical gates.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class UnaryAI {
/*
* AI using Unary Logical Gates
* Dataset in hashmap goes to a train function, iterate to PatternFinder, test
*/
public static void main(String[] args) {
HashMap<String,String> dataset = new HashMap<String,String>() { // Input,Output
{
put("true","false");
}
};
// Train, put LogicalGatesMap in a variable
ArrayList<String> LGM = train(dataset);
System.out.println(process("false", LGM)); // should return true, based on the rule that was detected
}
public static ArrayList<String> train(HashMap<String,String> dataset) {
ArrayList<String> instructions = new ArrayList<String>();
for (Map.Entry<String, String> set : dataset.entrySet()) {
if(Boolean.valueOf(set.getKey()) != Boolean.valueOf(set.getValue())) {
instructions.add("NOT"); // unary not gate instruction
}else {
instructions.add("NULL"); // unary null gate instruction
}
}
return instructions;
}
public static boolean process(String input, ArrayList<String> LGM) {
if(LGM.contains("NOT")) {
return ! Boolean.valueOf(input);
}else {
return Boolean.valueOf(input);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment