Skip to content

Instantly share code, notes, and snippets.

@TheGloriousGenesis
TheGloriousGenesis / table.csv
Last active March 1, 2021 20:15
Table on some PCG method I might want to look at
ALGORITHM BEST EVALUATION
SPACE PARTITION ALGORITHMS (2): --
Binary Space Partitioning Trees N/A
Agent based generation (A* - FSM - blind digger) Steps taken - agent based
Cellular Automata N/A
PLATFORM GENERATION ALGORITHMS (3): --
Rhythms Linearity/Leniency - edit distance - Rhythm Group Analysis (agglomerative hierarchical clustering method)-> Launchpad
Occupancy regulated extension -
Probabilistic multi-pass generator -
LANDSCAPE GENERATION ALGORITHMS(4): --
@TheGloriousGenesis
TheGloriousGenesis / StackWithMax.java
Created May 10, 2020 22:32
Stack data type with max
public class StackWithMax {
private Node head;
private int maximum = 0;
private int pointer = 0;
public StackWithMax() {
}
public void push(final Integer value) {
if (value >= maximum) {
import java.util.Stack;
public class QueueWithTwoStacks {
public Stack<Integer> temp = new Stack<>();
public Stack<Integer> mockQueue = new Stack<>();
public void enqueue(final Integer value) {
for (int i=1; i <= mockQueue.size(); i++) {
temp.add(mockQueue.pop());
}
@TheGloriousGenesis
TheGloriousGenesis / EvaluatingPostFix.java
Created May 9, 2020 17:32
Evaluating post fix expression
public static String operators = "+-^*/";
public static void main(String[] args){
System.out.println(evaluatePostFix("6 2 3 + - 3 8 2 / + * 2 ^ 3 +"));
}
private static int evaluatePostFix(final String infix) {
Stack<Integer> numberStack = new Stack<>();
String[] infixCharacters = infix.split("");
for (String i: infixCharacters) {
@TheGloriousGenesis
TheGloriousGenesis / updatedInfixPostfixAlgo.java
Created May 8, 2020 21:41
Updated version of Infix-Postfix
// could also have a string that contains operators and check if contains;
public static HashMap<Character, Integer> operators = new HashMap<>();
// only push to stack if order higher
public static Stack<Character> operatorStack = new Stack<Character>();
public static StringBuilder postFixNotation = new StringBuilder();
public InfixPostFixAlgo() {
// assign numerical order depending on order of operator in BODMAS
operators.put('^', 5);
operators.put('/', 4);
@TheGloriousGenesis
TheGloriousGenesis / infixToPostFix.java
Created May 6, 2020 22:38
InfixToPostFix conversion
private static String infixToPostfix(final String equation){
Stack<Character> stack = new Stack<Character>();
StringBuilder postFixNotation = new StringBuilder();
HashMap<Character, Integer> operators = new HashMap<>();
operators.put('^', 5);
operators.put('/', 4);
operators.put('*', 3);
operators.put('+', 2);
operators.put('-', 1);
operators.put('(', 0);
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int result = 0;
while(scanner.hasNext()) {
for (String i: scanner.next().split(",")) {
/** XOR: when you XOR with a integer an even number of times
* your return value will be 0 or whatever you started with.
* E.g A ^ B ^ B = A. Hence can iterate through the array and
* only odd one out will remain as everything else is in pairs!
**/
public static void main(String[] args) {
System.out.println(roadsAndLibraries(6, 2, 5,
new int[][]{{1,3},{3,4},{2,4},{1,2},{2,3},{5,6}}));
System.out.println(roadsAndLibraries(3, 2, 1,
new int[][]{{1,2},{3,1},{2,3}}));
System.out.println(roadsAndLibraries(5, 6, 1,
new int[][]{{1,2},{1,3},{1,4}}));
System.out.println(roadsAndLibraries(3, 2, 1,
new int[][]{{1,2},{3,1},{2,3}}));
}