Skip to content

Instantly share code, notes, and snippets.

View otaruMendez's full-sized avatar

Babatunde Otaru otaruMendez

View GitHub Profile
@otaruMendez
otaruMendez / Output.java
Created February 23, 2019 21:10
Printing the Output in the Simulator Class
public void printOutput () {
PrintWriter writer = null;
try {
writer = new PrintWriter(this.fileName + ".out", "UTF-8");
int noOfSlices = pizzaCutter.cutSlices.size();
writer.print(noOfSlices);
writer.println();
@otaruMendez
otaruMendez / Simulate.java
Created February 23, 2019 21:08
Implementing the Simulate method in the Simulator Class (HashCode Practice Pizza Question)
public void simulate() {
pizzaCutter = new PizzaCutter(pizza);
pizzaCutter.cutPizza();
}
@otaruMendez
otaruMendez / ParsingInput.java
Last active February 23, 2019 21:06
Parsing the Input in the Simulator Class (HashCode Practice Pizza Question)
public void parseInput () {
int bufferSize = 8 * 1024;
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader(this.fileName + ".in"), bufferSize);
String line = bufferedReader.readLine();
String[] firstLine = line.split(" ");
pizza = new Pizza();
pizza.rows = Integer.parseInt(firstLine[0]);
@otaruMendez
otaruMendez / Main.java
Created February 23, 2019 20:59
Entry Point for the HashCode Practice Pizza Question
public static void main(String[] args) {
String[] inputs = {"a_example", "b_small", "c_medium", "d_big"};
for (String in: inputs) {
String fileName = "path/to/datasets/" + in;
Simulator simulator = new Simulator(fileName);
simulator.parseInput();
simulator.simulate();
simulator.printOutput();
}
@otaruMendez
otaruMendez / Simulator.java
Last active February 23, 2019 21:19
Simulator Class for the HashCode Practice Pizza Question
public class Simulator {
private String fileName;
private Pizza pizza;
private PizzaCutter pizzaCutter;
public Simulator (String fileName) {
this.fileName = fileName;
}
public void parseInput () {
@otaruMendez
otaruMendez / Slice.java
Created February 23, 2019 20:56
Slice Class for the HashCode Practice Pizza Question
public class Slice {
int startX;
int endX;
int startY;
int endY;
}
@otaruMendez
otaruMendez / PizzaCutter.java
Created February 23, 2019 20:55
PizzaCutter Class for the HashCode Pizza Question
public class PizzaCutter {
Pizza pizza;
ArrayList<Slice> cutSlices = new ArrayList<>();
public PizzaCutter (Pizza pizza) {
this.pizza = pizza;
}
}
@otaruMendez
otaruMendez / Pizza.java
Created February 23, 2019 20:52
The Pizza Class for Hashcode Pizza Question
public class Pizza {
int rows;
int cols;
int minIngredientEachPerSlice;
int maxCellsPerSlice;
HashMap<String, Cell> cells;
int rowLength;
int colLength;
public String getCellHashKey (int x, int y) {
@otaruMendez
otaruMendez / Cell.java
Created February 23, 2019 20:50
Cell Class for the Pizza Question
public class Cell {
int x;
int y;
char ingredient;
boolean cutOut = false;
}
@otaruMendez
otaruMendez / PizzaCutter.java
Last active February 23, 2019 20:09
Explaining the PizzaCutter Algorithm
public class PizzaCutter {
Pizza pizza;
ArrayList<Slice> cutSlices = new ArrayList<>();
public PizzaCutter (Pizza pizza) {
this.pizza = pizza;
}