This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | |
**/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}})); | |
} |