diff --git a/src/.vscode/launch.json b/src/.vscode/launch.json deleted file mode 100644 index 277a23c4faec54d3749a0e43694d5227e8947d65..0000000000000000000000000000000000000000 --- a/src/.vscode/launch.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "java", - "name": "Debug (Launch) - Current File", - "request": "launch", - "mainClass": "${file}" - }, - { - "type": "java", - "name": "Debug (Launch)-Main<src_311626d8>", - "request": "launch", - "mainClass": "Main", - "projectName": "src_311626d8" - }, - { - "type": "java", - "name": "Debug (Launch)-TestMain<src_311626d8>", - "request": "launch", - "mainClass": "TestMain", - "projectName": "src_311626d8" - } - ] -} \ No newline at end of file diff --git a/src/TestMain.class b/src/TestMain.class deleted file mode 100644 index e7f9705e0a4b24a56443a47ac8cf938ed973e452..0000000000000000000000000000000000000000 Binary files a/src/TestMain.class and /dev/null differ diff --git a/src/UserData$ChangeListener.class b/src/UserData$ChangeListener.class deleted file mode 100644 index 70e2f5037acc5cb9650070188eebb915bfa28829..0000000000000000000000000000000000000000 Binary files a/src/UserData$ChangeListener.class and /dev/null differ diff --git a/src/UserData.class b/src/UserData.class deleted file mode 100644 index 121c1f9d162a1ddcffebbc8078e1a9cb58579024..0000000000000000000000000000000000000000 Binary files a/src/UserData.class and /dev/null differ diff --git a/src/Util$BoardPosVec.class b/src/Util$BoardPosVec.class deleted file mode 100644 index 95937138e3616da9ea3d85912a3998f92b33b797..0000000000000000000000000000000000000000 Binary files a/src/Util$BoardPosVec.class and /dev/null differ diff --git a/src/Util$Direction.class b/src/Util$Direction.class deleted file mode 100644 index 9d4acba5882d6b8880736640d6dd19f74351d81c..0000000000000000000000000000000000000000 Binary files a/src/Util$Direction.class and /dev/null differ diff --git a/src/Util.class b/src/Util.class deleted file mode 100644 index b038078cedcf2dbb78d12ab1f3babf73fa0a8794..0000000000000000000000000000000000000000 Binary files a/src/Util.class and /dev/null differ diff --git a/src/com/patryk/mathdoku/Action$Type.class b/src/com/patryk/mathdoku/Action$Type.class deleted file mode 100644 index 0eb336881e11ffae88608046c16de650a42a495e..0000000000000000000000000000000000000000 Binary files a/src/com/patryk/mathdoku/Action$Type.class and /dev/null differ diff --git a/src/com/patryk/mathdoku/Action.class b/src/com/patryk/mathdoku/Action.class deleted file mode 100644 index 4c7f6c76eaa9d75da1b3a443fbfffe63f48c83a0..0000000000000000000000000000000000000000 Binary files a/src/com/patryk/mathdoku/Action.class and /dev/null differ diff --git a/src/com/patryk/mathdoku/CageGenerator$BoardReadyFunc.class b/src/com/patryk/mathdoku/CageGenerator$BoardReadyFunc.class deleted file mode 100644 index 198ebfedaea20861c0f8ef33fd4c395b721ce1b2..0000000000000000000000000000000000000000 Binary files a/src/com/patryk/mathdoku/CageGenerator$BoardReadyFunc.class and /dev/null differ diff --git a/src/com/patryk/mathdoku/CageGenerator.class b/src/com/patryk/mathdoku/CageGenerator.class deleted file mode 100644 index a1f6bbe924f5f6f42f7ee5d7a069e9cc1e0e5905..0000000000000000000000000000000000000000 Binary files a/src/com/patryk/mathdoku/CageGenerator.class and /dev/null differ diff --git a/src/com/patryk/mathdoku/LimitedStack.class b/src/com/patryk/mathdoku/LimitedStack.class deleted file mode 100644 index 978c7c81f7d5fbc02740eff84f7a426aada5b131..0000000000000000000000000000000000000000 Binary files a/src/com/patryk/mathdoku/LimitedStack.class and /dev/null differ diff --git a/src/com/patryk/mathdoku/LimitedStackBase.class b/src/com/patryk/mathdoku/LimitedStackBase.class deleted file mode 100644 index c0b77352a8935f00ecfbb56d0c8c3c4172a628a5..0000000000000000000000000000000000000000 Binary files a/src/com/patryk/mathdoku/LimitedStackBase.class and /dev/null differ diff --git a/src/test/.vscode/launch.json b/src/test/.vscode/launch.json deleted file mode 100644 index 7ddb697fd72b7f9ed7f476eb1af1b578a387a556..0000000000000000000000000000000000000000 --- a/src/test/.vscode/launch.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "java", - "name": "Debug (Launch) - Current File", - "request": "launch", - "mainClass": "${file}" - }, - { - "type": "java", - "name": "Debug (Launch)-TestMain<test_5834f569>", - "request": "launch", - "mainClass": "TestMain", - "projectName": "test_5834f569" - } - ] -} \ No newline at end of file diff --git a/src/test/Action.java b/src/test/Action.java deleted file mode 100644 index 132fedb08726e11b21791ad2b1b40a70fc3c1995..0000000000000000000000000000000000000000 --- a/src/test/Action.java +++ /dev/null @@ -1,22 +0,0 @@ -public abstract class Action { - enum Type {CHANGE_CELL_VALUE, CLEAR_BOARD, SAMPLE}; - - private Type type; - private boolean flipped = false; - - public Action(Type type) { - this.type = type; - } - - public Type getType() { - return type; - } - - public boolean isFlipped() { - return flipped; - } - - public void reverse() { - flipped = !flipped; - } -} diff --git a/src/test/LimitedStack.java b/src/test/LimitedStack.java deleted file mode 100644 index 6157315662092299085ea45149085fb5f88c83c5..0000000000000000000000000000000000000000 --- a/src/test/LimitedStack.java +++ /dev/null @@ -1,94 +0,0 @@ -public class LimitedStack<T> implements LimitedStackBase<T> { - final int maxSize; - int size = 0; - int head = 0; - - T[] data; - - public LimitedStack(LimitedStack<T> other) { - this(other.maxSize); - this.size = other.size; - this.head = other.head; - - System.arraycopy(other.data, 0, data, 0, maxSize); - } - - public LimitedStack(int maxSize) { - this.maxSize = maxSize; - data = (T[])new Object[maxSize]; - } - - @Override - public void push(T item) { - if (isFull()) { - head = loop(head, 1); - size--; - } - - data[loop(head, size)] = item; - size++; - } - - public T popHead() { - assert (!isEmpty()); - T a = data[head]; - size--; - head = loop(head, 1); - return a; - } - - /*@Override - public void push(Action item, int pos) { - - }*/ - - @Override - public T pop() { - assert(!isEmpty()); - T item = data[loop(head, size - 1)]; - size--; - return item; - } - - @Override - public boolean isEmpty() { - return size == 0; - } - - public T[] toArray() { - T[] arr = (T[]) new Object[size]; - for (int i = 0; i < size; i ++) { - arr[i] = data[loop(head, i)]; - } - return arr; - } - - @Override - public boolean isFull() { - return size == maxSize; - } - - private int loop(int index,int offset) { - return (index + offset) % maxSize; - } - - @Override - public void clear() { - size = 0; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append('['); - for (int i = 0; i < size; i++) { - sb.append(data[loop(head, i)]); - sb.append(", "); - } - sb.append(']'); - return sb.toString(); - - - } - -} diff --git a/src/test/LimitedStackBase.java b/src/test/LimitedStackBase.java deleted file mode 100644 index 2d44818a3e0871ca89d2ea49f48a913490828c09..0000000000000000000000000000000000000000 --- a/src/test/LimitedStackBase.java +++ /dev/null @@ -1,14 +0,0 @@ -public interface LimitedStackBase<E> { - /** - * Pushes item at the end - */ - void push(E item); - //void push(E item, int pos); - E pop(); - - boolean isEmpty(); - boolean isFull(); - E popHead(); - void clear(); - -} diff --git a/src/test/SampleAction.java b/src/test/SampleAction.java deleted file mode 100644 index 1f2ea7247ade37dc9689e989e530fde69921dd85..0000000000000000000000000000000000000000 --- a/src/test/SampleAction.java +++ /dev/null @@ -1,12 +0,0 @@ -public class SampleAction extends Action { - String message; - public SampleAction(String message) { - super(Type.SAMPLE); - this.message = message; - } - - @Override - public String toString() { - return message; - } -} diff --git a/src/test/TestMain.java b/src/test/TestMain.java deleted file mode 100644 index d9de9d3b0bae2f49a0fff668f4be6fa18329b07b..0000000000000000000000000000000000000000 --- a/src/test/TestMain.java +++ /dev/null @@ -1,14 +0,0 @@ -public class TestMain { - public static void main(String[] args) { - LimitedStack stack = new LimitedStack(3); - stack.push(new SampleAction("aardvark")); - stack.push(new SampleAction("pig")); - stack.push(new SampleAction("dog")); - stack.push(new SampleAction("sheep")); - stack.push(new SampleAction("wolf")); - stack.push(new SampleAction("horse")); - Action temp = stack.pop(); - temp = stack.pop(); - temp = stack.pop(); - } -} diff --git a/src/trash/Action.java b/src/trash/Action.java deleted file mode 100644 index 132fedb08726e11b21791ad2b1b40a70fc3c1995..0000000000000000000000000000000000000000 --- a/src/trash/Action.java +++ /dev/null @@ -1,22 +0,0 @@ -public abstract class Action { - enum Type {CHANGE_CELL_VALUE, CLEAR_BOARD, SAMPLE}; - - private Type type; - private boolean flipped = false; - - public Action(Type type) { - this.type = type; - } - - public Type getType() { - return type; - } - - public boolean isFlipped() { - return flipped; - } - - public void reverse() { - flipped = !flipped; - } -} diff --git a/src/trash/CircularActionRecorder.java b/src/trash/CircularActionRecorder.java deleted file mode 100644 index c9ae939bf7ce3d5d10ef41ce04c178d32ab68b4f..0000000000000000000000000000000000000000 --- a/src/trash/CircularActionRecorder.java +++ /dev/null @@ -1,52 +0,0 @@ -public class CircularActionRecorder<E> implements ActionRecorderBase<E> { - - private final int maxSize = 3; - E[] actions = new E[maxSize]; - - int head = 0; // the actual index in the internal array reflecting the beginning of the list - int size = 0; // total number of elements, both undoable and redoable (max as specified) - int nRedoable = 0; - - @Override - public void record(E action) { - if (size == maxSize) { - head = loopForward(head,1); - size--; - } - - size -= nRedoable; - - actions[loopForward(head, size)] = action; - - size++; - } - - @Override - public E undo() { - assert (canUndo()); - E a = actions[loopForward(head, size - 1)]; - nRedoable++; - - return a; - - } - - @Override - public E redo() { - assert (canRedo()); - E a = actions[loopForward(head, size - 1)]; - nRedoable++; - return a; - } - - @Override - public boolean canUndo() { - return (size != nRedoable); - } - - @Override - public boolean canRedo() { - return nRedoable != 0; - } - -} diff --git a/src/trash/GameContext.java b/src/trash/GameContext.java deleted file mode 100644 index af47088b9d7a953bec95a3737432ef87d1697409..0000000000000000000000000000000000000000 --- a/src/trash/GameContext.java +++ /dev/null @@ -1,46 +0,0 @@ -//a singleton class -public class GameContext { - private int canvasPixelWidth; - private int boardWidth; - - private int squarePixelWidth; - - private static GameContext instance; - - - private GameContext(int canvasPixelWidth, int boardWidth) { - this.canvasPixelWidth = canvasPixelWidth; - this.boardWidth = boardWidth; - - squarePixelWidth = canvasPixelWidth / boardWidth; - } - - public static void init(int canvasPixelWidth, int boardWidth) { - instance = new GameContext(canvasPixelWidth, boardWidth); - } - - public static GameContext getInstance() throws NoContextException{ - if (instance == null) { - throw new NoContextException(); - } - return instance; - } - - public int getCanvasPixelWidth() { - return canvasPixelWidth; - } - - public int getBoardWidth() { - return boardWidth; - } - - public int getSquarePixelWidth() { - return squarePixelWidth; - } -} - -class NoContextException extends RuntimeException{ - NoContextException() { - super("You must first create a game context before any resource tries to obtain it."); - } -} diff --git a/src/trash/Generator.java b/src/trash/Generator.java deleted file mode 100644 index 538ecf8b2176e954d8fc9ed834c45f72039a8cfe..0000000000000000000000000000000000000000 --- a/src/trash/Generator.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.patryk.mathdoku.cage; - -import com.patryk.mathdoku.global.BoardPosVec; -import com.patryk.mathdoku.UserData; - -import java.util.BitSet; - -public class Generator { - public interface BoardReadyFunc { - void onBoardReady(UserData board); - } - - private BitSet[] colForbidden; - private BitSet[] rowForbidden; - private int size; - private UserData data; - private BoardReadyFunc boardReadyFunc; - - private static BitSet[] getBitsSetArray(int size) { - BitSet[] a = new BitSet[size]; - for (int i = 0; i < size; i++) { - a[i] = new BitSet(size); - } - return a; - } - - private Generator(int size, BoardReadyFunc boardReadyFunc) { - this.size = size; - this.data = new UserData(size); - this.boardReadyFunc = boardReadyFunc; - colForbidden = getBitsSetArray(size); - rowForbidden = getBitsSetArray(size); - } - - public static void perform(int size, BoardReadyFunc boardReadyFunc) { - new Generator(size, boardReadyFunc).f(BoardPosVec.zero()); - } - - private void f(BoardPosVec cell) { - //get bit vector of forbidden values for that row and column - BitSet forbiddenNums = new BitSet(); - forbiddenNums.or(colForbidden[cell.c]); - forbiddenNums.or(rowForbidden[cell.r]); - for (int i = 1; i <= size; i++) { - //if that value is not forbidden - if (!forbiddenNums.get(i)) { - //give current cell that number - data.setValueAtCell(cell, i); - if (cell.isLast()) { - boardReadyFunc.onBoardReady(data); - return; - } - //make this number forbidden in rows and columns - colForbidden[cell.c].set(i, true); - rowForbidden[cell.r].set(i, true); - //go to next cell and recursively do the same - f(cell.next()); - //after that is done, make this number no longer forbidden - colForbidden[cell.c].set(i, false); - rowForbidden[cell.r].set(i, false); - //assert(forbiddenNums.equals(colForbidden[cell.c].or(rowForbidden[cell.r]))); - //but don't remove the number; it will be ignored and later overwritten anyway - } - } - } - -} \ No newline at end of file diff --git a/src/trash/MathDoku.java b/src/trash/MathDoku.java deleted file mode 100644 index 3edbff4c77088357e7e90f4e320ea2499814bc41..0000000000000000000000000000000000000000 --- a/src/trash/MathDoku.java +++ /dev/null @@ -1,186 +0,0 @@ -import javafx.application.Application; -import javafx.application.Platform; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; - -import javafx.scene.input.KeyEvent; -import javafx.scene.input.MouseEvent; -import javafx.stage.Stage; - -public class MathDoku extends Application { - - private static int canvasPixelWidth = 600; - private static int boardWidth = 6; - - UI ui; - - private InitialData initialData; - private UserData userData; - - public static ActionRecorderBase<Action> actionRecorder = new CircularActionRecorder(); - - public static int getCanvasPixelWidth() { - return canvasPixelWidth; - } - - public static int getBoardWidth() { - return boardWidth; - } - - public static int getSquarePixelWidth() { - return canvasPixelWidth / boardWidth; - } - - @Override - public void start(Stage primaryStage) throws Exception{ - //GameContext.init(canvasPixelWidth, boardWidth); - - //create the canvas and put it in the window - primaryStage.setTitle("Mathdoku"); - - //create the constant game data - initialData = new InitialData("example.txt"); - userData = new UserData(); - - ui = new UI(initialData, userData); - - markedCellProperty.addListener(new ChangeListener<Util.BoardPosVec>() { - @Override - public void changed(ObservableValue<? extends Util.BoardPosVec> observableValue, Util.BoardPosVec oldPos, Util.BoardPosVec newPos) { - redrawMarkedCell(); - } - }); - - - ui.getScene().setOnKeyPressed(new EventHandler<KeyEvent>() { - @Override - public void handle(KeyEvent keyEvent) { - switch (keyEvent.g) - }); - - - - ui.undoButton.addEventHandler(ActionEvent.ANY, new EventHandler<ActionEvent>() { - @Override - public void handle(ActionEvent actionEvent) { - undo(); - } - }); - - ui.redoButton.addEventHandler(ActionEvent.ANY, new EventHandler<ActionEvent>() { - @Override - public void handle(ActionEvent actionEvent) { - redo(); - } - }); - - ui.clearButton.addEventHandler(ActionEvent.ANY, new EventHandler<ActionEvent>() { - @Override - public void handle(ActionEvent actionEvent) { - clear(); - } - }); - - - userDataDrawer.draw(); - - primaryStage.setScene(ui.getScene()); - - - primaryStage.show(); - } - - /** - * also checks if the digit is in range - * @param cell - * @param digit - */ - private void appendDigitToCell(Util.BoardPosVec cell, char digit) { - int newValue = Util.charToInt(digit); - if (newValue <= GameContext.getInstance().getBoardWidth()) - setValueAtCell(cell, newValue); - } - - - - private Util.BoardPosVec getSelectedCell() { - return this.markedCellProperty.get(); - } - - private void redrawMarkedCell() { - //TODO set colours, line width - //clear canvas - //re-draw the marked cell - //drawSquare(markedCellCanvas.getGraphicsContext(), markedCellProperty.getValue()); - selectedCellDrawer.draw(); - - } - - private void setSelectedCell(Util.BoardPosVec pos) { - - //Util.BoardPosVec newValue = markedCellProperty.get().add(direction.vector); - //if change has occured to the value - if (!pos.clampToArea()) { - markedCellProperty.set(pos); - } - } - - private void undo() { - if (actionRecorder.canUndo()) { - Action action = actionRecorder.undo(); - if (action.isFlipped()) { - redoAction(action); - } else { - undoAction(action); - } - - } - } - - private void redo() { - if(actionRecorder.canRedo()) { - Action action = actionRecorder.redo(); - if (action.isFlipped()) { - undoAction(action); - } else { - redoAction(action); - } - } - } - - public void redoAction(Action action) { - switch (action.getType()) { - case CHANGE_CELL_VALUE: - redoSpecificAction((CellValueChangeAction) action); - break; - default: - } } - - public void undoAction(Action action) { - switch (action.getType()) { - case CHANGE_CELL_VALUE: - undoSpecificAction((CellValueChangeAction) action); - break; - default: - } - } - - private void undoSpecificAction(CellValueChangeAction action) { - userData.setValueAtCell(action.getCell(), action.getOldValue()); - userDataDrawer.draw(); - } - - public void redoSpecificAction(CellValueChangeAction action) { - userData.setValueAtCell(action.getCell(), action.getNewValue()); - userDataDrawer.draw(); - } - - - - public static void main(String[] args) { - launch(args); - } -} diff --git a/src/trash/SampleAction.java b/src/trash/SampleAction.java deleted file mode 100644 index 1f2ea7247ade37dc9689e989e530fde69921dd85..0000000000000000000000000000000000000000 --- a/src/trash/SampleAction.java +++ /dev/null @@ -1,12 +0,0 @@ -public class SampleAction extends Action { - String message; - public SampleAction(String message) { - super(Type.SAMPLE); - this.message = message; - } - - @Override - public String toString() { - return message; - } -} diff --git a/src/trash/TestMain.java b/src/trash/TestMain.java deleted file mode 100644 index d9de9d3b0bae2f49a0fff668f4be6fa18329b07b..0000000000000000000000000000000000000000 --- a/src/trash/TestMain.java +++ /dev/null @@ -1,14 +0,0 @@ -public class TestMain { - public static void main(String[] args) { - LimitedStack stack = new LimitedStack(3); - stack.push(new SampleAction("aardvark")); - stack.push(new SampleAction("pig")); - stack.push(new SampleAction("dog")); - stack.push(new SampleAction("sheep")); - stack.push(new SampleAction("wolf")); - stack.push(new SampleAction("horse")); - Action temp = stack.pop(); - temp = stack.pop(); - temp = stack.pop(); - } -} diff --git a/trivial/.vscode/launch.json b/trivial/.vscode/launch.json deleted file mode 100644 index 5cfc0d3c2f363dba66c2e9a531b33f01f3b2b66c..0000000000000000000000000000000000000000 --- a/trivial/.vscode/launch.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "java", - "name": "Debug (Launch) - Current File", - "request": "launch", - "mainClass": "${file}" - }, - { - "type": "java", - "name": "Debug (Launch)-Permutations<trivial_ee8fd3d>", - "request": "launch", - "mainClass": "Permutations", - "projectName": "trivial_ee8fd3d" - } - ] -} \ No newline at end of file diff --git a/trivial/.vscode/settings.json b/trivial/.vscode/settings.json deleted file mode 100644 index 4394105e66d0db88a175e777ac25fb50370af249..0000000000000000000000000000000000000000 --- a/trivial/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.pythonPath": "/sbin/python3.8" -} \ No newline at end of file diff --git a/trivial/CageGenerator.java b/trivial/CageGenerator.java deleted file mode 100644 index 875d603c472f6d4478f00482ae5fd6b723940a95..0000000000000000000000000000000000000000 --- a/trivial/CageGenerator.java +++ /dev/null @@ -1,48 +0,0 @@ -import java.util.BitSet; - -public class CageGenerator { - public interface BoardReadyFunc { - void onBoardReady(UserData board); - } - - private BitSet[] colForbidden; - private BitSet[] rowForbidden; - private int size; - private UserData data; - private BoardReadyFunc boardReadyFunc; - - public void perform(UserData data, BoardReadyFunc boardReadyFunc) { - this.size = data.size; - this.data = data; - this.boardReadyFunc = boardReadyFunc; - colForbidden = new BitSet[size]; - rowForbidden = new BitSet[size]; - f(Util.BoardPosVec.zero()); - } - - private void f(Util.BoardPosVec cell) { - //get bit vector of forbidden values for that row and column - BitSet forbiddenNums = colForbidden[cell.c].or(rowForbidden[cell.r]); - for (int i = 1; i <= size; i++) { - //if that value is not forbidden - if (!forbiddenNums.get(i)) { - //give current cell that number - data.setValueAtCell(cell, i); - if (cell.isLast()) { - boardReadyFunc.onBoardReady(data); - return; - } - //make this number forbidden in rows and columns - colForbidden[cell.c].set(i, true); - rowForbidden[cell.r].set(i, true); - //go to next cell and recursively do the same - f(cell.next()); - //after that is done, make this number no longer forbidden - colForbidden[cell.c].set(i, false); - rowForbidden[cell.r].set(i, false); - assert(forbiddenNums.equals(colForbidden[cell.c].or(rowForbidden[cell.r]))); - //but don't remove the number; it will be ignored and later overwritten anyway - } - } - } -} \ No newline at end of file diff --git a/trivial/Permutations$1.class b/trivial/Permutations$1.class deleted file mode 100644 index 80e115ad153f305a8cde18394d50412f06b0c9a0..0000000000000000000000000000000000000000 Binary files a/trivial/Permutations$1.class and /dev/null differ diff --git a/trivial/Permutations$Sign.class b/trivial/Permutations$Sign.class deleted file mode 100644 index 8228fa2fd81ea93155270fb665d2557526e1fe82..0000000000000000000000000000000000000000 Binary files a/trivial/Permutations$Sign.class and /dev/null differ diff --git a/trivial/Permutations.class b/trivial/Permutations.class deleted file mode 100644 index a5076dc8e3adf43e075956edc57b552e2372d2e3..0000000000000000000000000000000000000000 Binary files a/trivial/Permutations.class and /dev/null differ diff --git a/trivial/Permutations.java b/trivial/Permutations.java deleted file mode 100644 index 6691a73631ccc57de6afbe6478bd64900713da2e..0000000000000000000000000000000000000000 --- a/trivial/Permutations.java +++ /dev/null @@ -1,67 +0,0 @@ -public class Permutations { - public enum Sign {PLUS, MINUS, MULTIPLY, DIVIDE}; - - //public boolean fits(int target, int[] nums) { - - /*checks if target can be formed by applying op1 with sign sign to any integer in the list or by also - additionally recursively applying each result to the remainders in the list. - */ - - private int operation(int operand1, int operand2, Sign operator) { - switch (operator) { - case PLUS: - return operand1 + operand2; - case MINUS: - return operand1 - operand2; - case MULTIPLY: - return operand1 * operand2; - case DIVIDE: - return Math.floorDiv(operand1, operand2); - default: - return -1; - - } - } - - boolean permute; - Sign operator; - int target = 240; - - private boolean f(int result,int[] cageList, int startIndex, int depth) { - //System.out.println("Analyzing " + result); - if (result == target) - return true; - for (int i = startIndex; i < cageList.length; i++) { - if (cageList[i] != -1) { - int e = cageList[i]; - int newResult = depth == 0 ? e : operation(result, e, operator); - //int newResult = e; - if (operator == Sign.DIVIDE && result % e != 0) { - //System.out.println(e + " Not divisible so ignoring"); - continue; - } - cageList[i] = -1; - boolean outcome = f(newResult, cageList, permute ? 0 : i + 1, depth + 1); - cageList[i] = e; - if (outcome) - return true; - - } - } - //System.out.println("Done analyzing " + result); - return false; - } - - //!!!not thread safe!!! - public boolean testSign(int[] cageList, int target, Sign operator) { - this.target = target; - this.operator = operator; - this.permute = (operator == Sign.MINUS || operator == Sign.DIVIDE); - - return f(0, cageList, 0, 0); - } - - public static void main(String[] args) { - System.out.println( new Permutations().testSign(new int[]{9, 1, 2, 3}, 8, Sign.MINUS)); - } -} \ No newline at end of file diff --git a/trivial/permutations.py b/trivial/permutations.py deleted file mode 100644 index ea52f87faf94fe3c32da991b046b1f6ad7171c65..0000000000000000000000000000000000000000 --- a/trivial/permutations.py +++ /dev/null @@ -1,41 +0,0 @@ -outSet = set() -runs = 0 - -def testAdd(cage : list, start: int, permute = False): - global runs - if (len(cage) == 0): - print() - return - for i, e in enumerate(cage): - result = start + e - runs+=1 - print(e, end=' ') - #outSet.add(result) - if permute: - newList = cage[:i] + cage[i + 1:] - else: - newList = cage[i + 1:] - - testAdd(newList, result) - -permute = True -operator = lambda x, y: x / y - -def f(result, cageList, startindex = 0): - print("Analyzing", result) - for i, e in enumerate(cageList): - if startindex == 0: - newResult = e - else: - newResult = operator(result, e) - - if permute: - newList = cageList[:i] + cageList[i + 1:] - else: - newList = cageList[i + 1:] - - f(newResult, newList, 1) - print("Done analyzing", result) - - -f(0, [6, 1, 12]) \ No newline at end of file