├── .DS_Store ├── Homework ├── .DS_Store ├── hw0 │ ├── .gitignore │ ├── README │ ├── Tester.java │ └── firstclass.java ├── hw1 │ ├── .gitignore │ ├── Arithmetic │ │ ├── Arithmetic.java │ │ ├── ArithmeticJUnitTest.java │ │ ├── ArithmeticTest.java │ │ └── Makefile │ ├── CompoundInterest │ │ ├── CompoundInterest.java │ │ ├── CompoundInterestTest.java │ │ └── Makefile │ ├── Makefile │ ├── MultiArr │ │ ├── Makefile │ │ ├── MultiArr.java │ │ └── MultiArrTest.java │ └── Signpost │ │ ├── Makefile │ │ ├── Place.java │ │ ├── PlaceTests.java │ │ └── Utils.java ├── hw2 │ ├── .gitignore │ ├── arrays │ │ ├── Arrays.java │ │ ├── ArraysTest.java │ │ ├── IntList.java │ │ ├── IntListList.java │ │ ├── Makefile │ │ ├── Utils.java │ │ └── style61b-suppress.xml │ ├── image │ │ ├── 4x6.png │ │ ├── 4x6.png.energyMatrix.correct │ │ ├── 4x6.png.horizontalAccumulation.correct │ │ ├── 4x6.png.horizontalSeam.correct │ │ ├── 4x6.png.verticalAccumulation.correct │ │ ├── 4x6.png.verticalSeam.correct │ │ ├── HJoceanSmall.jpg │ │ ├── In.java │ │ ├── Makefile │ │ ├── MatrixUtils.java │ │ ├── MatrixUtilsTest.java │ │ ├── Out.java │ │ ├── Picture.java │ │ ├── Rescaler.java │ │ └── Utils.java │ └── lists │ │ ├── IntList.java │ │ ├── IntListList.java │ │ ├── Lists.java │ │ ├── ListsTest.java │ │ ├── Makefile │ │ ├── Utils.java │ │ ├── out │ │ └── production │ │ │ └── lists │ │ │ ├── Makefile │ │ │ └── style61b-suppress.xml │ │ └── style61b-suppress.xml ├── hw3 │ ├── .gitignore │ ├── TrReader │ │ ├── Makefile │ │ ├── TrReader.java │ │ ├── TrReaderTest.java │ │ ├── TrReaderWithExamplesEmbedded.java.txt │ │ └── Translate.java │ └── WeirdList │ │ ├── ControlList.java │ │ ├── IntUnaryFunction.java │ │ ├── Makefile │ │ ├── WeirdList.java │ │ ├── WeirdListClient.java │ │ ├── WeirdListClientTest.java │ │ ├── WeirdListTest.java │ │ ├── addFunction.java │ │ └── sumFunction.java ├── hw4 │ ├── .gitignore │ ├── Makefile │ ├── Matching.java │ ├── P2Pattern.java │ ├── ReadInts.java │ ├── TestP2Pattern.java │ ├── TestReadInts.java │ └── Utils.java ├── hw5 │ ├── .gitignore │ ├── BitExercise.java │ ├── BitExerciseTest.java │ ├── HW5Test.java │ ├── Makefile │ ├── Nybbles.java │ └── NybblesTest.java ├── hw6 │ ├── .gitignore │ ├── BSTStringSet.java │ ├── BSTStringSetRangeTest.java │ ├── BSTStringSetTest.java │ ├── ECHashStringSet.java │ ├── ECHashStringSetTest.java │ ├── HW6Test.java │ ├── InsertInOrderSpeedTest.java │ ├── InsertRandomSpeedTest.java │ ├── Makefile │ ├── SortedStringSet.java │ ├── Stopwatch.java │ ├── StringSet.java │ ├── StringUtils.java │ └── hw6timing.txt ├── hw7 │ ├── .gitignore │ ├── BenchmarkUtility.java │ ├── Intervals.java │ ├── Inversions.java │ ├── Makefile │ ├── MySortingAlgorithms.java │ ├── MySortingAlgorithmsTest.java │ ├── Quicksort.java │ ├── RunBenchmarks.java │ ├── SortInts.java │ ├── SortingAlgorithm.java │ ├── Stopwatch.java │ └── Sum.java ├── hw8 │ ├── .gitignore │ ├── BTree.java │ ├── Makefile │ └── RedBlackTree.java └── hw9 │ ├── .idea │ ├── libraries │ │ └── lib.xml │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml │ ├── Makefile │ ├── NFA.java │ ├── NFATests.java │ ├── hw9.iml │ ├── out │ └── production │ │ └── hw9 │ │ ├── .idea │ │ ├── libraries │ │ │ └── lib.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── vcs.xml │ │ └── workspace.xml │ │ ├── Makefile │ │ ├── NFA$State.class │ │ ├── NFA.class │ │ ├── NFATests$1.class │ │ ├── NFATests.class │ │ ├── hw9.iml │ │ └── testing │ │ ├── hard │ │ ├── berkeleyWebsites.in │ │ ├── commaSeparated.in │ │ ├── emailaddress.in │ │ └── phonenumber.in │ │ ├── medium │ │ ├── aOrbStar.in │ │ ├── abOrcd.in │ │ ├── abPlus.in │ │ ├── abStar.in │ │ ├── astarA.in │ │ ├── highlyNested.in │ │ └── lotsOfPlus.in │ │ └── simple │ │ ├── a.in │ │ ├── aOrb.in │ │ ├── aOrbParens.in │ │ ├── ab.in │ │ ├── aplus.in │ │ └── astar.in │ └── testing │ ├── hard │ ├── berkeleyWebsites.in │ ├── commaSeparated.in │ ├── emailaddress.in │ └── phonenumber.in │ ├── medium │ ├── aOrbStar.in │ ├── abOrcd.in │ ├── abPlus.in │ ├── abStar.in │ ├── astarA.in │ ├── highlyNested.in │ └── lotsOfPlus.in │ └── simple │ ├── a.in │ ├── aOrb.in │ ├── aOrbParens.in │ ├── ab.in │ ├── aplus.in │ └── astar.in ├── Labs ├── .DS_Store ├── lab1 │ ├── .gitignore │ ├── AGTestYear.java │ └── Year.java ├── lab12 │ ├── .gitignore │ ├── .idea │ │ ├── libraries │ │ │ └── ucb.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── vcs.xml │ │ └── workspace.xml │ ├── Makefile │ ├── capers │ │ ├── Dog.java │ │ ├── Main.java │ │ ├── Makefile │ │ └── Utils.java │ ├── lab12.iml │ └── partner.txt ├── lab13 │ └── partner.txt ├── lab14 │ ├── .gitignore │ ├── MST.java │ ├── MSTTest.java │ ├── UnionFind.java │ ├── UnionFindTest.java │ ├── Utils.java │ └── partner.txt ├── lab2 │ ├── .gitignore │ ├── IntList.java │ ├── IntListTest.java │ └── partner.txt ├── lab3 │ ├── .gitignore │ ├── BuggyIntDList.java │ ├── BuggyIntDListTest.java │ ├── IntDList.java │ ├── IntDListTest.java │ ├── checkoff.txt │ └── partner.txt ├── lab5 │ ├── .idea │ │ ├── libraries │ │ │ └── gjdb.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── vcs.xml │ │ └── workspace.xml │ ├── ColumnMatchFilter.java │ ├── EqualityFilter.java │ ├── GreaterThanFilter.java │ ├── IdentityFilter.java │ ├── SubstringFilter.java │ ├── Table.java │ ├── TableFilter.java │ ├── TestTable.java │ ├── lab5.iml │ ├── out │ │ └── production │ │ │ └── lab5 │ │ │ ├── .idea │ │ │ ├── libraries │ │ │ │ └── gjdb.xml │ │ │ ├── misc.xml │ │ │ ├── modules.xml │ │ │ ├── vcs.xml │ │ │ └── workspace.xml │ │ │ ├── ColumnMatchFilter.class │ │ │ ├── EqualityFilter.class │ │ │ ├── GreaterThanFilter.class │ │ │ ├── IdentityFilter.class │ │ │ ├── SubstringFilter.class │ │ │ ├── Table$JoinIterator.class │ │ │ ├── Table$TableException.class │ │ │ ├── Table$TableRow.class │ │ │ ├── Table.class │ │ │ ├── TableFilter.class │ │ │ ├── TestTable.class │ │ │ ├── lab5.iml │ │ │ ├── partner.txt │ │ │ └── sample_db │ │ │ ├── bad_rows.db │ │ │ ├── joined.db │ │ │ ├── missing_vals.db │ │ │ ├── ta_color.db │ │ │ ├── ta_data_struct.db │ │ │ └── white_space.db │ ├── partner.txt │ └── sample_db │ │ ├── bad_rows.db │ │ ├── joined.db │ │ ├── missing_vals.db │ │ ├── ta_color.db │ │ ├── ta_data_struct.db │ │ └── white_space.db ├── lab6 │ ├── .gitignore │ ├── enigma │ │ ├── Alphabet.java │ │ ├── EnigmaException.java │ │ ├── Permutation.java │ │ ├── PermutationTest.java │ │ └── TestUtils.java │ ├── partner.txt │ └── testing │ │ └── correct │ │ ├── default.conf │ │ ├── trivial.in │ │ ├── trivial.out │ │ ├── trivial1.in │ │ └── trivial1.out ├── lab8 │ ├── .gitignore │ ├── amortized_timing.txt │ ├── map │ │ ├── LinkedListMap.java │ │ ├── MapTest.java │ │ ├── SimpleMap.java │ │ └── TreeMap.java │ ├── partner.txt │ ├── sort_timing.txt │ └── timing │ │ ├── AmortizationTiming.java │ │ ├── GraphUtil.java │ │ ├── GrowList.java │ │ ├── MySortTester.java │ │ ├── SortTiming.java │ │ ├── Sorter.java │ │ └── Timer.java └── lab9 │ ├── .gitignore │ ├── ArrayHeap.java │ ├── ArrayHeapTest.java │ └── partner.txt ├── Projects ├── .DS_Store ├── proj0 │ ├── .gitignore │ ├── Makefile │ ├── README │ ├── signpost │ │ ├── About.html │ │ ├── BoardWidget.java │ │ ├── CommandSource.java │ │ ├── Controller.java │ │ ├── GUI.java │ │ ├── GUISource.java │ │ ├── Help.html │ │ ├── Main.java │ │ ├── Makefile │ │ ├── Model.java │ │ ├── ModelTests.java │ │ ├── Place.java │ │ ├── PlaceTests.java │ │ ├── PuzzleGenerator.java │ │ ├── PuzzleGeneratorTests.java │ │ ├── PuzzleSource.java │ │ ├── TestSource.java │ │ ├── UnitTests.java │ │ ├── Utils.java │ │ └── View.java │ └── testing │ │ ├── Makefile │ │ ├── test00.in │ │ ├── test00.std │ │ ├── test01.in │ │ ├── test01.std │ │ ├── test02.in │ │ ├── test02.std │ │ ├── test03.in │ │ ├── test03.std │ │ ├── test05.in │ │ ├── test05.std │ │ ├── test06.in │ │ ├── test06.std │ │ ├── test07.in │ │ ├── test07.std │ │ ├── test08.in │ │ ├── test08.std │ │ ├── test09.in │ │ ├── test09.std │ │ ├── tester.py │ │ └── testing.py ├── proj1 │ ├── .gitignore │ ├── Makefile │ ├── enigma │ │ ├── Alphabet.java │ │ ├── EnigmaException.java │ │ ├── FixedRotor.java │ │ ├── Machine.java │ │ ├── Main.java │ │ ├── Makefile │ │ ├── MovingRotor.java │ │ ├── MovingRotorTest.java │ │ ├── Permutation.java │ │ ├── PermutationTest.java │ │ ├── Reflector.java │ │ ├── Rotor.java │ │ ├── TestUtils.java │ │ └── UnitTest.java │ └── testing │ │ ├── Makefile │ │ ├── correct │ │ ├── carroll1.in │ │ ├── carroll1.out │ │ ├── carroll2.in │ │ ├── carroll2.out │ │ ├── carroll3.conf │ │ ├── carroll3.in │ │ ├── carroll3.out │ │ ├── carroll4.conf │ │ ├── carroll4.in │ │ ├── carroll4.out │ │ ├── default.conf │ │ ├── format3.in │ │ ├── format3.out │ │ ├── newchars1.conf │ │ ├── newchars1.in │ │ ├── newchars1.out │ │ ├── permuted1.conf │ │ ├── permuted1.in │ │ ├── permuted1.out │ │ ├── reduced1.conf │ │ ├── reduced1.in │ │ ├── reduced1.out │ │ ├── reduced2.conf │ │ ├── reduced2.in │ │ ├── reduced2.out │ │ ├── riptide.in │ │ ├── riptide.out │ │ ├── trivial.in │ │ ├── trivial.out │ │ ├── trivial1.in │ │ └── trivial1.out │ │ ├── error │ │ ├── default.conf │ │ └── trivialerr.in │ │ ├── test-correct │ │ └── test-error ├── proj2 │ ├── .gitignore │ ├── Makefile │ ├── ReadMe.txt │ ├── loa │ │ ├── About.html │ │ ├── Board.java │ │ ├── BoardTest.java │ │ ├── BoardWidget.java │ │ ├── GUI.java │ │ ├── GUIPlayer.java │ │ ├── Game.java │ │ ├── Help.html │ │ ├── HelpText.txt │ │ ├── HumanPlayer.java │ │ ├── MachinePlayer.java │ │ ├── Main.java │ │ ├── Makefile │ │ ├── Move.java │ │ ├── NullView.java │ │ ├── Piece.java │ │ ├── Player.java │ │ ├── Reporter.java │ │ ├── Square.java │ │ ├── TextReporter.java │ │ ├── UnitTests.java │ │ ├── Usage.txt │ │ ├── Utils.java │ │ └── View.java │ └── testing │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── ai-v-staff-1.in │ │ ├── ai-v-staff-1.std │ │ ├── ai-v-staff-2.in │ │ ├── ai-v-staff-2.std │ │ ├── ai2-1.in │ │ ├── ai2-1.std │ │ ├── init-1.in │ │ ├── init-1.std │ │ ├── simplemoves-1.in │ │ ├── simplemoves-1.std │ │ ├── test-loa │ │ ├── tester.py │ │ └── testing.py └── proj3 │ ├── .gitignore │ ├── Makefile │ ├── gitlet │ ├── Driver.java │ ├── DumpObj.java │ ├── Dumpable.java │ ├── GitletException.java │ ├── Main.java │ ├── Makefile │ ├── UnitTest.java │ ├── Utils.java │ └── gitlet-design.md │ └── testing │ ├── Makefile │ ├── samples │ ├── test01-init.in │ ├── test02-basic-checkout.in │ ├── test03-basic-log.in │ └── test04-prev-checkout.in │ ├── src │ ├── notwug.txt │ └── wug.txt │ └── tester.py └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/.DS_Store -------------------------------------------------------------------------------- /Homework/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Homework/.DS_Store -------------------------------------------------------------------------------- /Homework/hw0/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.py 3 | *.jar 4 | *~ 5 | -------------------------------------------------------------------------------- /Homework/hw0/README: -------------------------------------------------------------------------------- 1 | The only skeleton file in this assignment is Tester.java, which you 2 | can use to test your solution. Create whatever files you need to hold your 3 | solution and use 'git add` to tell git about them before committing and 4 | submitting. 5 | -------------------------------------------------------------------------------- /Homework/hw0/Tester.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | 4 | import ucb.junit.textui; 5 | 6 | /** Tests for hw0. 7 | * @author YOUR NAMES HERE 8 | */ 9 | public class Tester { 10 | 11 | /* Feel free to add your own tests. For now, you can just follow 12 | * the pattern you see here. We'll look into the details of JUnit 13 | * testing later. 14 | * 15 | * To actually run the tests, just use 16 | * java Tester 17 | * (after first compiling your files). 18 | * 19 | * DON'T put your HW0 solutions here! Put them in a separate 20 | * class and figure out how to call them from here. You'll have 21 | * to modify the calls to max, threeSum, and threeSumDistinct to 22 | * get them to work, but it's all good practice! */ 23 | 24 | @Test 25 | public void maxTest() { 26 | // Change call to max to make this call yours. 27 | assertEquals(14, firstclass.max(new int[] { 0, -5, 2, 14, 10 })); 28 | // REPLACE THIS WITH MORE TESTS. 29 | } 30 | 31 | @Test 32 | public void threeSumTest() { 33 | // Change call to threeSum to make this call yours. 34 | assertTrue(firstclass.threeSum(new int[] { -6, 3, 10, 200 })); 35 | // REPLACE THIS WITH MORE TESTS. 36 | } 37 | 38 | @Test 39 | public void threeSumDistinctTest() { 40 | // Change call to threeSumDistinct to make this call yours. 41 | assertFalse(firstclass.threeSumDistinct(new int[] { -6, 3, 10, 200 })); 42 | // REPLACE THIS WITH MORE TESTS. 43 | } 44 | 45 | public static void main(String[] unused) { 46 | textui.runClasses(Tester.class); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Homework/hw0/firstclass.java: -------------------------------------------------------------------------------- 1 | public class firstclass{ 2 | static int max(int[] a){ 3 | int final_max = 0; 4 | for (int i = 0; i < a.length; i++){ 5 | if (a[i] > final_max){ 6 | final_max = a[i]; 7 | } 8 | } 9 | return final_max; 10 | } 11 | 12 | static boolean threeSum(int[] a){ 13 | for (int i = 0; i < a.length; i++){ 14 | for (int j = 0; j < a.length; j++){ 15 | for (int k = 0; k < a.length; k++){ 16 | if ((a[i] + a[j] + a[k]) == 0){ 17 | return true; 18 | } 19 | } 20 | } 21 | } 22 | return false; 23 | } 24 | 25 | static boolean threeSumDistinct(int[] a){ 26 | for (int i = 0; i < a.length; i++){ 27 | for (int j = i + 1; j < a.length; j++){ 28 | for (int k = j + 1; k < a.length; k++){ 29 | if ((a[i] + a[j] + a[k]) == 0){ 30 | return true; 31 | } 32 | } 33 | } 34 | } 35 | return false; 36 | } 37 | public static void main(String[] args){ 38 | int[] tester = new int[]{8, 2, -1, -15}; 39 | System.out.println(max(tester)); 40 | System.out.println(threeSum(tester)); 41 | System.out.println(threeSumDistinct(tester)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Homework/hw1/Arithmetic/Arithmetic.java: -------------------------------------------------------------------------------- 1 | /** A couple of arithmetic functions. 2 | * @author 3 | */ 4 | public class Arithmetic { 5 | 6 | /** Returns the product of A and B. */ 7 | public static double product(double a, double b) { 8 | return a * b; 9 | } 10 | 11 | /** Returns the sum of A and B. */ 12 | public static double sum(double a, double b) { 13 | return a + b; // WRONG 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Homework/hw1/Arithmetic/ArithmeticJUnitTest.java: -------------------------------------------------------------------------------- 1 | import static org.junit.Assert.*; 2 | import org.junit.Test; 3 | 4 | public class ArithmeticJUnitTest { 5 | 6 | /** Tolerance for comparison of doubles. */ 7 | static final double DELTA = 1e-15; 8 | 9 | @Test 10 | public void testProduct() { 11 | /* assertEquals for comparison of doubles takes three arguments: 12 | * assertEquals(expected, actual, DELTA). 13 | * + if Math.abs(expected - actual) < DELTA, then the test succeeds. 14 | * + Otherwise, the test fails. 15 | * 16 | * See http://junit.sourceforge.net/javadoc/org/junit/ \ 17 | * Assert.html#assertEquals(double, double, double) 18 | * for more. */ 19 | 20 | assertEquals(30, Arithmetic.product(5, 6), DELTA); 21 | assertEquals(-30, Arithmetic.product(5, -6), DELTA); 22 | assertEquals(0, Arithmetic.product(0, -6), DELTA); 23 | } 24 | 25 | @Test 26 | public void testSum() { 27 | assertEquals(11, Arithmetic.sum(5, 6), DELTA); 28 | assertEquals(-1, Arithmetic.sum(5, -6), DELTA); 29 | assertEquals(-6, Arithmetic.sum(0, -6), DELTA); 30 | assertEquals(0, Arithmetic.sum(6, -6), DELTA); 31 | } 32 | 33 | /* Run the unit tests in this file. */ 34 | public static void main(String... args) { 35 | System.exit(ucb.junit.textui.runClasses(ArithmeticJUnitTest.class)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Homework/hw1/Arithmetic/ArithmeticTest.java: -------------------------------------------------------------------------------- 1 | public class ArithmeticTest { 2 | 3 | private static final double DELTA = 1e-15; 4 | 5 | /** Reports whether test result ISOK is true for test whose name 6 | * is NAME on standard output. */ 7 | private static void report(String name, boolean isOK) { 8 | if (isOK) { 9 | System.out.printf("%s OK.%n", name); 10 | } else { 11 | System.out.printf("%s FAILS.%n", name); 12 | } 13 | } 14 | 15 | /** Returns true iff X and Y are within DELTA of each other. */ 16 | private static boolean approxEqual(double x, double y) { 17 | return Math.abs(x - y) < DELTA; 18 | } 19 | 20 | /** Check that CORRECT and EXPECTED are approximately equal, 21 | * incrementing error count if not. */ 22 | private static void check(double correct, double expected) { 23 | if (!approxEqual(correct, expected)) { 24 | errorCount++; 25 | } 26 | } 27 | 28 | /** Performs a few arbitrary tests to see if the product 29 | * method is correct. */ 30 | public static boolean testProduct() { 31 | int startingErrors = errorCount; 32 | check(30, Arithmetic.product(5, 6)); 33 | check(-30, Arithmetic.product(5, -6)); 34 | check(0, Arithmetic.product(0, -6)); 35 | return startingErrors == errorCount; 36 | } 37 | 38 | /* Performs a few arbitrary tests to see if the sum method is correct. */ 39 | public static boolean testSum() { 40 | int startingErrors = errorCount; 41 | check(11, Arithmetic.sum(5, 6)); 42 | check(-1, Arithmetic.sum(5, -6)); 43 | check(-6, Arithmetic.sum(0, -6)); 44 | check(0, Arithmetic.sum(6, -6)); 45 | return startingErrors == errorCount; 46 | } 47 | 48 | /** Run all tests. */ 49 | public static void main(String[] args) { 50 | report("product", testProduct()); 51 | report("sum", testSum()); 52 | } 53 | 54 | /** Cumulative test errors. */ 55 | private static int errorCount; 56 | } 57 | -------------------------------------------------------------------------------- /Homework/hw1/Arithmetic/Makefile: -------------------------------------------------------------------------------- 1 | # make # Defaults to the first target: default 2 | # make default # Same as gmake compile. 3 | # make compile # Compiles Java code in this directory. 4 | # make adhoc-check # Compile if needed and test using ArithmeticTest. 5 | # make check # Compile if needed and test using ArithmeticJUnitTest. 6 | # We give the check label to this test instead of the 7 | # other ad-hoc because it is better. 8 | 9 | # make clean # Remove extraneous or rebuildable files 10 | 11 | STYLEPROG = style61b 12 | 13 | # Define $(SRCS) to be a list of Java files. 14 | SRCS = Arithmetic.java ArithmeticTest.java ArithmeticJUnitTest.java 15 | 16 | # The targets following .PHONY aren't actually files; they serve as commands. 17 | .PHONY: compile default check clean style 18 | 19 | # By default, compile all sources 20 | default: compile 21 | 22 | # To compile all source files, compile all java source files. 23 | compile: $(SRCS) 24 | javac -g $(SRCS) 25 | 26 | # Test the compiled program, after first making sure it is up-to-date. 27 | # This type of testing is relatively lame. 28 | adhoc-check: compile 29 | java ArithmeticTest 30 | 31 | # Check style of program 32 | style: 33 | $(STYLEPROG) $(SRCS) 34 | 35 | # Test the compiled program, after first making sure it is up-to-date. 36 | check: compile 37 | java ArithmeticJUnitTest 38 | 39 | # Remove extraneous or reconstructable files. 40 | clean: 41 | $(RM) *.class *~ 42 | -------------------------------------------------------------------------------- /Homework/hw1/CompoundInterest/CompoundInterestTest.java: -------------------------------------------------------------------------------- 1 | import static org.junit.Assert.*; 2 | import org.junit.Test; 3 | 4 | public class CompoundInterestTest { 5 | 6 | @Test 7 | public void testNumYears() { 8 | /** Sample assert statement for comparing integers. 9 | 10 | assertEquals(0, 0); */ 11 | assertEquals(CompoundInterest.numYears(2021),1); 12 | assertEquals(CompoundInterest.numYears(2023),3); 13 | } 14 | 15 | @Test 16 | public void testFutureValue() { 17 | double tolerance = 0.01; 18 | assertEquals(CompoundInterest.futureValue(10.0,12.0,2022),12.544, tolerance); 19 | assertEquals(CompoundInterest.futureValue(1000000, 0, 2060),1000000, tolerance); 20 | } 21 | 22 | @Test 23 | public void testFutureValueReal() { 24 | double tolerance = 0.01; 25 | assertEquals(CompoundInterest.futureValueReal(10, 12, 2022, 3),11.8026496, tolerance); 26 | assertEquals(CompoundInterest.futureValueReal(1000000, 0, 2060, 3),295712.29, tolerance); 27 | } 28 | 29 | @Test 30 | public void testTotalSavings() { 31 | double tolerance = 0.01; 32 | assertEquals(CompoundInterest.totalSavings(5000, 2022, 10), 16550, tolerance); 33 | } 34 | 35 | @Test 36 | public void testTotalSavingsReal() { 37 | double tolerance = 0.2; 38 | assertEquals(15572, CompoundInterest.totalSavingsReal(5000, 2022, 10, 3), tolerance); 39 | } 40 | 41 | 42 | /* Run the unit tests in this file. */ 43 | public static void main(String... args) { 44 | System.exit(ucb.junit.textui.runClasses(CompoundInterestTest.class)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Homework/hw1/CompoundInterest/Makefile: -------------------------------------------------------------------------------- 1 | # make # Defaults to the first target: default 2 | # make default # Same as make compile. 3 | # make compile # Compiles Java code in this directory. 4 | # make style # Runs style checks (only on instructional machines) 5 | # make check # Compile if needed and test using HW1Test. 6 | # make clean # Remove extraneous or rebuildable files 7 | 8 | PROGSTYLE = style61b 9 | 10 | # Define $(SRCS) to be a list of Java files. 11 | SRCS = CompoundInterest.java CompoundInterestTest.java 12 | 13 | # The targets following .PHONY aren't actually files; they serve as commands. 14 | .PHONY: compile default check clean style 15 | 16 | # By default, compile all sources 17 | default: compile 18 | 19 | # Compile all source files. 20 | compile: 21 | javac -g $(SRCS) 22 | 23 | # Run our style checks. 24 | style: 25 | $(PROGSTYLE) $(SRCS) 26 | 27 | # Test the compiled program, after first making sure it is up-to-date. 28 | check: compile 29 | java CompoundInterestTest 30 | 31 | # Remove extraneous or reconstructable files. 32 | clean: 33 | rm -f *.class *~ 34 | -------------------------------------------------------------------------------- /Homework/hw1/Makefile: -------------------------------------------------------------------------------- 1 | 2 | .PHONY: default check compile clean style 3 | 4 | default: compile 5 | 6 | compile: 7 | $(MAKE) -C Arithmetic 8 | $(MAKE) -C CompoundInterest 9 | $(MAKE) -C MultiArr 10 | $(MAKE) -C Signpost 11 | 12 | check: 13 | $(MAKE) -C Arithmetic check 14 | $(MAKE) -C CompoundInterest check 15 | $(MAKE) -C MultiArr check 16 | $(MAKE) -C Signpost check 17 | 18 | style: 19 | $(MAKE) -C Arithmetic style 20 | $(MAKE) -C CompoundInterest style 21 | $(MAKE) -C MultiArr style 22 | $(MAKE) -C Signpost style 23 | 24 | clean: 25 | $(MAKE) -C Arithmetic clean 26 | $(MAKE) -C CompoundInterest clean 27 | $(MAKE) -C MultiArr clean 28 | $(MAKE) -C Signpost clean 29 | 30 | -------------------------------------------------------------------------------- /Homework/hw1/MultiArr/Makefile: -------------------------------------------------------------------------------- 1 | # make # Defaults to the first target: default 2 | # make default # Same as gmake compile. 3 | # make compile # Compiles Java code in this directory. 4 | # make check # Compile if needed and test using ArithmeticJUnitTest. 5 | # We give the check label to this test instead of the 6 | # other ad-hoc because it is better. 7 | 8 | # make clean # Remove extraneous or rebuildable files 9 | 10 | STYLEPROG = style61b 11 | 12 | # Define $(SRCS) to be a list of Java files. 13 | SRCS = MultiArr.java MultiArrTest.java 14 | 15 | # The targets following .PHONY aren't actually files; they serve as commands. 16 | .PHONY: compile default check clean style 17 | 18 | # By default, compile all sources 19 | default: compile 20 | 21 | # To compile all source files, compile all java source files. 22 | compile: $(SRCS) 23 | javac -g $(SRCS) 24 | 25 | # Check style of program 26 | style: 27 | $(STYLEPROG) $(SRCS) 28 | 29 | # Test the compiled program, after first making sure it is up-to-date. 30 | check: compile 31 | java MultiArrTest 32 | 33 | # Remove extraneous or reconstructable files. 34 | clean: 35 | $(RM) *.class *~ 36 | -------------------------------------------------------------------------------- /Homework/hw1/MultiArr/MultiArr.java: -------------------------------------------------------------------------------- 1 | /** Multidimensional array 2 | * @author Zoe Plaxco 3 | */ 4 | 5 | public class MultiArr { 6 | 7 | /** 8 | {{“hello”,"you",”world”} ,{“how”,”are”,”you”}} prints: 9 | Rows: 2 10 | Columns: 3 11 | 12 | {{1,3,4},{1},{5,6,7,8},{7,9}} prints: 13 | Rows: 4 14 | Columns: 4 15 | */ 16 | public static void printRowAndCol(int[][] arr) { 17 | //TODO: Your code here! 18 | for (int row = 0; row < arr.length; row++){ 19 | for(int col = 0; col < arr[row].length; col++){ 20 | System.out.println(arr[row][col]); 21 | } 22 | } 23 | } 24 | 25 | /** 26 | @param arr: 2d array 27 | @return maximal value present anywhere in the 2d array 28 | */ 29 | public static int maxValue(int[][] arr) { 30 | int max = 0; 31 | //TODO: Your code here! 32 | for (int row = 0; row < arr.length; row++){ 33 | for (int col = 0; col < arr[row].length; col++){ 34 | //arr[0].length may not exist if length = 0 35 | if (arr[row][col] > max){ 36 | max = arr[row][col]; 37 | } 38 | } 39 | } 40 | return max; 41 | } 42 | 43 | /**Return an array where each element is the sum of the 44 | corresponding row of the 2d array*/ 45 | public static int[] allRowSums(int[][] arr) { 46 | //TODO: Your code here!! 47 | int[] result; 48 | result = new int[arr.length]; 49 | for (int row = 0; row < arr.length; row++){ 50 | for (int col = 0; col < arr[row].length; col++){ 51 | result[row] += arr[row][col]; 52 | } 53 | } 54 | return result; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Homework/hw1/MultiArr/MultiArrTest.java: -------------------------------------------------------------------------------- 1 | import static org.junit.Assert.*; 2 | import org.junit.Test; 3 | 4 | public class MultiArrTest { 5 | int[][] tester = { {1, 1, 14, 1}, 6 | {4, 4, 4 , 4}, 7 | {2, 2, 2 , 2} }; 8 | int[] tester2 = {17, 16, 8}; 9 | 10 | @Test 11 | public void testMaxValue() { 12 | //TODO: Your code here 13 | assertEquals(14, MultiArr.maxValue(tester)); 14 | } 15 | 16 | @Test 17 | public void testAllRowSums(){ 18 | //TODO: Your code here! 19 | assertArrayEquals(tester2, MultiArr.allRowSums(tester)); 20 | } 21 | 22 | 23 | /* Run the unit tests in this file. */ 24 | public static void main(String... args) { 25 | System.exit(ucb.junit.textui.runClasses(MultiArrTest.class)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Homework/hw1/Signpost/Makefile: -------------------------------------------------------------------------------- 1 | # make # Defaults to the first target: default 2 | # make default # Same as gmake compile. 3 | # make compile # Compiles Java code in this directory. 4 | # make check # Compile if needed and test using ArithmeticJUnitTest. 5 | # We give the check label to this test instead of the 6 | # other ad-hoc because it is better. 7 | 8 | # make clean # Remove extraneous or rebuildable files 9 | 10 | STYLEPROG = style61b 11 | 12 | # Define $(SRCS) to be a list of Java files. 13 | SRCS = Place.java PlaceTests.java Utils.java 14 | 15 | # The targets following .PHONY aren't actually files; they serve as commands. 16 | .PHONY: compile default check clean style 17 | 18 | # By default, compile all sources 19 | default: compile 20 | 21 | # To compile all source files, compile all java source files. 22 | compile: $(SRCS) 23 | javac -g $(SRCS) 24 | 25 | # Check style of program 26 | style: 27 | $(STYLEPROG) $(SRCS) 28 | 29 | # Test the compiled program, after first making sure it is up-to-date. 30 | check: compile 31 | java PlaceTests 32 | 33 | # Remove extraneous or reconstructable files. 34 | clean: 35 | $(RM) *.class *~ 36 | -------------------------------------------------------------------------------- /Homework/hw1/Signpost/PlaceTests.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | 4 | import java.util.Arrays; 5 | 6 | /** Tests of the Place class. 7 | * @author Will Wang 8 | */ 9 | public class PlaceTests { 10 | 11 | private void checkSuccessors(Place[][] expected, Place.PlaceList[] actual) { 12 | for (int dir = 8; dir >= 0; dir -= 1) { 13 | Utils.assertSetEquals(Utils.msg("Mismatch sucessors at direction %d", dir), 14 | Arrays.asList(expected[dir]), actual[dir]); 15 | } 16 | } 17 | 18 | @Test 19 | public void successorCellsTest() { 20 | Place.PlaceList[][][] sucessors = Place.successorCells(WIDTH, HEIGHT); 21 | checkSuccessors(EXPECTED, sucessors[PL.x][PL.y]); 22 | } 23 | 24 | private static final int WIDTH = 4; 25 | private static final int HEIGHT = 4; 26 | 27 | private static final Place PL = Place.pl(1, 1); 28 | 29 | private static final Place[][] EXPECTED = { 30 | { Place.pl(0, 0), Place.pl(0, 1), Place.pl(0, 2), Place.pl(1, 2), 31 | Place.pl(1, 3), Place.pl(2, 2), Place.pl(3, 3), Place.pl(2, 1), 32 | Place.pl(3, 1), Place.pl(2, 0), Place.pl(1, 0)}, 33 | { Place.pl(2, 2), Place.pl(3, 3) }, 34 | { Place.pl(2, 1), Place.pl(3, 1) }, 35 | { Place.pl(2, 0) }, 36 | { Place.pl(1, 0) }, 37 | { Place.pl(0, 0) }, 38 | { Place.pl(0, 1) }, 39 | { Place.pl(0, 2) }, 40 | { Place.pl(1, 2), Place.pl(1, 3) }, 41 | }; 42 | 43 | /* Run the unit tests in this file. */ 44 | public static void main(String... args) { 45 | System.exit(ucb.junit.textui.runClasses(PlaceTests.class)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Homework/hw1/Signpost/Utils.java: -------------------------------------------------------------------------------- 1 | import static org.junit.Assert.*; 2 | import static java.lang.System.arraycopy; 3 | import java.util.Collection; 4 | import java.util.HashSet; 5 | 6 | /** Various utility methods. 7 | * @author P. N. Hilfinger 8 | */ 9 | class Utils { 10 | 11 | /** Returns String.format(FORMAT, ARGS...). */ 12 | static String msg(String format, Object... args) { 13 | return String.format(format, args); 14 | } 15 | 16 | /** Check that the set of T's in EXPECTED is the same as that in ACTUAL. 17 | * Use MSG as the error message if the check fails. */ 18 | static void assertSetEquals(String msg, 19 | Collection expected, 20 | Collection actual) { 21 | assertNotNull(msg, actual); 22 | assertEquals(msg, new HashSet(expected), new HashSet(actual)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Homework/hw2/arrays/ArraysTest.java: -------------------------------------------------------------------------------- 1 | package arrays; 2 | 3 | import org.junit.Test; 4 | import static org.junit.Assert.*; 5 | 6 | /** FIXME 7 | * @author FIXME 8 | */ 9 | 10 | public class ArraysTest { 11 | /** FIXME 12 | */ 13 | @Test 14 | public void catenateTests(){ 15 | int[] a = new int[]{1,2,3,4}; 16 | int[] b = new int[]{5,6,9,8}; 17 | int[] result = Arrays.catenate(a, b); 18 | int[] expected = new int[]{1,2,3,4,5,6,9,8}; 19 | assertArrayEquals(expected, result); 20 | 21 | int[] c = new int[]{1,3,5,7,89}; 22 | int[] d = new int[]{4,5,6,77,9}; 23 | int[] result2 = Arrays.catenate(c, d); 24 | int[] expected2 = new int[]{1,3,5,7,89,4,5,6,77,9}; 25 | assertArrayEquals(expected2, result2); 26 | } 27 | 28 | @Test 29 | public void removeTests(){ 30 | int[] a = new int[]{1,2,3,4}; 31 | int[] result = Arrays.remove(a, 1, 2); 32 | int[] expected = new int[]{1, 4}; 33 | assertArrayEquals(expected, result); 34 | 35 | int[] b = new int[]{5,6,9,8,34,23}; 36 | int[] result2 = Arrays.remove(b, 2, 3); 37 | int[] expected2 = new int[]{5, 6, 23}; 38 | } 39 | 40 | @Test 41 | public void naturalRunsTest(){ 42 | int[] a = new int[]{1, 3, 7, 5, 4, 6, 9, 10}; 43 | int[][] result = new int[][]{{1, 3, 7}, {5}, {4, 6, 9, 10}}; 44 | int[][] expected = Arrays.naturalRuns(a); 45 | assertArrayEquals(expected, result); 46 | } 47 | public static void main(String[] args) { 48 | System.exit(ucb.junit.textui.runClasses(ArraysTest.class)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Homework/hw2/arrays/Makefile: -------------------------------------------------------------------------------- 1 | STYLEPROG = style61b 2 | 3 | # All Java sources. If you add more files, be sure to add them here as 4 | # well. 5 | STUDENT = Arrays.java ArraysTest.java IntList.java IntListList.java 6 | 7 | PROVIDED = Utils.java 8 | 9 | ALL_SRCS = $(STUDENT) $(PROVIDED) 10 | 11 | # The $(NAME:.java=.class) notation substitutes .java for trailing .class 12 | # extensions. 13 | STUDENT_CLASSES = $(STUDENT:.java=.class) 14 | 15 | PROVIDED_CLASSES = $(PROVIDED:.java=.class) 16 | 17 | ALL_CLASSES = $(STUDENT_CLASSES) $(PROVIDED_CLASSES) 18 | 19 | # Flags to pass to Java compilations (include debugging info and report 20 | # "unsafe" operations. 21 | JFLAGS = -g 22 | 23 | .PHONY: default style clean 24 | 25 | # By default, recompile if any sources have changed since the last build. 26 | # This will fail to recompile properly if you compile, then delete 27 | # a .class file in the draw package, and then compile again. You 28 | # shouldn't do that, of course, but if it happens, just do a 'make clean' 29 | # first and then 'gmake' 30 | default: $(ALL_CLASSES) 31 | 32 | # Check style of source files with style61b. 33 | style: 34 | $(STYLEPROG) $(STUDENT) 35 | 36 | # Remove files that are unnecessary or that can be regenerated with make. 37 | clean: 38 | $(RM) *.class *~ 39 | 40 | check: ArraysTest.class 41 | cd ..; java -ea arrays.ArraysTest 42 | 43 | #what to do when the makefile requests all classes sbould be compiled 44 | #it makes this request as the default option (see above) 45 | $(ALL_CLASSES): $(ALL_SRCS) 46 | cd ..; javac $(JFLAGS) $(ALL_SRCS:%=arrays/%) 47 | -------------------------------------------------------------------------------- /Homework/hw2/arrays/style61b-suppress.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 10 | 12 | 14 | 15 | -------------------------------------------------------------------------------- /Homework/hw2/image/4x6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Homework/hw2/image/4x6.png -------------------------------------------------------------------------------- /Homework/hw2/image/4x6.png.energyMatrix.correct: -------------------------------------------------------------------------------- 1 | 1000000 1000000 1000000 1000000 2 | 1000000 75990 30003 1000000 3 | 1000000 30002 103046 1000000 4 | 1000000 29515 38273 1000000 5 | 1000000 73403 35399 1000000 6 | 1000000 1000000 1000000 1000000 7 | -------------------------------------------------------------------------------- /Homework/hw2/image/4x6.png.horizontalAccumulation.correct: -------------------------------------------------------------------------------- 1 | 1000000 2000000 2075990 2060005 2 | 1000000 1075990 1060005 2060005 3 | 1000000 1030002 1132561 2060005 4 | 1000000 1029515 1067788 2064914 5 | 1000000 1073403 1064914 2064914 6 | 1000000 2000000 2073403 2064914 7 | -------------------------------------------------------------------------------- /Homework/hw2/image/4x6.png.horizontalSeam.correct: -------------------------------------------------------------------------------- 1 | 1000000 2000000 2075990 [2060005] 2 | [1000000] 1075990 [1060005] 2060005 3 | 1000000 [1030002] 1132561 2060005 4 | 1000000 1029515 1067788 2064914 5 | 1000000 1073403 1064914 2064914 6 | 1000000 2000000 2073403 2064914 7 | -------------------------------------------------------------------------------- /Homework/hw2/image/4x6.png.verticalAccumulation.correct: -------------------------------------------------------------------------------- 1 | 1000000 1000000 1000000 1000000 2 | 2000000 1075990 1030003 2000000 3 | 2075990 1060005 1133049 2030003 4 | 2060005 1089520 1098278 2133049 5 | 2089520 1162923 1124919 2098278 6 | 2162923 2124919 2124919 2124919 7 | -------------------------------------------------------------------------------- /Homework/hw2/image/4x6.png.verticalSeam.correct: -------------------------------------------------------------------------------- 1 | 1000000 [1000000] 1000000 1000000 2 | 2000000 1075990 [1030003] 2000000 3 | 2075990 [1060005] 1133049 2030003 4 | 2060005 [1089520] 1098278 2133049 5 | 2089520 1162923 [1124919] 2098278 6 | 2162923 [2124919] 2124919 2124919 7 | -------------------------------------------------------------------------------- /Homework/hw2/image/HJoceanSmall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Homework/hw2/image/HJoceanSmall.jpg -------------------------------------------------------------------------------- /Homework/hw2/image/Makefile: -------------------------------------------------------------------------------- 1 | STYLEPROG = style61b 2 | 3 | # All Java sources. If you add more files, be sure to add them here as 4 | # well. 5 | STUDENT = MatrixUtils.java MatrixUtilsTest.java 6 | 7 | PROVIDED = Rescaler.java In.java Picture.java Utils.java Out.java 8 | 9 | ALL_SRCS = $(STUDENT) $(PROVIDED) 10 | 11 | # The $(NAME:.java=.class) notation substitutes .java for trailing .class 12 | # extensions. 13 | STUDENT_CLASSES = $(STUDENT:.java=.class) 14 | 15 | PROVIDED_CLASSES = $(PROVIDED:.java=.class) 16 | 17 | ALL_CLASSES = $(STUDENT_CLASSES) $(PROVIDED_CLASSES) 18 | 19 | # Flags to pass to Java compilations (include debugging info) and report 20 | # "unsafe" operations. 21 | JFLAGS = -g 22 | 23 | .PHONY: default style clean 24 | 25 | # By default, recompile if any sources have changed since the last build. 26 | # This will fail to recompile properly if you compile, then delete 27 | # a .class file in the draw package, and then compile again. You 28 | # shouldn't do that, of course, but if it happens, just do a 'make clean' 29 | # first and then 'gmake' 30 | default: $(ALL_CLASSES) 31 | 32 | # Check style of source files with style61b. 33 | style: 34 | $(STYLEPROG) $(STUDENT) 35 | 36 | # Remove files that are unnecessary or that can be regenerated with make. 37 | clean: 38 | $(RM) *.class *~ 39 | 40 | check: MatrixUtilsTest.class 41 | cd ..; java image.MatrixUtilsTest 42 | 43 | #what to do when the makefile requests all classes sbould be compiled 44 | #it makes this request as the default option (see above) 45 | $(ALL_CLASSES): $(ALL_SRCS) 46 | cd ..; javac $(JFLAGS) $(ALL_SRCS:%=image/%) 47 | -------------------------------------------------------------------------------- /Homework/hw2/image/MatrixUtilsTest.java: -------------------------------------------------------------------------------- 1 | package image; 2 | 3 | import org.junit.Test; 4 | import static org.junit.Assert.*; 5 | 6 | /** FIXME 7 | * @author FIXME 8 | */ 9 | 10 | public class MatrixUtilsTest { 11 | /** FIXME 12 | */ 13 | 14 | public static void main(String[] args) { 15 | System.exit(ucb.junit.textui.runClasses(MatrixUtilsTest.class)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Homework/hw2/lists/ListsTest.java: -------------------------------------------------------------------------------- 1 | package lists; 2 | 3 | import org.junit.Test; 4 | import static org.junit.Assert.*; 5 | 6 | 7 | /** FIXME 8 | * 9 | * @author FIXME 10 | */ 11 | 12 | public class ListsTest { 13 | /** FIXME 14 | */ 15 | 16 | @Test 17 | public void naturalRunsTest(){ 18 | IntList source = IntList.list(1, 3, 7, 5, 4, 6, 9, 10, 10, 11); 19 | IntListList result = Lists.naturalRuns(source); 20 | int[][] expectedArray = {{1,3,7}, {5}, {4,6,9,10}, {10,11}}; 21 | IntListList expected = IntListList.list(expectedArray); 22 | assertEquals(expected, result); 23 | 24 | } 25 | // It might initially seem daunting to try to set up 26 | // IntListList expected. 27 | // 28 | // There is an easy way to get the IntListList that you want in just 29 | // few lines of code! Make note of the IntListList.list method that 30 | // takes as input a 2D array. 31 | 32 | public static void main(String[] args) { 33 | System.exit(ucb.junit.textui.runClasses(ListsTest.class)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Homework/hw2/lists/Makefile: -------------------------------------------------------------------------------- 1 | 2 | STYLEPROG = style61b 3 | 4 | # All Java sources. If you add more files, be sure to add them here as 5 | # well. 6 | STUDENT = Lists.java ListsTest.java 7 | 8 | PROVIDED = IntList.java IntListList.java Utils.java 9 | 10 | ALL_SRCS = $(STUDENT) $(PROVIDED) 11 | 12 | # The $(NAME:.java=.class) notation substitutes .java for trailing .class 13 | # extensions. 14 | STUDENT_CLASSES = $(STUDENT:.java=.class) 15 | 16 | PROVIDED_CLASSES = $(PROVIDED:.java=.class) 17 | 18 | ALL_CLASSES = $(STUDENT_CLASSES) $(PROVIDED_CLASSES) 19 | 20 | # Flags to pass to Java compilations (include debugging info and report 21 | # "unsafe" operations. 22 | JFLAGS = -g 23 | 24 | .PHONY: default style clean 25 | 26 | # By default, recompile if any sources have changed since the last build. 27 | # This will fail to recompile properly if you compile, then delete 28 | # a .class file in the draw package, and then compile again. You 29 | # shouldn't do that, of course, but if it happens, just do a 'make clean' 30 | # first and then 'gmake' 31 | default: $(ALL_CLASSES) 32 | 33 | # Check style of source files with style61b. 34 | style: 35 | $(STYLEPROG) $(STUDENT) 36 | 37 | # Remove files that are unnecessary or that can be regenerated with make. 38 | clean: 39 | $(RM) *.class *~ 40 | 41 | check: ListsTest.class 42 | cd ..; java lists.ListsTest 43 | 44 | #what to do when the makefile requests all classes sbould be compiled 45 | #it makes this request as the default option (see above) 46 | $(ALL_CLASSES): $(ALL_SRCS) 47 | cd ..; javac $(JFLAGS) $(ALL_SRCS:%=lists/%) 48 | -------------------------------------------------------------------------------- /Homework/hw2/lists/out/production/lists/Makefile: -------------------------------------------------------------------------------- 1 | 2 | STYLEPROG = style61b 3 | 4 | # All Java sources. If you add more files, be sure to add them here as 5 | # well. 6 | STUDENT = Lists.java ListsTest.java 7 | 8 | PROVIDED = IntList.java IntListList.java Utils.java 9 | 10 | ALL_SRCS = $(STUDENT) $(PROVIDED) 11 | 12 | # The $(NAME:.java=.class) notation substitutes .java for trailing .class 13 | # extensions. 14 | STUDENT_CLASSES = $(STUDENT:.java=.class) 15 | 16 | PROVIDED_CLASSES = $(PROVIDED:.java=.class) 17 | 18 | ALL_CLASSES = $(STUDENT_CLASSES) $(PROVIDED_CLASSES) 19 | 20 | # Flags to pass to Java compilations (include debugging info and report 21 | # "unsafe" operations. 22 | JFLAGS = -g 23 | 24 | .PHONY: default style clean 25 | 26 | # By default, recompile if any sources have changed since the last build. 27 | # This will fail to recompile properly if you compile, then delete 28 | # a .class file in the draw package, and then compile again. You 29 | # shouldn't do that, of course, but if it happens, just do a 'make clean' 30 | # first and then 'gmake' 31 | default: $(ALL_CLASSES) 32 | 33 | # Check style of source files with style61b. 34 | style: 35 | $(STYLEPROG) $(STUDENT) 36 | 37 | # Remove files that are unnecessary or that can be regenerated with make. 38 | clean: 39 | $(RM) *.class *~ 40 | 41 | check: ListsTest.class 42 | cd ..; java lists.ListsTest 43 | 44 | #what to do when the makefile requests all classes sbould be compiled 45 | #it makes this request as the default option (see above) 46 | $(ALL_CLASSES): $(ALL_SRCS) 47 | cd ..; javac $(JFLAGS) $(ALL_SRCS:%=lists/%) 48 | -------------------------------------------------------------------------------- /Homework/hw2/lists/out/production/lists/style61b-suppress.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 10 | 12 | 14 | 15 | -------------------------------------------------------------------------------- /Homework/hw2/lists/style61b-suppress.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 10 | 12 | 14 | 15 | -------------------------------------------------------------------------------- /Homework/hw3/TrReader/Makefile: -------------------------------------------------------------------------------- 1 | 2 | STYLEPROG = style61b 3 | 4 | # All Java sources. 5 | SRCS = $(wildcard *.java) 6 | 7 | CLASSES = $(SRCS:.java=.class) 8 | 9 | JFLAGS = -g 10 | 11 | .PHONY: default style clean 12 | 13 | default: $(CLASSES) 14 | 15 | style: 16 | $(STYLEPROG) $(SRCS) 17 | 18 | clean: 19 | $(RM) *.class *~ sentinel 20 | 21 | check: default 22 | @echo Warning: ONLY sample tests defined. 23 | java TrReaderTest 24 | 25 | $(CLASSES): sentinel 26 | 27 | sentinel: $(SRCS) 28 | @echo javac $(JFLAGS) $(SRCS); \ 29 | javac $(JFLAGS) $(SRCS) || { \ 30 | echo "*** NOTE: If you received an error that 'TrReader is"; \ 31 | echo "*** not abstract and ...', DON'T make TrReader abstract."; \ 32 | echo "*** Look at the ... part instead."; \ 33 | false; } 34 | touch $@ 35 | 36 | -------------------------------------------------------------------------------- /Homework/hw3/TrReader/TrReaderWithExamplesEmbedded.java.txt: -------------------------------------------------------------------------------- 1 | import java.io.Reader; 2 | import java.io.IOException; 3 | 4 | /** Translating Reader: a stream that is a translation of an 5 | * existing reader. */ 6 | public class TrReader extends Reader { 7 | /** A new TrReader that produces the stream of characters produced 8 | * by STR, converting all characters that occur in FROM to the 9 | * corresponding characters in TO. That is, change occurrences of 10 | * FROM.charAt(0) to TO.charAt(0), etc., leaving other characters 11 | * unchanged. FROM and TO must have the same length. */ 12 | public TrReader(Reader str, String from, String to) { 13 | // FILL IN 14 | } 15 | 16 | /** Reads characters into a portion of an array */ 17 | public int read(char[] cbuf, int off, int len) { 18 | // Information goes from the reader supplied 19 | // gets translated, and stored in cbuf[off] through 20 | // cbuf[off + len] 21 | 22 | // say off were 2, and len were 10 23 | // e.g. c[2] = translated 0th character 24 | // c[3] = translated 1st character 25 | 26 | } 27 | from = 'cbF' 28 | to = 'CRS' 29 | cat (from the outside world) 30 | 31 | cbuf: ['F','H','I','J','O'] : Some stuff is here. you overwrite it, who cares about it. 32 | 33 | we call read with cbuf, off = 2, len = 2, someone types cat 34 | cbuf: ['F', 'H', 'C', 'a'] 35 | 36 | 37 | // FILL IN 38 | // NOTE: Until you fill in the right methods, the compiler will 39 | // reject this file, saying that you must declare TrReader 40 | // abstract. Don't do that; define the right methods instead! 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /Homework/hw3/TrReader/Translate.java: -------------------------------------------------------------------------------- 1 | import java.io.IOException; 2 | import java.io.StringReader; 3 | 4 | /** String translation. 5 | * @author Brian Faun 6 | */ 7 | public class Translate { 8 | /** This method should return the String S, but with all characters that 9 | * occur in FROM changed to the corresponding characters in TO. 10 | * FROM and TO must have the same length. 11 | * NOTE: You must use your TrReader to achieve this. */ 12 | static String translate(String S, String from, String to) { 13 | /* NOTE: The try {...} catch is a technicality to keep Java happy. */ 14 | char[] buffer = new char[S.length()]; 15 | try { 16 | StringReader sReader = new StringReader(S); 17 | TrReader translator = new TrReader(sReader, from, to); 18 | int c = translator.read(buffer, 0, S.length()); 19 | String str = new String(buffer); 20 | return str; 21 | } catch (IOException e) { 22 | return null; 23 | } 24 | } 25 | 26 | /** Ad-hoc Tests. 27 | * @param args arguments 28 | */ 29 | public static void main(String [] args) { 30 | System.out.println(translate("My Name Is Brian", "MNIB", "mnib")); 31 | System.out.println(translate("chipmunks", "chipmunk", "flamingo")); 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Homework/hw3/WeirdList/ControlList.java: -------------------------------------------------------------------------------- 1 | import sun.applet.resources.MsgAppletViewer_it; 2 | 3 | /** 4 | * Helper class for WeirdList. 5 | * @author Brian Faun 6 | */ 7 | public class ControlList extends WeirdList { 8 | 9 | /** Constructor. */ 10 | public ControlList() { 11 | super(0, null); 12 | } 13 | 14 | /** 15 | * Base case for recursion 16 | * @param w WeirdList 17 | * @return b boolean 18 | */ 19 | static boolean isEmpty(WeirdList w) { 20 | return w.equals(WeirdList.EMPTY); 21 | } 22 | 23 | /** Return 0. */ 24 | public int length() { 25 | return 0; 26 | } 27 | 28 | /** Print nothing. */ 29 | public String toString() { 30 | return ""; 31 | } 32 | 33 | /** 34 | * Return null WeirdList 35 | * @param func func 36 | * @return EMPTY 37 | */ 38 | public WeirdList map(IntUnaryFunction func) { 39 | return EMPTY; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Homework/hw3/WeirdList/IntUnaryFunction.java: -------------------------------------------------------------------------------- 1 | /* DO NOT CHANGE THIS FILE. */ 2 | 3 | 4 | /** An IntUnaryFunction represents a function from 5 | * integers to integers. 6 | * @author P. N. Hilfinger 7 | */ 8 | public interface IntUnaryFunction { 9 | /** Return the result of applying this function to X. */ 10 | int apply(int x); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Homework/hw3/WeirdList/Makefile: -------------------------------------------------------------------------------- 1 | 2 | STYLEPROG = style61b 3 | 4 | # All Java sources. 5 | SRCS = $(wildcard *.java) 6 | 7 | CLASSES = $(SRCS:.java=.class) 8 | 9 | JFLAGS = -g 10 | 11 | .PHONY: default style clean 12 | 13 | default: $(CLASSES) 14 | 15 | style: 16 | $(STYLEPROG) $(SRCS) 17 | 18 | clean: 19 | $(RM) *.class *~ sentinel 20 | 21 | check: default 22 | @echo Warning: ONLY sample tests defined. 23 | java WeirdListTest 24 | java WeirdListClientTest 25 | 26 | $(CLASSES): sentinel 27 | 28 | sentinel: $(SRCS) 29 | javac $(JFLAGS) $(SRCS) 30 | touch $@ 31 | -------------------------------------------------------------------------------- /Homework/hw3/WeirdList/WeirdListClient.java: -------------------------------------------------------------------------------- 1 | /** Functions to increment and sum the elements of a WeirdList. */ 2 | class WeirdListClient { 3 | 4 | /** Return the result of adding N to each element of L. */ 5 | static WeirdList add(WeirdList L, int n) { 6 | return L.map(new addFunction(n)); 7 | } 8 | 9 | /** Return the sum of all the elements in L. */ 10 | static int sum(WeirdList L) { 11 | sumFunction.total = 0; 12 | L.map(new sumFunction()); 13 | return sumFunction.total; 14 | } 15 | 16 | /* IMPORTANT: YOU ARE NOT ALLOWED TO USE RECURSION IN ADD AND SUM 17 | * 18 | * As with WeirdList, you'll need to add an additional class or 19 | * perhaps more for WeirdListClient to work. Again, you may put 20 | * those classes either inside WeirdListClient as private static 21 | * classes, or in their own separate files. 22 | 23 | * You are still forbidden to use any of the following: 24 | * if, switch, while, for, do, try, or the ?: operator. 25 | * 26 | * HINT: Try checking out the IntUnaryFunction interface. 27 | * Can we use it somehow? 28 | */ 29 | } 30 | -------------------------------------------------------------------------------- /Homework/hw3/WeirdList/WeirdListClientTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | 4 | import ucb.junit.textui; 5 | 6 | /** Cursory tests of WeirdListClient. 7 | * @author Josh Hug 8 | * @author P. N. Hilfinger 9 | */ 10 | public class WeirdListClientTest { 11 | @Test 12 | public void testSum() { 13 | WeirdList wl1 = new WeirdList(5, WeirdList.EMPTY); 14 | WeirdList wl2 = new WeirdList(6, wl1); 15 | WeirdList wl3 = new WeirdList(10, wl2); 16 | 17 | assertEquals(10 + 6 + 5, WeirdListClient.sum(wl3)); 18 | assertEquals(5, WeirdListClient.sum(wl1)); 19 | assertEquals(21, WeirdListClient.sum(wl3)); 20 | } 21 | 22 | @Test 23 | public void testAddSum() { 24 | WeirdList wl1 = new WeirdList(5, WeirdList.EMPTY); 25 | WeirdList wl2 = new WeirdList(6, wl1); 26 | 27 | WeirdList nwl = WeirdListClient.add(wl2, 4); 28 | assertEquals((6 + 4) + (5 + 4), WeirdListClient.sum(nwl)); 29 | } 30 | 31 | public static void main(String[] args) { 32 | System.exit(textui.runClasses(WeirdListClientTest.class)); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Homework/hw3/WeirdList/WeirdListTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | 4 | import ucb.junit.textui; 5 | 6 | /** Tests of WeirdList. 7 | * @author Josh Hug 8 | * @author P. N. Hilfinger 9 | */ 10 | public class WeirdListTest { 11 | @Test 12 | public void testList() { 13 | WeirdList wl1 = new WeirdList(5, WeirdList.EMPTY); 14 | WeirdList wl2 = new WeirdList(6, wl1); 15 | WeirdList wl3 = new WeirdList(10, wl2); 16 | assertEquals(3, wl3.length()); 17 | assertEquals(1, wl1.length()); 18 | 19 | assertEquals(" 10 6 5", wl3.toString()); 20 | } 21 | 22 | 23 | 24 | public static void main(String[] args) { 25 | System.exit(textui.runClasses(WeirdListTest.class)); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Homework/hw3/WeirdList/addFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Implements IntUnaryFunction Interface. 3 | * @author Brian Faun 4 | */ 5 | public class addFunction implements IntUnaryFunction { 6 | private int add; 7 | 8 | public addFunction(int n){ 9 | add = n; 10 | } 11 | 12 | public int apply(int x) { 13 | return add + x; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Homework/hw3/WeirdList/sumFunction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Implements IntUnaryFunction Interface. 3 | * @author Brian Faun 4 | */ 5 | public class sumFunction implements IntUnaryFunction{ 6 | static int total = 0; 7 | 8 | public int apply(int x) { 9 | return total += x; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Homework/hw4/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # All Java sources. If you add more files, be sure to add them here as 3 | # well. 4 | SRCS = Matching.java P2Pattern.java ReadInts.java TestP2Pattern.java TestReadInts.java Utils.java 5 | 6 | CLASSES = $(SRCS:.java=.class) 7 | 8 | JFLAGS = -g 9 | 10 | .PHONY: default style clean 11 | 12 | default: $(CLASSES) 13 | 14 | style: 15 | style61b $(SRCS) 16 | 17 | clean: 18 | $(RM) *.class *~ 19 | 20 | check: default 21 | java TestReadInts 22 | java TestP2Pattern 23 | 24 | $(CLASSES): $(SRCS) 25 | javac $(JFLAGS) $(SRCS) 26 | -------------------------------------------------------------------------------- /Homework/hw4/P2Pattern.java: -------------------------------------------------------------------------------- 1 | /** P2Pattern class 2 | * @author Josh Hug & Vivant Sakore 3 | */ 4 | 5 | public class P2Pattern { 6 | /* Pattern to match a valid date of the form MM/DD/YYYY. Eg: 9/22/2019 */ 7 | public static String P1 = "([0]?\\d|[1][0-2])/([0]?\\d|[1]\\d|[2]\\d|[3][0-1])/[1-9]\\d\\d\\d"; 8 | 9 | /** Pattern to match 61b notation for literal IntLists. */ 10 | public static String P2 = "\\(\\d+(\\, +\\d+)+\\)"; 11 | 12 | /* Pattern to match a valid domain name. Eg: www.support.facebook-login.com */ 13 | public static String P3 = "(www\\\\.)?(([a-z]|([a-z](-|[a-z])*[a-z]))\\.)+[a-z]{2,6}"; 14 | 15 | /* Pattern to match a valid java variable name. Eg: _child13$ */ 16 | public static String P4 = "[^0-9][a-zA-Z0-9$_]*"; 17 | 18 | /* Pattern to match a valid IPv4 address. Eg: 127.0.0.1 */ 19 | public static String P5 = "(\\d?\\d?[0-9]\\.){3}\\d?\\d?[0-9]"; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Homework/hw4/TestReadInts.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | import java.util.List; 4 | import java.util.InputMismatchException; 5 | 6 | /** Runs tests of ReadInts class 7 | * @author Josh Hug 8 | */ 9 | 10 | public class TestReadInts { 11 | 12 | 13 | @Test 14 | /* For human evaluation. No automated testing here. */ 15 | public void testPrintInts() { 16 | String inp = "5 12 6 2 3"; 17 | System.out.println("Calling printInts(\"5 12 6 2 3\")"); 18 | ReadInts.printInts(inp); 19 | } 20 | 21 | @Test 22 | public void testReadInts() { 23 | List actual = ReadInts.readInts("5 12 6 2 3"); 24 | List expected = Utils.createList(5, 12, 6, 2, 3); 25 | assertEquals(expected, actual); 26 | try { 27 | ReadInts.readInts("5 1 3 dog horse 9"); 28 | fail("Exception should have been thrown!"); 29 | } catch (InputMismatchException e) { 30 | /* Ignore InputMismatchException. */ 31 | } 32 | } 33 | 34 | @Test 35 | public void testSmartReadInts() { 36 | List actual = ReadInts.smartReadInts("5 12 6 2 3"); 37 | List expected = Utils.createList(5, 12, 6, 2, 3); 38 | assertEquals(expected, actual); 39 | 40 | actual = ReadInts.smartReadInts("5 1 3 dog horse 9"); 41 | expected = Utils.createList(5, 1, 3, 9); 42 | assertEquals(expected, actual); 43 | } 44 | 45 | public static void main(String[] args) { 46 | System.exit(ucb.junit.textui.runClasses(TestReadInts.class)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Homework/hw4/Utils.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | import java.util.LinkedList; 3 | /** Utility functions for hw4. Do not modify this file. 4 | * If you need additional utilities, please make your 5 | * own class. 6 | * @author Josh Hug 7 | */ 8 | 9 | public class Utils { 10 | /** Make List from integer ARGS, e.g. 11 | * List x = createList(1, 6, 3, 2, 4); 12 | * Returns this new list. 13 | */ 14 | public static List createList(Integer... args) { 15 | LinkedList L = new LinkedList(); 16 | for (int k = 0; k < args.length; k += 1) { 17 | L.add(args[k]); 18 | } 19 | return L; 20 | } 21 | 22 | /** Prints an integer list L. */ 23 | public static void printList(List L) { 24 | for (int x : L) { 25 | System.out.print(x + " "); 26 | } 27 | System.out.println(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Homework/hw5/BitExercise.java: -------------------------------------------------------------------------------- 1 | /** A collection of bit twiddling exercises. 2 | * @author Brian Faun 3 | */ 4 | 5 | public class BitExercise { 6 | 7 | /** Fill in the function below so that it returns 8 | * the value of the argument x with all but its last 9 | * (least significant) 1-bit set to 0. 10 | * For example, 100 in binary is 0b1100100, so lastBit(100) 11 | * should return 4, which in binary is 0b100. 12 | */ 13 | public static int lastBit(int x) { 14 | return x & -x; 15 | } 16 | 17 | /** Fill in the function below so that it returns 18 | * True iff x is a power of two, otherwise False. 19 | * For example: 2, 32, and 8192 are powers of two. 20 | */ 21 | public static boolean powerOfTwo(int x) { 22 | return (x % 2 == 0) ; 23 | } 24 | 25 | /** Fill in the function below so that it returns 26 | * the absolute value of x WITHOUT USING ANY IF 27 | * STATEMENTS OR CALLS TO MATH. 28 | * For example, absolute(1) should return 1 and 29 | * absolute(-1) should return 1. 30 | */ 31 | public static int absolute(int x) { 32 | return ((x >> 10) + x) ^ (x >> 10); 33 | } 34 | 35 | public static void main (String [] args) { 36 | System.out.println(Math.pow(2, 3)); 37 | System.out.println((1 << 3)); 38 | } 39 | } -------------------------------------------------------------------------------- /Homework/hw5/BitExerciseTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | 4 | /** Tests of BitExercise 5 | * @author Zoe Plaxco 6 | */ 7 | public class BitExerciseTest { 8 | 9 | @Test 10 | public void testLastBit() { 11 | int four = BitExercise.lastBit(100); 12 | assertEquals(4, four); 13 | } 14 | 15 | @Test 16 | public void testPowerOfTwo() { 17 | boolean powOfTwo = BitExercise.powerOfTwo(32); 18 | assertTrue(powOfTwo); 19 | boolean notPower = BitExercise.powerOfTwo(7); 20 | assertFalse(notPower); 21 | } 22 | 23 | @Test 24 | public void testAbsolute() { 25 | int hundred = BitExercise.absolute(100); 26 | assertEquals(100, hundred); 27 | int negative = BitExercise.absolute(-100); 28 | assertEquals(100, negative); 29 | int zero = BitExercise.absolute(0); 30 | assertEquals(0, zero); 31 | } 32 | 33 | public static void main(String[] args) { 34 | System.exit(ucb.junit.textui.runClasses(BitExerciseTest.class)); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Homework/hw5/HW5Test.java: -------------------------------------------------------------------------------- 1 | /** Tests of HW5 2 | * @author P. N. Hilfinger, Zoe Plaxco 3 | */ 4 | public class HW5Test { 5 | 6 | public static void main(String[] args) { 7 | System.exit(ucb.junit.textui.runClasses(NybblesTest.class,BitExerciseTest.class)); 8 | } 9 | 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Homework/hw5/Makefile: -------------------------------------------------------------------------------- 1 | SHELL = bash 2 | 3 | STYLEPROG = style61b 4 | 5 | JFLAGS = -g -Xlint:unchecked -encoding utf8 6 | 7 | SRCS = $(wildcard *.java) 8 | 9 | CLASSES = $(SRCS:.java=.class) 10 | 11 | # Tell make that these are not really files. 12 | .PHONY: clean default style check 13 | 14 | default: compile 15 | 16 | compile: $(CLASSES) 17 | 18 | style: 19 | $(STYLEPROG) $(SRCS) 20 | 21 | $(CLASSES): sentinel 22 | 23 | sentinel: $(SRCS) 24 | javac $(JFLAGS) $(SRCS) 25 | touch $@ 26 | 27 | # Run Tests. 28 | check: compile 29 | java -ea HW5Test 30 | 31 | # Find and remove all *~ and *.class files. 32 | clean: 33 | $(RM) sentinel *.class *~ 34 | 35 | -------------------------------------------------------------------------------- /Homework/hw5/Nybbles.java: -------------------------------------------------------------------------------- 1 | /** Represents an array of integers each in the range -8..7. 2 | * Such integers may be represented in 4 bits (called nybbles). 3 | * @author Brian Faun 4 | */ 5 | public class Nybbles { 6 | 7 | /** Maximum positive value of a Nybble. */ 8 | public static final int MAX_VALUE = 7; 9 | 10 | public static void main (String [] args) { 11 | for (int i = 0; i < 16; i++) { 12 | System.out.print(i % 8); 13 | } 14 | System.out.println(); 15 | 16 | 17 | int[] a = new int[8]; 18 | for (int i = 0; i < 8; i++) { 19 | a[i] = i; 20 | System.out.println(); 21 | } 22 | } 23 | 24 | /** Return an array of size N. 25 | * DON'T CHANGE THIS.*/ 26 | public Nybbles(int N) { 27 | _data = new int[(N + 7) / 8]; 28 | _n = N; 29 | } 30 | 31 | /** Return the size of THIS. */ 32 | public int size() { 33 | return _n; 34 | } 35 | 36 | /** Return the Kth integer in THIS array, numbering from 0. 37 | * Assumes 0 <= K < N. */ 38 | public int get(int k) { 39 | if (k < 0 || k >= _n) { 40 | throw new IndexOutOfBoundsException(); 41 | } else { 42 | return (_data[k / 8] << 4 * (7 - k % 8)) >> 28; // REPLACE WITH SOLUTION 43 | } 44 | } 45 | 46 | /** Set the Kth integer in THIS array to VAL. Assumes 47 | * 0 <= K < N and -8 <= VAL < 8. */ 48 | public void set(int k, int val) { 49 | if (k < 0 || k >= _n) { 50 | throw new IndexOutOfBoundsException(); 51 | } else if (val < (-MAX_VALUE - 1) || val > MAX_VALUE) { 52 | throw new IllegalArgumentException(); 53 | } else { 54 | _data[k / 8] = (_data[k / 8] | (val & 0xF) << 4 * (k % 8)); 55 | } 56 | } 57 | 58 | /** DON'T CHANGE OR ADD TO THESE.*/ 59 | /** Size of current array (in nybbles). */ 60 | private int _n; 61 | /** The array data, packed 8 nybbles to an int. */ 62 | private int[] _data; 63 | } 64 | -------------------------------------------------------------------------------- /Homework/hw5/NybblesTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | 4 | /** Tests of Nybbles 5 | * @author P. N. Hilfinger 6 | */ 7 | public class NybblesTest { 8 | 9 | @Test 10 | public void testPos() { 11 | Nybbles arr = new Nybbles(16); 12 | for (int i = 0; i < arr.size(); i += 1) { 13 | arr.set(i, i % 8); 14 | } 15 | for (int i = 0; i < arr.size(); i += 1) { 16 | assertEquals(i % 8, arr.get(i)); 17 | } 18 | } 19 | 20 | @Test 21 | public void testNeg() { 22 | Nybbles arr = new Nybbles(16); 23 | for (int i = 0; i < arr.size(); i += 1) { 24 | arr.set(i, i % 8 - 8); 25 | } 26 | for (int i = 0; i < arr.size(); i += 1) { 27 | assertEquals(i % 8 - 8, arr.get(i)); 28 | } 29 | } 30 | 31 | @Test 32 | public void testMixed() { 33 | Nybbles arr = new Nybbles(16); 34 | for (int i = 0; i < arr.size(); i += 2) { 35 | arr.set(i, i / 2 - 8); 36 | arr.set(i + 1, i / 2); 37 | } 38 | for (int i = 0; i < arr.size(); i += 2) { 39 | assertEquals(i / 2 - 8, arr.get(i)); 40 | assertEquals(i / 2, arr.get(i + 1)); 41 | } 42 | } 43 | 44 | public static void main(String[] args) { 45 | System.exit(ucb.junit.textui.runClasses(NybblesTest.class)); 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /Homework/hw6/BSTStringSetTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | import java.util.List; 4 | 5 | /** 6 | * Test of a BST-based String Set. 7 | * @author Brian Faun 8 | */ 9 | public class BSTStringSetTest { 10 | // FIXME: Add your own tests for your BST StringSet 11 | 12 | @Test 13 | public void testNothing() { 14 | // FIXME: Delete this function and add your own tests 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Homework/hw6/ECHashStringSet.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | /** A set of String values. 4 | * @author Brian Faun 5 | */ 6 | class ECHashStringSet implements StringSet { 7 | private double _max = 5; 8 | private LinkedList[] hash; 9 | private int length; 10 | 11 | public ECHashStringSet(){ 12 | hash = new LinkedList[5]; 13 | for (int i = 0; i < 5; i++) { 14 | hash[i] = new LinkedList(); 15 | } 16 | length = 0; 17 | } 18 | 19 | @Override 20 | public void put(String s) { 21 | if (s == null) { 22 | return; 23 | } 24 | if (_max <= stack()) { 25 | List lst = asList(); 26 | hash = new LinkedList[2 * hash.length]; 27 | for (int i = 0; i < hash.length; i++) { 28 | hash[i] = new LinkedList(); 29 | } 30 | for (Object l : lst) { 31 | hash[(l.hashCode() & 0x7fffffff) % hash.length].add((String) l); 32 | } 33 | } 34 | hash[(s.hashCode() & 0x7fffffff) % hash.length].add(s); 35 | length ++; 36 | } 37 | 38 | @Override 39 | public boolean contains(String s) { 40 | int index = (s.hashCode() & 0x7fffffff) % hash.length; 41 | return hash[index].contains(s); 42 | } 43 | 44 | @Override 45 | public List asList() { 46 | LinkedList lst = new LinkedList(); 47 | for(LinkedList l : hash) { 48 | lst.addAll(l); 49 | } 50 | return lst; 51 | } 52 | 53 | private double stack() { 54 | return (double) length / (double) hash.length; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Homework/hw6/ECHashStringSetTest.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | import java.util.List; 4 | 5 | /** 6 | * Test of a BST-based String Set. 7 | * @author 8 | */ 9 | public class ECHashStringSetTest { 10 | // FIXME: Add your own tests for your ECHashStringSetTest 11 | 12 | @Test 13 | public void testNothing() { 14 | // FIXME: Delete this function and add your own tests 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Homework/hw6/HW6Test.java: -------------------------------------------------------------------------------- 1 | /** Tests of HW5 2 | * @author P. N. Hilfinger 3 | */ 4 | public class HW6Test { 5 | 6 | public static void main(String[] args) { 7 | System.exit(ucb.junit.textui.runClasses(BSTStringSetTest.class, 8 | BSTStringSetRangeTest.class, 9 | ECHashStringSetTest.class)); 10 | } 11 | 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Homework/hw6/Makefile: -------------------------------------------------------------------------------- 1 | SHELL = bash 2 | 3 | STYLEPROG = style61b 4 | 5 | JFLAGS = -g -Xlint:unchecked -encoding utf8 6 | 7 | SRCS = $(wildcard *.java) 8 | 9 | CLASSES = $(SRCS:.java=.class) 10 | 11 | # Tell make that these are not really files. 12 | .PHONY: clean default style check 13 | 14 | default: compile 15 | 16 | compile: $(CLASSES) 17 | 18 | style: 19 | $(STYLEPROG) $(SRCS) 20 | 21 | $(CLASSES): sentinel 22 | 23 | sentinel: $(SRCS) 24 | javac $(JFLAGS) $(SRCS) 25 | touch $@ 26 | 27 | # Run Tests. 28 | check: compile 29 | java -ea HW6Test 30 | 31 | # Find and remove all *~ and *.class files. 32 | clean: 33 | $(RM) sentinel *.class *~ 34 | 35 | -------------------------------------------------------------------------------- /Homework/hw6/SortedStringSet.java: -------------------------------------------------------------------------------- 1 | import java.util.Iterator; 2 | 3 | /** A type of StringSet with a bounded iterator producing Strings in 4 | * ascending lexicographic order. 5 | * @author P. N. Hilfinger. 6 | */ 7 | public interface SortedStringSet extends StringSet { 8 | /** Return an Iterator yielding all my strings that are between L 9 | * (inclusive) and U (exclusive) in ascending order. */ 10 | Iterator iterator(String L, String U); 11 | } 12 | -------------------------------------------------------------------------------- /Homework/hw6/Stopwatch.java: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Compilation: javac Stopwatch.java 3 | * 4 | * 5 | *************************************************************************/ 6 | 7 | /** 8 | * The Stopwatch data type is for measuring 9 | * the time that elapses between the start and end of a 10 | * programming task (wall-clock time). 11 | * 12 | * See {@link StopwatchCPU} for a version that measures CPU time. 13 | * 14 | * @author Robert Sedgewick 15 | * @author Kevin Wayne 16 | */ 17 | 18 | 19 | public class Stopwatch { 20 | 21 | /** Starting time, in milliseconds since the Epoch. */ 22 | private final long start; 23 | 24 | /** 25 | * Initialize a stopwatch object. 26 | */ 27 | public Stopwatch() { 28 | start = System.currentTimeMillis(); 29 | } 30 | 31 | 32 | /** 33 | * Returns the elapsed time (in seconds) since this object was created. 34 | */ 35 | public double elapsedTime() { 36 | long now = System.currentTimeMillis(); 37 | return (now - start) / 1000.0; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Homework/hw6/StringSet.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | 3 | /** Interface for a basic String set. 4 | * @author Josh Hug and Paul Hilfinger */ 5 | public interface StringSet { 6 | /** Adds the string S to the string set. If it is already present in the 7 | * set, do nothing. */ 8 | void put(String s); 9 | 10 | /** Returns true iff S is in the string set. */ 11 | boolean contains(String s); 12 | 13 | /** Return a list of all members of this set in ascending order. */ 14 | List asList(); 15 | } 16 | -------------------------------------------------------------------------------- /Homework/hw6/hw6timing.txt: -------------------------------------------------------------------------------- 1 | 1a. Results for InsertRandomSpeedTest for N = 1000000: 2 | BSTStringSet: 1.10 s 3 | ECHashStringSet: 0.16 s 4 | TreeSet: 1.07 s 5 | HashSet: 0.44 s 6 | 7 | 8 | 1b. Results for InsertRandomSpeedTest for N = 2000000: 9 | BSTStringSet: 2.41 s 10 | ECHashStringSet: 0.22 s 11 | TreeSet: 2.37 s 12 | HashSet: 0.79 s 13 | 14 | 1c. Does your ECHashStringSet look roughly linear or roughly quadratic 15 | in its scaling behavior for random strings? 16 | ECHashStringset looks roughly linear for its scaling behavior from one million to two million. 17 | 18 | 19 | 2a. Results for InsertInOrderSpeedTest for N = 10000: 20 | BSTStringSet: 0.79 s 21 | ECHashStringSet: 0.01 s 22 | TreeSet: 0.01 s 23 | HashSet: 0.00 s 24 | 25 | 2b. Results for InsertInOrderSpeedTest for N = 20000: 26 | BSTStringSet: 2.24 s 27 | ECHashStringSet: 0.01 s 28 | TreeSet: 0.03 s 29 | HashSet: 0.02 s 30 | 31 | 2c. Does your **BST**StringSet look roughly linear or roughly 32 | quadratic in its scaling behavior for in order strings? 33 | BSTStringSet looks roughy quadratic when inserting in order, as opposed to when inserting in random. 34 | 35 | 36 | Before submitting, make sure that your ECHashStringSet is capable of 37 | handling inputs of size 1000000 in a reasonable amount of time (a few 38 | seconds). 39 | 40 | -------------------------------------------------------------------------------- /Homework/hw7/Inversions.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.List; 3 | 4 | /** HW #7, Count inversions. 5 | * @author 6 | */ 7 | public class Inversions { 8 | 9 | /** A main program for testing purposes. Prints the number of inversions 10 | * in the sequence ARGS. */ 11 | public static void main(String[] args) { 12 | System.out.println(inversions(Arrays.asList(args))); 13 | } 14 | 15 | /** Return the number of inversions of T objects in ARGS. */ 16 | public static > 17 | int inversions(List args) { 18 | return 0; // REPLACE WITH YOUR ANSWER 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Homework/hw7/Makefile: -------------------------------------------------------------------------------- 1 | SHELL = bash 2 | 3 | STYLEPROG = style61b 4 | 5 | JFLAGS = -g -Xlint:unchecked -encoding utf8 6 | 7 | SRCS = $(wildcard *.java) 8 | 9 | CLASSES = $(SRCS:.java=.class) 10 | 11 | # Tell make that these are not really files. 12 | .PHONY: clean default style check 13 | 14 | default: compile 15 | 16 | compile: $(CLASSES) 17 | 18 | style: 19 | $(STYLEPROG) $(SRCS) 20 | 21 | $(CLASSES): sentinel 22 | 23 | sentinel: $(SRCS) 24 | javac $(JFLAGS) $(SRCS) 25 | touch $@ 26 | 27 | # Run Tests. 28 | check: compile 29 | @echo Replace with testing instructions, as desired. 30 | 31 | # Find and remove all *~ and *.class files. 32 | clean: 33 | $(RM) sentinel *.class *~ 34 | 35 | -------------------------------------------------------------------------------- /Homework/hw7/SortInts.java: -------------------------------------------------------------------------------- 1 | /** HW #7, Distribution counting for large numbers. 2 | * @author Brian Faun 3 | */ 4 | public class SortInts { 5 | 6 | /** Sort A into ascending order. Assumes that 0 <= A[i] < n*n for all 7 | * i, and that the A[i] are distinct. */ 8 | static void sort(long[] A) { 9 | long in; 10 | int prev; 11 | for (int i = 0; i < A.length; i++) { 12 | in = A[i]; 13 | prev = i - 1; 14 | while (prev >= 0 && A[prev] > in) { 15 | A[prev + 1] = A[prev]; 16 | prev--; 17 | } 18 | A[prev + 1] = in; 19 | } 20 | } 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Homework/hw7/SortingAlgorithm.java: -------------------------------------------------------------------------------- 1 | /** 2 | * A sorting algorithm (e.g. Selection Sort, Insertion Sort, etc.) 3 | * that implements a single sort method. 4 | * @author Josh Hug 5 | */ 6 | public interface SortingAlgorithm { 7 | 8 | /** 9 | * Given a not-necessarily sorted array ARRAY, puts the first 10 | * K elements in sorted ascending order. 11 | * 12 | * Precondition: K <= ARRAY.LENGTH 13 | */ 14 | void sort(int[] array, int k); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Homework/hw7/Stopwatch.java: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Compilation: javac Stopwatch.java 3 | * 4 | * 5 | *************************************************************************/ 6 | 7 | /** 8 | * The Stopwatch data type is for measuring 9 | * the time that elapses between the start and end of a 10 | * programming task (wall-clock time). 11 | * 12 | * See {@link StopwatchCPU} for a version that measures CPU time. 13 | * 14 | * @author Robert Sedgewick 15 | * @author Kevin Wayne 16 | */ 17 | 18 | 19 | public class Stopwatch { 20 | 21 | /** Time at which I was started. */ 22 | private final long _start; 23 | 24 | /** 25 | * Initialize a stopwatch object. 26 | */ 27 | public Stopwatch() { 28 | _start = System.currentTimeMillis(); 29 | } 30 | 31 | 32 | /** 33 | * Returns the elapsed time (in seconds) since this object was created. 34 | */ 35 | public double elapsedTime() { 36 | long now = System.currentTimeMillis(); 37 | return (now - _start) / 1000.0; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Homework/hw7/Sum.java: -------------------------------------------------------------------------------- 1 | /** HW #7, Two-sum problem. 2 | * @author 3 | */ 4 | public class Sum { 5 | 6 | /** Returns true iff A[i]+B[j] = M for some i and j. */ 7 | public static boolean sumsTo(int[] A, int[] B, int m) { 8 | return false; // REPLACE WITH YOUR ANSWER 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Homework/hw8/Makefile: -------------------------------------------------------------------------------- 1 | SHELL = bash 2 | 3 | STYLEPROG = style61b 4 | 5 | JFLAGS = -g -Xlint:unchecked -encoding utf8 6 | 7 | SRCS = $(wildcard *.java) 8 | 9 | CLASSES = $(SRCS:.java=.class) 10 | 11 | # Tell make that these are not really files. 12 | .PHONY: clean default style check 13 | 14 | default: compile 15 | 16 | compile: $(CLASSES) 17 | 18 | style: 19 | $(STYLEPROG) $(SRCS) 20 | 21 | check: $(CLASSES) 22 | java -ea MSTTest 23 | 24 | $(CLASSES): sentinel 25 | 26 | sentinel: $(SRCS) 27 | javac $(JFLAGS) $(SRCS) 28 | touch $@ 29 | 30 | # Find and remove all *~ and *.class files. 31 | clean: 32 | $(RM) sentinel *.class *~ 33 | 34 | -------------------------------------------------------------------------------- /Homework/hw9/.idea/libraries/lib.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Homework/hw9/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Homework/hw9/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Homework/hw9/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Homework/hw9/Makefile: -------------------------------------------------------------------------------- 1 | # make # Defaults to the first target: default 2 | # make default # Same as make compile. 3 | # make compile # Compiles Java code in this directory. 4 | # make style # Runs style checks (only on instructional machines) 5 | # make check # Compile if needed and test using NFATests. 6 | # make clean # Remove extraneous or rebuildable files 7 | 8 | # Define $(SRCS) to be a list of Java files. 9 | SRCS = NFA.java NFATests.java 10 | 11 | # The targets following .PHONY aren't actually files; they serve as commands. 12 | .PHONY: compile default check clean style 13 | 14 | # By default, compile all sources 15 | default: compile 16 | 17 | # To compile all source files, just bring the file NFATests.class up to date. 18 | compile: NFATests.class 19 | 20 | # Run our style checks. 21 | style: 22 | style61b $(SRCS) 23 | 24 | # Test the compiled program, after first making sure it is up-to-date. 25 | check: NFATests.class 26 | java -ea NFATests 27 | 28 | # Remove extraneous or reconstructable files. 29 | clean: 30 | rm -f *.class *~ 31 | 32 | NFATests.class: $(SRCS) 33 | javac -g $(SRCS) 34 | -------------------------------------------------------------------------------- /Homework/hw9/hw9.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/.idea/libraries/lib.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/Makefile: -------------------------------------------------------------------------------- 1 | # make # Defaults to the first target: default 2 | # make default # Same as make compile. 3 | # make compile # Compiles Java code in this directory. 4 | # make style # Runs style checks (only on instructional machines) 5 | # make check # Compile if needed and test using NFATests. 6 | # make clean # Remove extraneous or rebuildable files 7 | 8 | # Define $(SRCS) to be a list of Java files. 9 | SRCS = NFA.java NFATests.java 10 | 11 | # The targets following .PHONY aren't actually files; they serve as commands. 12 | .PHONY: compile default check clean style 13 | 14 | # By default, compile all sources 15 | default: compile 16 | 17 | # To compile all source files, just bring the file NFATests.class up to date. 18 | compile: NFATests.class 19 | 20 | # Run our style checks. 21 | style: 22 | style61b $(SRCS) 23 | 24 | # Test the compiled program, after first making sure it is up-to-date. 25 | check: NFATests.class 26 | java -ea NFATests 27 | 28 | # Remove extraneous or reconstructable files. 29 | clean: 30 | rm -f *.class *~ 31 | 32 | NFATests.class: $(SRCS) 33 | javac -g $(SRCS) 34 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/NFA$State.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Homework/hw9/out/production/hw9/NFA$State.class -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/NFA.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Homework/hw9/out/production/hw9/NFA.class -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/NFATests$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Homework/hw9/out/production/hw9/NFATests$1.class -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/NFATests.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Homework/hw9/out/production/hw9/NFATests.class -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/hw9.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/hard/berkeleyWebsites.in: -------------------------------------------------------------------------------- 1 | ((www.)|(http://)|(https://))(\l+.)+(berkeley.edu)(/(\l|\d)+)* 2 | * https://ls.berkeley.edu http://guide.berkeley.edu/undergraduate https://inst.eecs.berkeley.edu/cs61b/fa19/materials/hw/hw8 3 | ** www.stanfurd.edu https://inst.eecs.berkeley.edu.fakepath http:// www. https:// http://berkeley.edu http://berkeley.edu// -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/hard/commaSeparated.in: -------------------------------------------------------------------------------- 1 | ((\l|\d)+,)*(\l|\d)+ 2 | * dog,cat milk,eggs,butter cs61a,cs61b,cs70 thanos,mudit joe,itai,omar single comma,separated,values 1,2,3 3 | ** dog,cat, ,milk,eggs , ,, ,,, this,that,,those this,,is,unacceptable curse,,you,,perry,,the,platypus 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/hard/emailaddress.in: -------------------------------------------------------------------------------- 1 | \l(\l|\d)*@((gmail)|(hotmail)|(yahoo)).com 2 | * a@hotmail.com a1@hotmail.com omarkhan902@gmail.com cs61b@gmail.com 3 | ** 1@gmail.com 100a@hotmail.com @gmail.com hotmail.com .com gmail hotmail yahoo bunchofrandomgarbagethisisjusttolookatyourtimingbecauseeventhoughthisisnotgoingtomatchitshouldnttakethatlongtotellthatitcannotmatch 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/hard/phonenumber.in: -------------------------------------------------------------------------------- 1 | \d\d\d-\d\d\d-\d\d\d\d 2 | * 707-799-1083 510-642-6000 707-775-6322 707-762-1000 3 | ** 911 7077621000 707-7990-1083 7070-799-1083 7o7-799-1o83 707-799-108E 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/medium/aOrbStar.in: -------------------------------------------------------------------------------- 1 | (a|b)* 2 | ** a b aa bb aaa bbb ab ba aaaab bbbba bbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbb ababbbbabbaaaaabababbbabababababbbbbbbaababababbbbabbaaaaaababaababababbababababababa 3 | * c aac bbbac caaaabbbabbabbbbaaaabababababa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcbbbbbbbbbbbbba 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/medium/abOrcd.in: -------------------------------------------------------------------------------- 1 | (ab)|(cd) 2 | * ab cd 3 | ** a b c d ba dc abcd cdab db ac 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/medium/abPlus.in: -------------------------------------------------------------------------------- 1 | (ab)+ 2 | * ab abab ababab abababababababababababababababababababababababababababababab 3 | ** a b ba aba baba abababababababababbababababababababab 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/medium/abStar.in: -------------------------------------------------------------------------------- 1 | (ab)* 2 | ** ab abab ababab ababababababababab ababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab 3 | * a b ba aba baba abababababababababbababababababababab 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/medium/astarA.in: -------------------------------------------------------------------------------- 1 | a*a 2 | * a aa aaa aaaa aaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 | ** ba aaaab baaaa bbbbba aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaa 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/medium/highlyNested.in: -------------------------------------------------------------------------------- 1 | (a(b(c(d|e)*)*)*) 2 | * a ab abb abbb abc abbc abcb abcbbccbbbccb abcd abce abcde abcdededed abcdec abcdeeecb abcdbcdbcdbcd 3 | ** aa aab abbba abca abcdf abbacd abcdabcd 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/medium/lotsOfPlus.in: -------------------------------------------------------------------------------- 1 | ((a+)+a+b)+ 2 | * aab aaab aaaab aaaaab aabaab aaabaaab aaaaabaaaaab aabaabaab aaaaaaaaaaaaabaabaabaab 3 | ** a aa b ab aaba aabaa aabab abaabaab aaaaaaaaaaaaaaaaaaaaabaabaabb 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/simple/a.in: -------------------------------------------------------------------------------- 1 | a 2 | * a 3 | ** aa ba aaa 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/simple/aOrb.in: -------------------------------------------------------------------------------- 1 | a|b 2 | * a b 3 | ** ab ba _a _b 0a 0b 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/simple/aOrbParens.in: -------------------------------------------------------------------------------- 1 | (a|b) 2 | * a b 3 | ** ab ba _a _b 0a 0b 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/simple/ab.in: -------------------------------------------------------------------------------- 1 | ab 2 | * ab 3 | ** a b aba ba aab 0ab _ab abb 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/simple/aplus.in: -------------------------------------------------------------------------------- 1 | a+ 2 | * a aa aaa aaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 | ** ba aaaab aaaaabaaaaa 4 | -------------------------------------------------------------------------------- /Homework/hw9/out/production/hw9/testing/simple/astar.in: -------------------------------------------------------------------------------- 1 | a* 2 | ** a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 | * _a baaa 0a aaaaaaab aaaaaaaaaaaaaabaaaaaaaaaa Aa 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/hard/berkeleyWebsites.in: -------------------------------------------------------------------------------- 1 | ((www.)|(http://)|(https://))(\l+.)+(berkeley.edu)(/(\l|\d)+)* 2 | * https://ls.berkeley.edu http://guide.berkeley.edu/undergraduate https://inst.eecs.berkeley.edu/cs61b/fa19/materials/hw/hw8 3 | ** www.stanfurd.edu https://inst.eecs.berkeley.edu.fakepath http:// www. https:// http://berkeley.edu http://berkeley.edu// -------------------------------------------------------------------------------- /Homework/hw9/testing/hard/commaSeparated.in: -------------------------------------------------------------------------------- 1 | ((\l|\d)+,)*(\l|\d)+ 2 | * dog,cat milk,eggs,butter cs61a,cs61b,cs70 thanos,mudit joe,itai,omar single comma,separated,values 1,2,3 3 | ** dog,cat, ,milk,eggs , ,, ,,, this,that,,those this,,is,unacceptable curse,,you,,perry,,the,platypus 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/hard/emailaddress.in: -------------------------------------------------------------------------------- 1 | \l(\l|\d)*@((gmail)|(hotmail)|(yahoo)).com 2 | * a@hotmail.com a1@hotmail.com omarkhan902@gmail.com cs61b@gmail.com 3 | ** 1@gmail.com 100a@hotmail.com @gmail.com hotmail.com .com gmail hotmail yahoo bunchofrandomgarbagethisisjusttolookatyourtimingbecauseeventhoughthisisnotgoingtomatchitshouldnttakethatlongtotellthatitcannotmatch 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/hard/phonenumber.in: -------------------------------------------------------------------------------- 1 | \d\d\d-\d\d\d-\d\d\d\d 2 | * 707-799-1083 510-642-6000 707-775-6322 707-762-1000 3 | ** 911 7077621000 707-7990-1083 7070-799-1083 7o7-799-1o83 707-799-108E 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/medium/aOrbStar.in: -------------------------------------------------------------------------------- 1 | (a|b)* 2 | ** a b aa bb aaa bbb ab ba aaaab bbbba bbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbb ababbbbabbaaaaabababbbabababababbbbbbbaababababbbbabbaaaaaababaababababbababababababa 3 | * c aac bbbac caaaabbbabbabbbbaaaabababababa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcbbbbbbbbbbbbba 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/medium/abOrcd.in: -------------------------------------------------------------------------------- 1 | (ab)|(cd) 2 | * ab cd 3 | ** a b c d ba dc abcd cdab db ac 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/medium/abPlus.in: -------------------------------------------------------------------------------- 1 | (ab)+ 2 | * ab abab ababab abababababababababababababababababababababababababababababab 3 | ** a b ba aba baba abababababababababbababababababababab 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/medium/abStar.in: -------------------------------------------------------------------------------- 1 | (ab)* 2 | ** ab abab ababab ababababababababab ababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab 3 | * a b ba aba baba abababababababababbababababababababab 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/medium/astarA.in: -------------------------------------------------------------------------------- 1 | a*a 2 | * a aa aaa aaaa aaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 | ** ba aaaab baaaa bbbbba aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaa 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/medium/highlyNested.in: -------------------------------------------------------------------------------- 1 | (a(b(c(d|e)*)*)*) 2 | * a ab abb abbb abc abbc abcb abcbbccbbbccb abcd abce abcde abcdededed abcdec abcdeeecb abcdbcdbcdbcd 3 | ** aa aab abbba abca abcdf abbacd abcdabcd 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/medium/lotsOfPlus.in: -------------------------------------------------------------------------------- 1 | ((a+)+a+b)+ 2 | * aab aaab aaaab aaaaab aabaab aaabaaab aaaaabaaaaab aabaabaab aaaaaaaaaaaaabaabaabaab 3 | ** a aa b ab aaba aabaa aabab abaabaab aaaaaaaaaaaaaaaaaaaaabaabaabb 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/simple/a.in: -------------------------------------------------------------------------------- 1 | a 2 | * a 3 | ** aa ba aaa 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/simple/aOrb.in: -------------------------------------------------------------------------------- 1 | a|b 2 | * a b 3 | ** ab ba _a _b 0a 0b 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/simple/aOrbParens.in: -------------------------------------------------------------------------------- 1 | (a|b) 2 | * a b 3 | ** ab ba _a _b 0a 0b 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/simple/ab.in: -------------------------------------------------------------------------------- 1 | ab 2 | * ab 3 | ** a b aba ba aab 0ab _ab abb 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/simple/aplus.in: -------------------------------------------------------------------------------- 1 | a+ 2 | * a aa aaa aaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 | ** ba aaaab aaaaabaaaaa 4 | -------------------------------------------------------------------------------- /Homework/hw9/testing/simple/astar.in: -------------------------------------------------------------------------------- 1 | a* 2 | ** a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 | * _a baaa 0a aaaaaaab aaaaaaaaaaaaaabaaaaaaaaaa Aa 4 | -------------------------------------------------------------------------------- /Labs/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Labs/.DS_Store -------------------------------------------------------------------------------- /Labs/lab1/AGTestYear.java: -------------------------------------------------------------------------------- 1 | import org.junit.Test; 2 | import static org.junit.Assert.*; 3 | import ucb.junit.textui; 4 | 5 | /** Autograder tests for the Year class using the Test61B package. 6 | * @author Sarah Kim, P. N. Hilfinger 7 | */ 8 | public class AGTestYear { 9 | 10 | @Test 11 | public void test400() { 12 | String msg = "should be leap year"; 13 | assertTrue(msg, Year.isLeapYear(2000)); 14 | assertTrue(msg, Year.isLeapYear(2400)); 15 | } 16 | 17 | @Test 18 | public void testLeapYearNotDivisible100() { 19 | String msg = "should be leap year"; 20 | assertTrue(msg, Year.isLeapYear(2004)); 21 | assertTrue(msg, Year.isLeapYear(2008)); 22 | } 23 | 24 | @Test 25 | public void testDivisible400And100() { 26 | String msg = "should not be leap year"; 27 | assertFalse(msg, Year.isLeapYear(1900)); 28 | assertFalse(msg, Year.isLeapYear(2100)); 29 | assertFalse(msg, Year.isLeapYear(2300)); 30 | } 31 | 32 | @Test 33 | public void testDivisibleNot4() { 34 | String msg = "should not be leap year"; 35 | assertFalse(msg, Year.isLeapYear(1901)); 36 | assertFalse(msg, Year.isLeapYear(2003)); 37 | } 38 | 39 | public static void main(String[] args) { 40 | System.exit(textui.runClasses(AGTestYear.class)); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Labs/lab1/Year.java: -------------------------------------------------------------------------------- 1 | /** Class that determines whether or not a year is a leap year. 2 | * @author YOUR NAME HERE 3 | */ 4 | public class Year { 5 | 6 | /** Return true iff YEAR is a leap year. */ 7 | static boolean isLeapYear(int year) { 8 | if (year % 400 == 0){ 9 | return true; 10 | } 11 | if ((year % 4 == 0) && (year % 100 != 0)){ 12 | return true; 13 | } 14 | return false; 15 | } 16 | 17 | /** Print whether YEAR is a a leap year on System.out. */ 18 | private static void checkLeapYear(int year) { 19 | if (isLeapYear(year)) { 20 | System.out.printf("%d is a leap year.\n", year); 21 | } else { 22 | System.out.printf("%d is not a leap year.\n", year); 23 | } 24 | } 25 | 26 | /** For each item in ARGS (an array of one or more numerals), print 27 | * whether it is a leap year. */ 28 | public static void main(String[] args) { 29 | if (args.length < 1) { 30 | System.out.println("Please enter command line arguments."); 31 | System.out.println("e.g. java Year 2000"); 32 | System.exit(1); 33 | } 34 | for (int i = 0; i < args.length; i++) { 35 | try { 36 | int year = Integer.parseInt(args[i]); 37 | checkLeapYear(year); 38 | } catch (NumberFormatException e) { 39 | System.out.printf("%s is not a valid number.\n", args[i]); 40 | } 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Labs/lab12/.gitignore: -------------------------------------------------------------------------------- 1 | .capers 2 | capers/.capers -------------------------------------------------------------------------------- /Labs/lab12/.idea/libraries/ucb.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Labs/lab12/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Labs/lab12/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Labs/lab12/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Labs/lab12/Makefile: -------------------------------------------------------------------------------- 1 | # This makefile is defined to give you the following targets: 2 | # 3 | # default: The default target: Compiles the program in package db61b. 4 | # style: Run our style checker on the project source files. Requires that 5 | # the source files compile. 6 | # check: Compiles the db61b package, if needed, and then performs the 7 | # tests described in testing/Makefile. 8 | # clean: Remove regeneratable files (such as .class files) produced by 9 | # other targets and Emacs backup files. 10 | # 11 | # In other words, type 'make' to compile everything; 'make check' to 12 | # compile and test everything, and 'make clean' to clean things up. 13 | # 14 | # You can use this file without understanding most of it, of course, but 15 | # I strongly recommend that you try to figure it out, and where you cannot, 16 | # that you ask questions. The Lab Reader contains documentation. 17 | 18 | # Name of package containing main procedure 19 | PACKAGE = capers 20 | 21 | STYLEPROG = style61b 22 | 23 | # The name of the Python 3 program, used in the 'check' target. If your system 24 | # has a different name for this program (such as just "python"), run 25 | # the Makefile with 26 | # make PYTHON=python check 27 | PYTHON = python3 28 | 29 | # Flags to pass to tester.py. 30 | TESTER_FLAGS = 31 | 32 | RMAKE = "$(MAKE)" 33 | 34 | # Targets that don't correspond to files, but are to be treated as commands. 35 | .PHONY: default check integration unit clean style 36 | 37 | default: 38 | $(RMAKE) -C $(PACKAGE) default 39 | 40 | check: integration unit 41 | 42 | integration: default 43 | $(RMAKE) -C testing PYTHON=$(PYTHON) TESTER_FLAGS="$(TESTER_FLAGS)" check 44 | 45 | unit: default 46 | $(RMAKE) -C gitlet unit 47 | 48 | style: 49 | $(RMAKE) -C $(PACKAGE) STYLEPROG=$(STYLEPROG) style 50 | 51 | # 'make clean' will clean up stuff you can reconstruct. 52 | clean: 53 | $(RM) *~ 54 | $(RMAKE) -C $(PACKAGE) clean 55 | 56 | 57 | -------------------------------------------------------------------------------- /Labs/lab12/capers/Dog.java: -------------------------------------------------------------------------------- 1 | package capers; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.Serializable; 6 | 7 | /** Represents a dog that can be serialized. 8 | * @author Sean Dooher 9 | */ 10 | public class Dog implements Serializable{ // FIXME 11 | 12 | /** Folder that dogs live in. */ 13 | static final File DOG_FOLDER = new File(".capers/dogs"); 14 | 15 | /** 16 | * Creates a dog object with the specified parameters. 17 | * @param name Name of dog 18 | * @param breed Breed of dog 19 | * @param age Age of dog 20 | */ 21 | public Dog(String name, String breed, int age) { 22 | _age = age; 23 | _breed = breed; 24 | _name = name; 25 | } 26 | 27 | /** 28 | * Reads in and deserializes a dog from a file with name NAME in DOG_FOLDER. 29 | * 30 | * @param name Name of dog to load 31 | * @return Dog read from file 32 | */ 33 | public static Dog fromFile(String name) { 34 | File dog = Utils.join(DOG_FOLDER, name); 35 | return Utils.readObject(dog, Dog.class); 36 | } 37 | 38 | /** 39 | * Increases a dog's age and celebrates! 40 | */ 41 | public void haveBirthday() { 42 | _age ++; 43 | System.out.println(toString()); 44 | System.out.println("Happy birthday! Woof! Woof!"); 45 | } 46 | 47 | /** 48 | * Saves a dog to a file for future use. 49 | */ 50 | public void saveDog() { 51 | File saveFile = Utils.join(DOG_FOLDER, _name); 52 | try { 53 | saveFile.createNewFile(); 54 | } catch (IOException e) { 55 | e.printStackTrace(); 56 | } 57 | Utils.writeObject(saveFile, this); 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return String.format( 63 | "Woof! My name is %s and I am a %s! I am %d years old! Woof!", 64 | _name, _breed, _age); 65 | } 66 | 67 | /** Age of dog. */ 68 | private int _age; 69 | /** Breed of dog. */ 70 | private String _breed; 71 | /** Name of dog. */ 72 | private String _name; 73 | } 74 | -------------------------------------------------------------------------------- /Labs/lab12/lab12.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Labs/lab12/partner.txt: -------------------------------------------------------------------------------- 1 | Lab Partner's name: 2 | Lab Partner's SID: 3 | Lab Partner's email: -------------------------------------------------------------------------------- /Labs/lab13/partner.txt: -------------------------------------------------------------------------------- 1 | Lab Partner's name: 2 | Lab Partner's SID: 3 | Lab Partner's email: -------------------------------------------------------------------------------- /Labs/lab14/MST.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Comparator; 3 | 4 | /** Minimal spanning tree utility. 5 | * @author Brian Faun 6 | */ 7 | public class MST { 8 | 9 | /** Given an undirected, weighted, connected graph whose vertices are 10 | * numbered 1 to V, and an array E of edges, returns an array of edges 11 | * in E that form a minimal spanning tree of the input graph. 12 | * Each edge in E is a three-element int array of the form (u, v, w), 13 | * where 0 < u < v <= V are vertex numbers, and 0 <= w is the weight 14 | * of the edge. The result is an array containing edges from E. 15 | * Neither E nor the arrays in it may be modified. There may be 16 | * multiple edges between vertices. The objects in the returned array 17 | * are a subset of those in E (they do not include copies of the 18 | * original edges, just the original edges themselves.) */ 19 | public static int[][] mst(int V, int[][] E) { 20 | E = Arrays.copyOf(E, E.length); 21 | int numEdgesInResult = V - 1; // FIXME: how many edges should there be in our MST? 22 | int[][] result = new int[numEdgesInResult][]; 23 | // FIXME: what other data structures do I need? 24 | unionFind = new UnionFind(V); 25 | Arrays.sort(E, EDGE_WEIGHT_COMPARATOR); 26 | // FIXME: do Kruskal's Algorithm 27 | int i = 0, count; 28 | for (count = 0; count < V - 1; i++) { 29 | int[] edge = E[i]; 30 | if (!unionFind.samePartition(edge[0], edge[1])) { 31 | result[count] = edge; 32 | unionFind.union(edge[0], edge[1]); 33 | count++; 34 | } 35 | } 36 | return result; 37 | } 38 | 39 | /** An ordering of edges by weight. */ 40 | private static final Comparator EDGE_WEIGHT_COMPARATOR = 41 | new Comparator() { 42 | @Override 43 | public int compare(int[] e0, int[] e1) { 44 | return e0[2] - e1[2]; 45 | } 46 | }; 47 | 48 | /** UnionFind data structure. */ 49 | static UnionFind unionFind; 50 | } 51 | -------------------------------------------------------------------------------- /Labs/lab14/partner.txt: -------------------------------------------------------------------------------- 1 | Lab Partner's name: 2 | Lab Partner's SID: 3 | Lab Partner's email: -------------------------------------------------------------------------------- /Labs/lab2/IntListTest.java: -------------------------------------------------------------------------------- 1 | import static org.junit.Assert.*; 2 | import org.junit.Test; 3 | 4 | public class IntListTest { 5 | 6 | /** Sample test that verifies correctness of the IntList.list static 7 | * method. The main point of this is to convince you that 8 | * assertEquals knows how to handle IntLists just fine. 9 | */ 10 | 11 | @Test 12 | public void testList() { 13 | IntList one = new IntList(1, null); 14 | IntList twoOne = new IntList(2, one); 15 | IntList threeTwoOne = new IntList(3, twoOne); 16 | 17 | IntList x = IntList.list(3, 2, 1); 18 | assertEquals(threeTwoOne, x); 19 | } 20 | 21 | @Test 22 | public void testSum() { 23 | assertEquals(15, IntList.sum(IntList.list(1, 2, 3, 4, 5))); 24 | } 25 | 26 | @Test 27 | public void testdSquareList() { 28 | IntList L = IntList.list(1, 2, 3); 29 | IntList.dSquareList(L); 30 | assertEquals(IntList.list(1, 4, 9), L); 31 | } 32 | 33 | /* Do not use the "new" keyword in your tests. You can create 34 | * lists using the handy IntList.list method. 35 | * 36 | * Make sure to include test cases involving lists of various sizes 37 | * on both sides of the operation. That includes the empty list, which 38 | * can be instantiated, for example, with 39 | * IntList empty = IntList.list(). 40 | */ 41 | 42 | @Test 43 | public void testSquareListRecursive() { 44 | // TODO: test for correctness 45 | assertEquals(IntList.list(1,4,9), IntList.squareListRecursive(IntList.list(1,2,3))); 46 | 47 | // TODO: test for non-destructiveness 48 | IntList tester = IntList.list(1, 2, 3); 49 | IntList.squareListRecursive(tester); 50 | assertEquals(tester, IntList.list(1,2,3)); 51 | 52 | } 53 | 54 | /* Run the unit tests in this file. */ 55 | public static void main(String... args) { 56 | System.exit(ucb.junit.textui.runClasses(IntListTest.class)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Labs/lab2/partner.txt: -------------------------------------------------------------------------------- 1 | Partner's name: Matt Chorlian 2 | Partner's SID: 3033045472 3 | Partner's email: mattchorlian@berkeley.edu 4 | -------------------------------------------------------------------------------- /Labs/lab3/checkoff.txt: -------------------------------------------------------------------------------- 1 | Banana Knob -------------------------------------------------------------------------------- /Labs/lab3/partner.txt: -------------------------------------------------------------------------------- 1 | Lab Partner's name: Matt Chorlian 2 | Lab Partner's SID: 3033045472 3 | Lab Partner's email: mattchorlian@berkeley.edu 4 | -------------------------------------------------------------------------------- /Labs/lab5/.idea/libraries/gjdb.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Labs/lab5/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Labs/lab5/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Labs/lab5/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Labs/lab5/ColumnMatchFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * TableFilter to filter for entries whose two columns match. 3 | * 4 | * @author Matthew Owen 5 | */ 6 | public class ColumnMatchFilter extends TableFilter { 7 | Table _input; 8 | String _colName1, _colName2; 9 | 10 | public ColumnMatchFilter(Table input, String colName1, String colName2) { 11 | super(input); 12 | _input = input; 13 | _colName1 = colName1; 14 | _colName2 = colName2; 15 | } 16 | 17 | @Override 18 | protected boolean keep() { 19 | int col1 = _input.colNameToIndex(_colName1); 20 | int col2 = _input.colNameToIndex(_colName2); 21 | if (_next.getValue(col1).equals(_next.getValue(col2))) { 22 | return true; 23 | } else { 24 | return false; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Labs/lab5/EqualityFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * TableFilter to filter for entries equal to a given string. 3 | * 4 | * @author Matthew Owen 5 | */ 6 | public class EqualityFilter extends TableFilter { 7 | Table _input; 8 | String _colName, _match; 9 | 10 | public EqualityFilter(Table input, String colName, String match) { 11 | super(input); 12 | _input = input; 13 | _colName = colName; 14 | _match = match; 15 | } 16 | 17 | @Override 18 | protected boolean keep() { 19 | int col = _input.colNameToIndex(_colName); 20 | if (_next.getValue(col).equals(_match)) { 21 | return true; 22 | } else { 23 | return false; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Labs/lab5/GreaterThanFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * TableFilter to filter for entries greater than a given string. 3 | * 4 | * @author Matthew Owen 5 | */ 6 | public class GreaterThanFilter extends TableFilter { 7 | Table _input; 8 | String _colName, _ref; 9 | 10 | public GreaterThanFilter(Table input, String colName, String ref) { 11 | super(input); 12 | _input = input; 13 | _colName = colName; 14 | _ref = ref; 15 | } 16 | 17 | @Override 18 | protected boolean keep() { 19 | int col = _input.colNameToIndex(_colName); 20 | if (_next.getValue(col).length() > _ref.length()) { 21 | return true; 22 | } else { 23 | return false; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Labs/lab5/IdentityFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * TableFilter which does not filter out any rows. 3 | * 4 | * @author Matthew Owen 5 | */ 6 | public class IdentityFilter extends TableFilter { 7 | 8 | public IdentityFilter(Table input) { 9 | super(input); 10 | } 11 | 12 | @Override 13 | protected boolean keep() { 14 | return true; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Labs/lab5/SubstringFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * TableFilter to filter for containing substrings. 3 | * 4 | * @author Matthew Owen 5 | */ 6 | public class SubstringFilter extends TableFilter { 7 | Table _input; 8 | String _colName, _subStr; 9 | 10 | public SubstringFilter(Table input, String colName, String subStr) { 11 | super(input); 12 | _input = input; 13 | _colName = colName; 14 | _subStr = subStr; 15 | } 16 | 17 | @Override 18 | protected boolean keep() { 19 | int col = _input.colNameToIndex(_colName); 20 | if (_next.getValue(col).contains(_subStr)) { 21 | return true; 22 | } 23 | return false; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Labs/lab5/lab5.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/.idea/libraries/gjdb.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/ColumnMatchFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Labs/lab5/out/production/lab5/ColumnMatchFilter.class -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/EqualityFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Labs/lab5/out/production/lab5/EqualityFilter.class -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/GreaterThanFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Labs/lab5/out/production/lab5/GreaterThanFilter.class -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/IdentityFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Labs/lab5/out/production/lab5/IdentityFilter.class -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/SubstringFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Labs/lab5/out/production/lab5/SubstringFilter.class -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/Table$JoinIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Labs/lab5/out/production/lab5/Table$JoinIterator.class -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/Table$TableException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Labs/lab5/out/production/lab5/Table$TableException.class -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/Table$TableRow.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Labs/lab5/out/production/lab5/Table$TableRow.class -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/Table.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Labs/lab5/out/production/lab5/Table.class -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/TableFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Labs/lab5/out/production/lab5/TableFilter.class -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/TestTable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Labs/lab5/out/production/lab5/TestTable.class -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/lab5.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/partner.txt: -------------------------------------------------------------------------------- 1 | Lab Partner's name: 2 | Lab Partner's SID: 3 | Lab Partner's email: -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/sample_db/bad_rows.db: -------------------------------------------------------------------------------- 1 | first_name,last_name,fav_data_structure 2 | Itai,Smith,Red Black Tree 3 | Matt,Owen 4 | Michelle,Hwang,HashMap 5 | Sean,Dooher,Merkle Hash Tree 6 | Omar,Khan,LinkedList 7 | -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/sample_db/joined.db: -------------------------------------------------------------------------------- 1 | t1.first_name,t1.last_name,t1.fav_data_structure,t2.first_name,t2.last_name,t2.fav_color 2 | Itai,Smith,Red Black Tree,Matt,Owen,Yellow 3 | Itai,Smith,Red Black Tree,Michelle,Hwang,Black 4 | Itai,Smith,Red Black Tree,Itai,Smith,Blue 5 | Itai,Smith,Red Black Tree,Tina,Zhao,Salmon 6 | Itai,Smith,Red Black Tree,Carlo,Cruz-Albrecht,Blue 7 | Itai,Smith,Red Black Tree,Shivani,Kishnani,Emerald 8 | Matt,Owen,kd-tree,Matt,Owen,Yellow 9 | Matt,Owen,kd-tree,Michelle,Hwang,Black 10 | Matt,Owen,kd-tree,Itai,Smith,Blue 11 | Matt,Owen,kd-tree,Tina,Zhao,Salmon 12 | Matt,Owen,kd-tree,Carlo,Cruz-Albrecht,Blue 13 | Matt,Owen,kd-tree,Shivani,Kishnani,Emerald 14 | Michelle,Hwang,HashMap,Matt,Owen,Yellow 15 | Michelle,Hwang,HashMap,Michelle,Hwang,Black 16 | Michelle,Hwang,HashMap,Itai,Smith,Blue 17 | Michelle,Hwang,HashMap,Tina,Zhao,Salmon 18 | Michelle,Hwang,HashMap,Carlo,Cruz-Albrecht,Blue 19 | Michelle,Hwang,HashMap,Shivani,Kishnani,Emerald 20 | Sean,Dooher,Merkle Hash Tree,Matt,Owen,Yellow 21 | Sean,Dooher,Merkle Hash Tree,Michelle,Hwang,Black 22 | Sean,Dooher,Merkle Hash Tree,Itai,Smith,Blue 23 | Sean,Dooher,Merkle Hash Tree,Tina,Zhao,Salmon 24 | Sean,Dooher,Merkle Hash Tree,Carlo,Cruz-Albrecht,Blue 25 | Sean,Dooher,Merkle Hash Tree,Shivani,Kishnani,Emerald 26 | Omar,Khan,LinkedList,Matt,Owen,Yellow 27 | Omar,Khan,LinkedList,Michelle,Hwang,Black 28 | Omar,Khan,LinkedList,Itai,Smith,Blue 29 | Omar,Khan,LinkedList,Tina,Zhao,Salmon 30 | Omar,Khan,LinkedList,Carlo,Cruz-Albrecht,Blue 31 | Omar,Khan,LinkedList,Shivani,Kishnani,Emerald -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/sample_db/missing_vals.db: -------------------------------------------------------------------------------- 1 | first_name,last_name,fav_data_structure 2 | Itai,, 3 | Matt,Owen,kd-tree 4 | Michelle,Hwang, 5 | ,Dooher,Merkle Hash Tree 6 | Omar,Khan,LinkedList -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/sample_db/ta_color.db: -------------------------------------------------------------------------------- 1 | first_name,last_name,fav_color 2 | Matt,Owen,Yellow 3 | Michelle,Hwang,Black 4 | Itai,Smith,Blue 5 | Tina,Zhao,Salmon 6 | Carlo,Cruz-Albrecht,Blue 7 | Shivani,Kishnani,Emerald -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/sample_db/ta_data_struct.db: -------------------------------------------------------------------------------- 1 | first_name,last_name,fav_data_structure 2 | Itai,Smith,Red Black Tree 3 | Matt,Owen,kd-tree 4 | Michelle,Hwang,HashMap 5 | Sean,Dooher,Merkle Hash Tree 6 | Omar,Khan,LinkedList 7 | -------------------------------------------------------------------------------- /Labs/lab5/out/production/lab5/sample_db/white_space.db: -------------------------------------------------------------------------------- 1 | first_name , last_name, fav_data_structure 2 | Itai ,Smith, Red Black Tree 3 | Matt ,Owen , kd-tree 4 | Michelle ,Hwang ,HashMap 5 | Sean,Dooher, Merkle Hash Tree 6 | Omar,Khan,LinkedList -------------------------------------------------------------------------------- /Labs/lab5/partner.txt: -------------------------------------------------------------------------------- 1 | Lab Partner's name: 2 | Lab Partner's SID: 3 | Lab Partner's email: -------------------------------------------------------------------------------- /Labs/lab5/sample_db/bad_rows.db: -------------------------------------------------------------------------------- 1 | first_name,last_name,fav_data_structure 2 | Itai,Smith,Red Black Tree 3 | Matt,Owen 4 | Michelle,Hwang,HashMap 5 | Sean,Dooher,Merkle Hash Tree 6 | Omar,Khan,LinkedList 7 | -------------------------------------------------------------------------------- /Labs/lab5/sample_db/joined.db: -------------------------------------------------------------------------------- 1 | t1.first_name,t1.last_name,t1.fav_data_structure,t2.first_name,t2.last_name,t2.fav_color 2 | Itai,Smith,Red Black Tree,Matt,Owen,Yellow 3 | Itai,Smith,Red Black Tree,Michelle,Hwang,Black 4 | Itai,Smith,Red Black Tree,Itai,Smith,Blue 5 | Itai,Smith,Red Black Tree,Tina,Zhao,Salmon 6 | Itai,Smith,Red Black Tree,Carlo,Cruz-Albrecht,Blue 7 | Itai,Smith,Red Black Tree,Shivani,Kishnani,Emerald 8 | Matt,Owen,kd-tree,Matt,Owen,Yellow 9 | Matt,Owen,kd-tree,Michelle,Hwang,Black 10 | Matt,Owen,kd-tree,Itai,Smith,Blue 11 | Matt,Owen,kd-tree,Tina,Zhao,Salmon 12 | Matt,Owen,kd-tree,Carlo,Cruz-Albrecht,Blue 13 | Matt,Owen,kd-tree,Shivani,Kishnani,Emerald 14 | Michelle,Hwang,HashMap,Matt,Owen,Yellow 15 | Michelle,Hwang,HashMap,Michelle,Hwang,Black 16 | Michelle,Hwang,HashMap,Itai,Smith,Blue 17 | Michelle,Hwang,HashMap,Tina,Zhao,Salmon 18 | Michelle,Hwang,HashMap,Carlo,Cruz-Albrecht,Blue 19 | Michelle,Hwang,HashMap,Shivani,Kishnani,Emerald 20 | Sean,Dooher,Merkle Hash Tree,Matt,Owen,Yellow 21 | Sean,Dooher,Merkle Hash Tree,Michelle,Hwang,Black 22 | Sean,Dooher,Merkle Hash Tree,Itai,Smith,Blue 23 | Sean,Dooher,Merkle Hash Tree,Tina,Zhao,Salmon 24 | Sean,Dooher,Merkle Hash Tree,Carlo,Cruz-Albrecht,Blue 25 | Sean,Dooher,Merkle Hash Tree,Shivani,Kishnani,Emerald 26 | Omar,Khan,LinkedList,Matt,Owen,Yellow 27 | Omar,Khan,LinkedList,Michelle,Hwang,Black 28 | Omar,Khan,LinkedList,Itai,Smith,Blue 29 | Omar,Khan,LinkedList,Tina,Zhao,Salmon 30 | Omar,Khan,LinkedList,Carlo,Cruz-Albrecht,Blue 31 | Omar,Khan,LinkedList,Shivani,Kishnani,Emerald -------------------------------------------------------------------------------- /Labs/lab5/sample_db/missing_vals.db: -------------------------------------------------------------------------------- 1 | first_name,last_name,fav_data_structure 2 | Itai,, 3 | Matt,Owen,kd-tree 4 | Michelle,Hwang, 5 | ,Dooher,Merkle Hash Tree 6 | Omar,Khan,LinkedList -------------------------------------------------------------------------------- /Labs/lab5/sample_db/ta_color.db: -------------------------------------------------------------------------------- 1 | first_name,last_name,fav_color 2 | Matt,Owen,Yellow 3 | Michelle,Hwang,Black 4 | Itai,Smith,Blue 5 | Tina,Zhao,Salmon 6 | Carlo,Cruz-Albrecht,Blue 7 | Shivani,Kishnani,Emerald -------------------------------------------------------------------------------- /Labs/lab5/sample_db/ta_data_struct.db: -------------------------------------------------------------------------------- 1 | first_name,last_name,fav_data_structure 2 | Itai,Smith,Red Black Tree 3 | Matt,Owen,kd-tree 4 | Michelle,Hwang,HashMap 5 | Sean,Dooher,Merkle Hash Tree 6 | Omar,Khan,LinkedList 7 | -------------------------------------------------------------------------------- /Labs/lab5/sample_db/white_space.db: -------------------------------------------------------------------------------- 1 | first_name , last_name, fav_data_structure 2 | Itai ,Smith, Red Black Tree 3 | Matt ,Owen , kd-tree 4 | Michelle ,Hwang ,HashMap 5 | Sean,Dooher, Merkle Hash Tree 6 | Omar,Khan,LinkedList -------------------------------------------------------------------------------- /Labs/lab6/enigma/Alphabet.java: -------------------------------------------------------------------------------- 1 | package enigma; 2 | 3 | /** 4 | * An alphabet of encodable characters. Provides a mapping from characters 5 | * to and from indices into the alphabet. For lab6, this is made an abstract 6 | * class so we don't give you the solutions. In proj1, this is a concrete 7 | * class you will need to implement. 8 | * 9 | * @author Michelle Hwang 10 | */ 11 | abstract class Alphabet { 12 | 13 | /** 14 | * Constructor1 should be in the format: Alphabet(String chars) 15 | * A new alphabet containing CHARS. Character number #k in the alphabet 16 | * has index k (numbering from 0). No character may be duplicated. 17 | */ 18 | 19 | /** 20 | * Constructor2 should be in the format: Alphabet() 21 | * A default alphabet of all upper-case characters, i.e. ABCD...Z. 22 | */ 23 | 24 | /** 25 | * Returns the size of the alphabet. 26 | */ 27 | abstract int size(); 28 | 29 | /** 30 | * Returns true if ch is in this alphabet. 31 | * @param ch the character to test 32 | */ 33 | abstract boolean contains(char ch); 34 | 35 | /** 36 | * Returns character number INDEX in the alphabet, where 37 | * 0 <= INDEX < size(). 38 | */ 39 | abstract char toChar(int index); 40 | 41 | /** 42 | * Returns the index of character ch, which must be in 43 | * the alphabet. This is the inverse of toChar(). 44 | * @param ch the character to convert to its index in the Alphabet 45 | */ 46 | abstract int toInt(char ch); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Labs/lab6/enigma/EnigmaException.java: -------------------------------------------------------------------------------- 1 | package enigma; 2 | 3 | /** 4 | * A general-purpose error-reporting exception for this package. All 5 | * anticipated user or I/O errors should be reported through this 6 | * exception, with the message being the error message to be printed. 7 | * 8 | * @author P. N. Hilfinger 9 | */ 10 | class EnigmaException extends RuntimeException { 11 | 12 | /** 13 | * An exception whose getMessage() value is MSG. 14 | */ 15 | EnigmaException(String msg) { 16 | super(msg); 17 | } 18 | 19 | /** 20 | * A utility method that returns a new exception with a message 21 | * formed from MSGFORMAT and ARGUMENTS, interpreted as for the 22 | * String.format method or the standard printf methods. 23 | *

24 | * The use is thus 'throw error(...)', which tells the compiler that 25 | * execution will terminate at that point, and avoid insistance on 26 | * an explicit return in a value-returning function.) 27 | */ 28 | static EnigmaException error(String msgFormat, Object... arguments) { 29 | return new EnigmaException(String.format(msgFormat, arguments)); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Labs/lab6/enigma/Permutation.java: -------------------------------------------------------------------------------- 1 | package enigma; 2 | 3 | /** 4 | * Represents a permutation of a range of integers starting at 0 corresponding 5 | * to the characters of an alphabet. For lab6, this is made an abstract 6 | * class so we don't give you the solutions. In proj1, this is a concrete 7 | * class you will need to implement. 8 | * @author Michelle Hwang 9 | */ 10 | abstract class Permutation { 11 | 12 | /** 13 | * Constructor should be in the format: 14 | * Permutation(String cycles, Alphabet alphabet) 15 | * Set this Permutation to that specified by CYCLES, a string in the 16 | * form "(cccc) (cc) ..." where the c's are characters in ALPHABET, which 17 | * is interpreted as a permutation in cycle notation. Characters in the 18 | * alphabet that are not included in any cycle map to themselves. 19 | * Whitespace is ignored. 20 | * */ 21 | 22 | /** 23 | * Returns the size of the alphabet I permute. 24 | */ 25 | abstract int size(); 26 | 27 | /** 28 | * Return the result of applying this permutation to P modulo the 29 | * alphabet size. 30 | */ 31 | abstract int permute(int p); 32 | 33 | /** 34 | * Return the result of applying the inverse of this permutation 35 | * to C modulo the alphabet size. 36 | */ 37 | abstract int invert(int c); 38 | 39 | /** 40 | * Return the result of applying this permutation to the index of P 41 | * in ALPHABET, and converting the result to a character of ALPHABET. 42 | */ 43 | abstract char permute(char p); 44 | 45 | /** 46 | * Return the result of applying the inverse of this permutation to C. 47 | */ 48 | abstract char invert(char c); 49 | 50 | /** 51 | * Return the alphabet used to initialize this Permutation. 52 | */ 53 | abstract Alphabet alphabet(); 54 | 55 | /** 56 | * Return true iff this permutation is a derangement (i.e., a 57 | * permutation for which no value maps to itself). 58 | */ 59 | abstract boolean derangement(); 60 | } 61 | -------------------------------------------------------------------------------- /Labs/lab6/partner.txt: -------------------------------------------------------------------------------- 1 | Lab Partner's name: 2 | Lab Partner's SID: 3 | Lab Partner's email: -------------------------------------------------------------------------------- /Labs/lab6/testing/correct/default.conf: -------------------------------------------------------------------------------- 1 | ABCDEFGHIJKLMNOPQRSTUVWXYZ 2 | 5 3 3 | I MQ (AELTPHQXRU) (BKNW) (CMOY) (DFG) (IV) (JZ) (S) 4 | II ME (FIXVYOMW) (CDKLHUP) (ESZ) (BJ) (GR) (NT) (A) (Q) 5 | III MV (ABDHPEJT) (CFLVMZOYQIRWUKXSG) (N) 6 | IV MJ (AEPLIYWCOXMRFZBSTGJQNH) (DV) (KU) 7 | V MZ (AVOLDRWFIUQ)(BZKSMNHYC) (EGTJPX) 8 | VI MZM (AJQDVLEOZWIYTS) (CGMNHFUX) (BPRK) 9 | VII MZM (ANOUPFRIMBZTLWKSVEGCJYDHXQ) 10 | VIII MZM (AFLSETWUNDHOZVICQ) (BKJ) (GXY) (MPR) 11 | Beta N (ALBEVFCYODJWUGNMQTZSKPR) (HIX) 12 | Gamma N (AFNIRLBSQWVXGUZDKMTPCOYJHE) 13 | B R (AE) (BN) (CK) (DQ) (FU) (GY) (HW) (IJ) (LO) (MP) 14 | (RX) (SZ) (TV) 15 | C R (AR) (BD) (CO) (EJ) (FN) (GT) (HK) (IV) (LM) (PW) 16 | (QZ) (SX) (UY) 17 | -------------------------------------------------------------------------------- /Labs/lab6/testing/correct/trivial.in: -------------------------------------------------------------------------------- 1 | * B Beta I II III AAAA 2 | HELLO WORLD 3 | * B Beta I II III AAAA 4 | ILBDA AMTAZ 5 | -------------------------------------------------------------------------------- /Labs/lab6/testing/correct/trivial.out: -------------------------------------------------------------------------------- 1 | ILBDA AMTAZ 2 | HELLO WORLD 3 | -------------------------------------------------------------------------------- /Labs/lab6/testing/correct/trivial1.in: -------------------------------------------------------------------------------- 1 | * B Beta I II III AAAA (AQ) (EP) 2 | HELLO WORLD 3 | * B Beta I II III AAAA (AQ) (EP) 4 | IHBDQ QMTQZ 5 | -------------------------------------------------------------------------------- /Labs/lab6/testing/correct/trivial1.out: -------------------------------------------------------------------------------- 1 | IHBDQ QMTQZ 2 | HELLO WORLD 3 | -------------------------------------------------------------------------------- /Labs/lab8/map/LinkedListMap.java: -------------------------------------------------------------------------------- 1 | package map; 2 | 3 | public class LinkedListMap, V> implements SimpleMap { 4 | 5 | @Override 6 | public void put(K key, V value) { 7 | if (_head != null) { 8 | MapNode ptr = _head; 9 | while (ptr._next != null) { 10 | if (ptr._key.equals(key)) { 11 | ptr._value = value; 12 | return; 13 | } 14 | ptr = ptr._next; 15 | } 16 | } 17 | _head = new MapNode(key, value, _head); 18 | } 19 | 20 | @Override 21 | public V get(K key) { 22 | MapNode ptr = _head; 23 | while (ptr != null) { 24 | if (ptr._key.equals(key)) { 25 | return ptr._value; 26 | } 27 | ptr = ptr._next; 28 | } 29 | return null; 30 | } 31 | 32 | @Override 33 | public void clear() { 34 | _head = null; 35 | } 36 | 37 | private MapNode _head; 38 | 39 | private class MapNode { 40 | 41 | private MapNode(K key, V value, MapNode next) { 42 | _key = key; 43 | _value = value; 44 | _next = next; 45 | } 46 | 47 | public String toString() { 48 | return "(" + _key.toString() + " -> " + _value.toString() + ")"; 49 | } 50 | 51 | private MapNode _next; 52 | private K _key; 53 | private V _value; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Labs/lab8/map/SimpleMap.java: -------------------------------------------------------------------------------- 1 | package map; 2 | 3 | public interface SimpleMap, V> { 4 | 5 | /** 6 | * Inserts the key-value mapping represented by key and value to the map. 7 | * If the map already contains the key, then the corresponding value 8 | * will be updated. 9 | */ 10 | void put(K key, V value); 11 | 12 | /** 13 | * Returns the value associated with the given key or null if the key does 14 | * not exist. 15 | * 16 | */ 17 | V get(K key); 18 | 19 | /** 20 | * Removes all key-value pair mappings from the given map. 21 | */ 22 | void clear(); 23 | } 24 | -------------------------------------------------------------------------------- /Labs/lab8/partner.txt: -------------------------------------------------------------------------------- 1 | Lab Partner's name: Brian Faun 2 | Lab Partner's SID: 3034585737 3 | Lab Partner's email: brianfaun@berkeley.edu -------------------------------------------------------------------------------- /Labs/lab8/timing/MySortTester.java: -------------------------------------------------------------------------------- 1 | package timing; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | public class MySortTester { 8 | public static void testSorter(Sorter expected, Sorter other) { 9 | for(int i = 0; i < 10; i++) { 10 | int[] a1 = other.getRandomArray(100); 11 | int[] a2 = new int[a1.length]; 12 | System.arraycopy(a1,0,a2, 0, a1.length); 13 | expected.sort(a1); 14 | other.sort(a2); 15 | assertArrayEquals(a1, a2); 16 | } 17 | } 18 | 19 | @Test 20 | public void testBubbleSort() { 21 | testSorter(new JavaSorter(), new BubbleSorter()); 22 | } 23 | 24 | @Test 25 | public void testWipingBubbleSort() { 26 | testSorter(new JavaSorter(), new WipingBubbleSorter()); 27 | } 28 | 29 | @Test 30 | public void testInsertionSort() { 31 | testSorter(new JavaSorter(), new InsertionSorter()); 32 | } 33 | 34 | @Test 35 | public void testCountingSort() { 36 | testSorter(new JavaSorter(), new CountingSorter()); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Labs/lab8/timing/Timer.java: -------------------------------------------------------------------------------- 1 | package timing; 2 | /* timing.Timer.java implements a simple stopwatch/timer type class based 3 | * on Java wall-clock time. 4 | * 5 | * RUNNING() == true <==> start() was called with no corresponding 6 | * call to stop() 7 | * 8 | * All times are given in units of msec. 9 | */ 10 | 11 | public class Timer { 12 | 13 | /* Initializes timing.Timer to 0 msec */ 14 | public Timer() { 15 | reset(); 16 | } 17 | 18 | /* Starts the timer. Accumulates time across multiple calls to start. */ 19 | public void start() { 20 | running = true; 21 | tStart = System.nanoTime(); 22 | tFinish = tStart; 23 | } 24 | 25 | /* Stops the timer. 26 | * Returns the time elapsed since the last matching call to start(), or 27 | * 0 if no such matching call was made. */ 28 | public double stop() { 29 | tFinish = System.nanoTime(); 30 | if (running) { 31 | running = false; 32 | double diff = tFinish - tStart; 33 | tAccum += diff; 34 | return diff/1000; // Return in microseconds!! 35 | } 36 | return 0; 37 | } 38 | 39 | /* 40 | * If RUNNING() ==> Returns the time since last call to start() 41 | * If !RUNNING() ==> Returns total elapsed time 42 | */ 43 | public double elapsed() { 44 | if( running ) 45 | return System.nanoTime() - tStart; 46 | 47 | return tAccum; 48 | } 49 | 50 | /* Stops timing if currently RUNNING() and resets the accumulated 51 | * time to 0. */ 52 | public void reset() { 53 | running = false; 54 | tStart = tFinish = 0; 55 | tAccum = 0; 56 | } 57 | 58 | private boolean running; 59 | private double tStart; 60 | private double tFinish; 61 | private double tAccum; // total time 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Labs/lab9/partner.txt: -------------------------------------------------------------------------------- 1 | Lab Partner's name: Matt Chorlian 2 | Lab Partner's SID: 3033045472 3 | Lab Partner's email: mattchorlian@berkeley.edu -------------------------------------------------------------------------------- /Projects/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Projects/.DS_Store -------------------------------------------------------------------------------- /Projects/proj0/Makefile: -------------------------------------------------------------------------------- 1 | # This makefile is defined to give you the following targets: 2 | # 3 | # default: The default target: Compiles the program in package galaxy. 4 | # style: Run our style checker on the project source files. Requires that 5 | # the source files compile. 6 | # check: Compiles the db61b package, if needed, and then performs the 7 | # tests described in testing/Makefile. 8 | # clean: Remove regeneratable files (such as .class files) produced by 9 | # other targets and Emacs backup files. 10 | # 11 | # In other words, type 'make' to compile everything; 'make check' to 12 | # compile and test everything, and 'make clean' to clean things up. 13 | # 14 | # You can use this file without understanding most of it, of course, but 15 | # I strongly recommend that you try to figure it out, and where you cannot, 16 | # that you ask questions. The Lab Reader contains documentation. 17 | 18 | # Name of package containing main procedure 19 | PACKAGE = signpost 20 | 21 | PYTHON = python3 22 | 23 | STYLEPROG = style61b 24 | 25 | # Targets that don't correspond to files, but are to be treated as commands. 26 | .PHONY: default check clean style unit integration 27 | 28 | default: 29 | "$(MAKE)" -C $(PACKAGE) default 30 | 31 | check: default 32 | code=0; \ 33 | "$(MAKE)" -C $(PACKAGE) PYTHON=$(PYTHON) unit || code=1; \ 34 | "$(MAKE)" -C testing PYTHON=$(PYTHON) check || code=1; \ 35 | exit $$code 36 | 37 | unit: default 38 | "$(MAKE)" -C $(PACKAGE) PYTHON=$(PYTHON) unit 39 | 40 | integration: default 41 | "$(MAKE)" -C testing PYTHON=$(PYTHON) check 42 | 43 | style: 44 | "$(MAKE)" -C $(PACKAGE) STYLEPROG=$(STYLEPROG) style 45 | 46 | # 'make clean' will clean up stuff you can reconstruct. 47 | clean: 48 | $(RM) *~ 49 | $(RM) bin/$(PACKAGE).jar 50 | "$(MAKE)" -C $(PACKAGE) clean 51 | "$(MAKE)" -C testing clean 52 | -------------------------------------------------------------------------------- /Projects/proj0/signpost/About.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

6 | Signpost CS61B, Version 1.0. 7 |

8 | 9 |

10 | This is a reimplementation of the Signpost puzzle from Simon Tatham's Portable 11 | Puzzle Collection. 12 |

13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Projects/proj0/signpost/CommandSource.java: -------------------------------------------------------------------------------- 1 | package signpost; 2 | 3 | /** Describes a source of input commands. The possible text commands are as 4 | * follows (parts of a command are separated by whitespace): 5 | * - TYPE w h [FREE]: Replace the current board with one that is w cells 6 | * wide and h cells high. Then start a new puzzle, allowing 7 | * free ends iff FREE is present. Requires that w, h >= 3 and 8 | * that they are properly formed numerals. 9 | * - NEW: Start a new puzzle with current parameters. 10 | * - RESTART: Clear all work on the current puzzle, returning to its initial 11 | * state. 12 | * - CONN X0 Y0 X1 Y1: 13 | * Connect square (X0, Y0) to (X1, Y1). 14 | * - BRK X0 Y0: 15 | * Remove any connections to and from (X0, Y0). 16 | * - UNDO: Go back one move. 17 | * - REDO: Go forward one previously undone move. 18 | * - SEED s: Set a new random seed. 19 | * - SOLVE: Show sequence numbers of a solution. 20 | * - QUIT: Exit the program. 21 | * @author P. N. Hilfinger 22 | */ 23 | interface CommandSource { 24 | 25 | /** Returns one command string, trimmed of preceding and following 26 | * whitespace and converted to upper case. */ 27 | String getCommand(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Projects/proj0/signpost/GUISource.java: -------------------------------------------------------------------------------- 1 | package signpost; 2 | 3 | /** A type of InputSource that receives commands from a GUI. 4 | * @author P. N. Hilfinger 5 | */ 6 | class GUISource implements CommandSource { 7 | 8 | /** Provides input from SOURCE. */ 9 | GUISource(GUI source) { 10 | _source = source; 11 | } 12 | 13 | @Override 14 | public String getCommand() { 15 | return _source.readCommand().toUpperCase(); 16 | } 17 | 18 | /** Input source. */ 19 | private GUI _source; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Projects/proj0/signpost/Help.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

Signpost Puzzle

6 | 7 |

The goal of this puzzle is to link the board squares by 8 | queen moves so that each square appears once in the sequence of linked 9 | squares and the positions of all the initially numbered squares are equal 10 | to their positions in the sequence. The term "queen move" here refers to 11 | the queen in chess, which can move any number of squares horizontally, 12 | vertically, or diagonally. 13 |

14 | 15 |

To link two squares, press and hold mouse button 1 on the first square, 16 | drag to the second square, and release. To break a link between two squares, 17 | press on the first square, move the mouse off the board, and release. 18 |

19 | 20 |

21 | By default, the upper-left square is initially numbered 1 and the lower-right 22 | square contains the last number (the total number of squares on the board). 23 | The "Type" menu allows you to change the dimensions of the board and to change 24 | the default so that the first and last squares in the sequence are "free ends", 25 | which can appear anywhere on the board. 26 |

27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Projects/proj0/signpost/PlaceTests.java: -------------------------------------------------------------------------------- 1 | package signpost; 2 | 3 | import org.junit.Test; 4 | import static org.junit.Assert.*; 5 | 6 | import java.util.Arrays; 7 | 8 | import static signpost.Place.PlaceList; 9 | import static signpost.Utils.*; 10 | 11 | /** Tests of the Place class. 12 | * @author Will Wang 13 | */ 14 | public class PlaceTests { 15 | 16 | private void checkSuccessors(Place[][] expected, PlaceList[] actual) { 17 | for (int dir = 8; dir >= 0; dir -= 1) { 18 | assertSetEquals(msg("Mismatch sucessors at direction %d", dir), 19 | Arrays.asList(expected[dir]), actual[dir]); 20 | } 21 | } 22 | 23 | @Test 24 | public void successorCellsTest() { 25 | PlaceList[][][] sucessors = Place.successorCells(WIDTH, HEIGHT); 26 | checkSuccessors(EXPECTED, sucessors[PL.x][PL.y]); 27 | } 28 | 29 | private static final int WIDTH = 4; 30 | private static final int HEIGHT = 4; 31 | 32 | private static final Place PL = Place.pl(1, 1); 33 | 34 | private static final Place[][] EXPECTED = { 35 | { Place.pl(0, 0), Place.pl(0, 1), Place.pl(0, 2), Place.pl(1, 2), 36 | Place.pl(1, 3), Place.pl(2, 2), Place.pl(3, 3), Place.pl(2, 1), 37 | Place.pl(3, 1), Place.pl(2, 0), Place.pl(1, 0)}, 38 | { Place.pl(2, 2), Place.pl(3, 3) }, 39 | { Place.pl(2, 1), Place.pl(3, 1) }, 40 | { Place.pl(2, 0) }, 41 | { Place.pl(1, 0) }, 42 | { Place.pl(0, 0) }, 43 | { Place.pl(0, 1) }, 44 | { Place.pl(0, 2) }, 45 | { Place.pl(1, 2), Place.pl(1, 3) }, 46 | }; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Projects/proj0/signpost/PuzzleSource.java: -------------------------------------------------------------------------------- 1 | package signpost; 2 | 3 | /** Describes a source of Signpost puzzles. 4 | * @author P. N. Hilfinger 5 | */ 6 | interface PuzzleSource { 7 | 8 | /** Returns a WIDTH x HEIGHT Model containing a puzzle. Unless 9 | * ALLOWFREEENDS, the upper-left square will be numbered 1 and the 10 | * lower-right will be numbered with the number of cells in the model. */ 11 | Model getPuzzle(int width, int height, boolean allowFreeEnds); 12 | 13 | /** Reseed the random number generator with SEED. */ 14 | void setSeed(long seed); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Projects/proj0/signpost/UnitTests.java: -------------------------------------------------------------------------------- 1 | package signpost; 2 | 3 | import ucb.junit.textui; 4 | 5 | /** The suite of all JUnit tests for the signpost package. 6 | * @author P. N. Hilfinger 7 | */ 8 | public class UnitTests { 9 | 10 | /** Run the JUnit tests in this package. Add xxxTest.class entries to 11 | * the arguments of runClasses to run other JUnit tests. */ 12 | public static void main(String[] ignored) { 13 | System.exit(textui.runClasses(ModelTests.class, 14 | PuzzleGeneratorTests.class, PlaceTests.class)); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Projects/proj0/signpost/View.java: -------------------------------------------------------------------------------- 1 | package signpost; 2 | 3 | /** A view of a Signost model. 4 | * @author P. N. Hilfinger */ 5 | interface View { 6 | 7 | /** Update the current view according to MODEL. */ 8 | void update(Model model); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Projects/proj0/testing/test00.in: -------------------------------------------------------------------------------- 1 | # Simple connections. 2 | PUZZLE 3 | 4 4 4 | 1 8 13 5 5 | 11 12 7 6 6 | 3 4 2 15 7 | 10 9 14 16 8 | 1 16 9 | ENDPUZZLE 10 | CONN 1 3 1 2 11 | CONN 1 2 2 3 12 | CONN 0 3 2 1 13 | CONN 0 1 1 1 14 | CONN 2 1 0 1 15 | CONN 0 2 2 2 16 | CONN 2 2 1 3 17 | CONN 1 1 3 3 18 | CONN 3 3 3 2 19 | CONN 3 2 0 2 20 | QUIT 21 | -------------------------------------------------------------------------------- /Projects/proj0/testing/test01.in: -------------------------------------------------------------------------------- 1 | # Connect and disconnect. 2 | PUZZLE 3 | 4 4 4 | 1 8 13 5 5 | 11 12 7 6 6 | 3 4 2 15 7 | 10 9 14 16 8 | 1 16 9 | ENDPUZZLE 10 | CONN 0 3 1 2 11 | CONN 1 2 2 3 12 | CONN 1 3 1 1 13 | CONN 1 1 3 3 14 | CONN 3 3 3 2 15 | CONN 0 0 0 1 16 | BRK 1 2 17 | CONN 3 2 1 2 18 | BRK 3 2 19 | CONN 0 1 3 1 20 | CONN 3 1 3 0 21 | BRK 3 1 22 | CONN 1 0 0 0 23 | CONN 1 3 1 0 24 | BRK 1 3 25 | CONN 1 3 1 0 26 | CONN 0 1 1 1 27 | BRK 0 1 28 | QUIT 29 | -------------------------------------------------------------------------------- /Projects/proj0/testing/test02.in: -------------------------------------------------------------------------------- 1 | # Play complete game. 2 | PUZZLE 3 | 4 4 4 | 1 8 13 5 5 | 11 12 7 6 6 | 3 4 2 15 7 | 10 9 14 16 8 | 1 16 9 | ENDPUZZLE 10 | CONN 1 2 2 3 11 | CONN 3 1 3 0 12 | CONN 2 2 1 3 13 | CONN 1 0 0 0 14 | CONN 1 1 3 3 15 | CONN 2 0 3 1 16 | CONN 2 3 2 0 17 | CONN 0 3 2 1 18 | CONN 2 1 0 1 19 | CONN 0 1 1 1 20 | CONN 0 0 0 2 21 | CONN 3 3 3 2 22 | CONN 3 2 2 2 23 | CONN 1 3 1 0 24 | QUIT 25 | -------------------------------------------------------------------------------- /Projects/proj0/testing/test03.in: -------------------------------------------------------------------------------- 1 | # Test "solve" button. 2 | PUZZLE 3 | 4 4 4 | 1 8 13 5 5 | 11 12 7 6 6 | 3 4 2 15 7 | 10 9 14 16 8 | 1 16 9 | ENDPUZZLE 10 | SOLVE 11 | QUIT 12 | -------------------------------------------------------------------------------- /Projects/proj0/testing/test03.std: -------------------------------------------------------------------------------- 1 | B[ 4x4 2 | +------+------+------+------+ 3 | |+1 | | | | 4 | | o SE |.o S |.o S |.o S | 5 | +------+------+------+------+ 6 | | | | | | 7 | |.o E |.o NE |.o NW |.o W | 8 | +------+------+------+------+ 9 | | | | | | 10 | |.o E |.o NE |.o W |.o S | 11 | +------+------+------+------+ 12 | | | | |+16 | 13 | |.o N |.o W |.o NE |. * | 14 | +------+------+------+------+] 15 | B[ 4x4 (SOLVED) 16 | +------+------+------+------+ 17 | |+1 |8 |13 |5 | 18 | | SE | S | S | S | 19 | +------+------+------+------+ 20 | |11 |12 |7 |6 | 21 | | E | NE | NW | W | 22 | +------+------+------+------+ 23 | |3 |4 |2 |15 | 24 | | E | NE | W | S | 25 | +------+------+------+------+ 26 | |10 |9 |14 |+16 | 27 | | N | W | NE | * | 28 | +------+------+------+------+] 29 | -------------------------------------------------------------------------------- /Projects/proj0/testing/test05.in: -------------------------------------------------------------------------------- 1 | # Test size change. 2 | PUZZLE 3 | 4 4 4 | 1 8 13 5 5 | 11 12 7 6 6 | 3 4 2 15 7 | 10 9 14 16 8 | 1 16 9 | ENDPUZZLE 10 | TYPE 7 7 11 | PUZZLE 12 | 7 7 13 | 1 14 13 32 8 46 33 14 | 15 2 44 3 45 7 43 15 | 12 31 11 10 20 23 9 16 | 16 30 25 21 35 47 22 17 | 17 41 5 42 48 18 4 18 | 26 40 27 29 19 28 34 19 | 6 36 39 37 38 24 49 20 | 1 8 44 3 45 11 25 47 22 41 48 18 27 34 49 21 | ENDPUZZLE 22 | CONN 5 5 4 6 23 | CONN 4 6 6 4 24 | CONN 6 4 3 4 25 | CONN 2 3 0 1 26 | CONN 1 6 0 5 27 | QUIT 28 | -------------------------------------------------------------------------------- /Projects/proj0/testing/test06.in: -------------------------------------------------------------------------------- 1 | # Size change to non-square. 2 | PUZZLE 3 | 4 4 4 | 1 8 13 5 5 | 11 12 7 6 6 | 3 4 2 15 7 | 10 9 14 16 8 | 1 16 9 | ENDPUZZLE 10 | TYPE 4 7 11 | PUZZLE 12 | 4 7 13 | 1 26 11 17 14 | 15 12 10 9 15 | 3 19 4 18 16 | 16 25 6 7 17 | 14 27 5 8 18 | 23 13 22 24 19 | 2 20 21 28 20 | 1 26 11 3 27 2 20 28 21 | ENDPUZZLE 22 | TYPE 7 4 23 | PUZZLE 24 | 7 4 25 | 1 20 21 13 15 19 5 26 | 26 2 3 14 16 4 27 27 | 7 25 24 17 22 18 6 28 | 12 8 9 23 10 11 28 29 | 1 5 24 6 28 30 | ENDPUZZLE 31 | QUIT 32 | -------------------------------------------------------------------------------- /Projects/proj0/testing/test06.std: -------------------------------------------------------------------------------- 1 | B[ 4x4 2 | +------+------+------+------+ 3 | |+1 | | | | 4 | | o SE |.o S |.o S |.o S | 5 | +------+------+------+------+ 6 | | | | | | 7 | |.o E |.o NE |.o NW |.o W | 8 | +------+------+------+------+ 9 | | | | | | 10 | |.o E |.o NE |.o W |.o S | 11 | +------+------+------+------+ 12 | | | | |+16 | 13 | |.o N |.o W |.o NE |. * | 14 | +------+------+------+------+] 15 | B[ 4x7 16 | +------+------+------+------+ 17 | |+1 |+26 |+11 | | 18 | | o S |.o S |.o SW |.o S | 19 | +------+------+------+------+ 20 | | | | | | 21 | |.o S |.o S |.o N |.o W | 22 | +------+------+------+------+ 23 | |+3 | | | | 24 | |.o E |.o S |.o S |.o W | 25 | +------+------+------+------+ 26 | | | | | | 27 | |.o NE |.o N |.o E |.o S | 28 | +------+------+------+------+ 29 | | |+27 | | | 30 | |.o N |.o SE |.o N |.o N | 31 | +------+------+------+------+ 32 | | | | | | 33 | |.o E |.o NW |.o W |.o NW | 34 | +------+------+------+------+ 35 | |+2 |+20 | |+28 | 36 | |.o N |.o E |.o N |. * | 37 | +------+------+------+------+] 38 | B[ 7x4 39 | +------+------+------+------+------+------+------+ 40 | |+1 | | | | | |+5 | 41 | | o SE |.o E |.o SE |.o S |.o S |.o W |.o S | 42 | +------+------+------+------+------+------+------+ 43 | | | | | | | | | 44 | |.o E |.o E |.o E |.o NE |.o SW |.o NE |.o S | 45 | +------+------+------+------+------+------+------+ 46 | | | |+24 | | | |+6 | 47 | |.o SE |.o NW |.o W |.o E |.o SW |.o N |.o W | 48 | +------+------+------+------+------+------+------+ 49 | | | | | | | |+28 | 50 | |.o NE |.o E |.o E |.o NW |.o E |.o W |. * | 51 | +------+------+------+------+------+------+------+] 52 | -------------------------------------------------------------------------------- /Projects/proj0/testing/test07.in: -------------------------------------------------------------------------------- 1 | # Size change with free ends. 2 | PUZZLE 3 | 4 4 4 | 1 8 13 5 5 | 11 12 7 6 6 | 3 4 2 15 7 | 10 9 14 16 8 | 1 16 9 | ENDPUZZLE 10 | TYPE 5 5 free 11 | PUZZLE 12 | 5 5 13 | 17 10 16 18 5 14 | 2 15 8 7 1 15 | 3 11 4 9 22 16 | 19 6 20 14 13 17 | 24 25 21 12 23 18 | 5 2 1 6 25 19 | ENDPUZZLE 20 | QUIT 21 | -------------------------------------------------------------------------------- /Projects/proj0/testing/test07.std: -------------------------------------------------------------------------------- 1 | B[ 4x4 2 | +------+------+------+------+ 3 | |+1 | | | | 4 | | o SE |.o S |.o S |.o S | 5 | +------+------+------+------+ 6 | | | | | | 7 | |.o E |.o NE |.o NW |.o W | 8 | +------+------+------+------+ 9 | | | | | | 10 | |.o E |.o NE |.o W |.o S | 11 | +------+------+------+------+ 12 | | | | |+16 | 13 | |.o N |.o W |.o NE |. * | 14 | +------+------+------+------+] 15 | B[ 5x5 16 | +------+------+------+------+------+ 17 | | | | | |+5 | 18 | |.o E |.o S |.o W |.o SW |.o SW | 19 | +------+------+------+------+------+ 20 | |+2 | | | |+1 | 21 | |.o S |.o NE |.o SE |.o W | o W | 22 | +------+------+------+------+------+ 23 | | | | | | | 24 | |.o E |.o SE |.o NE |.o NW |.o S | 25 | +------+------+------+------+------+ 26 | | |+6 | | | | 27 | |.o E |.o NE |.o S |.o NW |.o W | 28 | +------+------+------+------+------+ 29 | | |+25 | | | | 30 | |.o E |. * |.o NE |.o NE |.o W | 31 | +------+------+------+------+------+] 32 | -------------------------------------------------------------------------------- /Projects/proj0/testing/test08.in: -------------------------------------------------------------------------------- 1 | # Check that generated puzzles are OK. 2 | PUZZLE 3 | 4 4 4 | 1 8 13 5 5 | 11 12 7 6 6 | 3 4 2 15 7 | 10 9 14 16 8 | 1 16 9 | ENDPUZZLE 10 | 11 | seed 2948957 12 | TYPE 6 6 13 | AUTOPUZZLE 14 | SOLVE 15 | NEW 16 | AUTOPUZZLE 17 | SOLVE 18 | NEW 19 | AUTOPUZZLE 20 | SOLVE 21 | QUIT 22 | 23 | -------------------------------------------------------------------------------- /Projects/proj0/testing/test09.in: -------------------------------------------------------------------------------- 1 | # Check that generated puzzles are OK. 2 | PUZZLE 3 | 4 4 4 | 1 8 13 5 5 | 11 12 7 6 6 | 3 4 2 15 7 | 10 9 14 16 8 | 1 16 9 | ENDPUZZLE 10 | 11 | seed 29489578 12 | TYPE 6 6 free 13 | AUTOPUZZLE 14 | SOLVE 15 | NEW 16 | AUTOPUZZLE 17 | SOLVE 18 | NEW 19 | AUTOPUZZLE 20 | SOLVE 21 | QUIT 22 | 23 | -------------------------------------------------------------------------------- /Projects/proj1/Makefile: -------------------------------------------------------------------------------- 1 | # This makefile is defined to give you the following targets: 2 | # 3 | # default: The default target: Compiles the program in package db61b. 4 | # style: Run our style checker on the project source files. Requires that 5 | # the source files compile. 6 | # check: Compiles the db61b package, if needed, and then performs the 7 | # tests described in testing/Makefile. 8 | # clean: Remove regeneratable files (such as .class files) produced by 9 | # other targets and Emacs backup files. 10 | # 11 | # In other words, type 'make' to compile everything; 'make check' to 12 | # compile and test everything, and 'make clean' to clean things up. 13 | # 14 | # You can use this file without understanding most of it, of course, but 15 | # I strongly recommend that you try to figure it out, and where you cannot, 16 | # that you ask questions. The Lab Reader contains documentation. 17 | 18 | # Name of package containing main procedure 19 | PACKAGE = enigma 20 | 21 | STYLEPROG = style61b 22 | 23 | # Targets that don't correspond to files, but are to be treated as commands. 24 | .PHONY: default check clean style 25 | 26 | default: 27 | "$(MAKE)" -C $(PACKAGE) default 28 | 29 | check: unit integration 30 | 31 | unit: 32 | "$(MAKE)" -C $(PACKAGE) unit 33 | 34 | integration: 35 | "$(MAKE)" -C $(PACKAGE) integration 36 | 37 | style: 38 | "$(MAKE)" -C $(PACKAGE) STYLEPROG=$(STYLEPROG) style 39 | 40 | # 'make clean' will clean up stuff you can reconstruct. 41 | clean: 42 | $(RM) *~ 43 | "$(MAKE)" -C $(PACKAGE) clean 44 | "$(MAKE)" -C testing clean 45 | 46 | 47 | -------------------------------------------------------------------------------- /Projects/proj1/enigma/Alphabet.java: -------------------------------------------------------------------------------- 1 | package enigma; 2 | 3 | /** An alphabet of encodable characters. Provides a mapping from characters 4 | * to and from indices into the alphabet. 5 | * @author Brian Faun 6 | */ 7 | class Alphabet { 8 | /** String array representing the mapping of characters. */ 9 | private char[] alpha; 10 | 11 | /** A new alphabet containing CHARS. Character number #k has index 12 | * K (numbering from 0). No character may be duplicated. */ 13 | Alphabet(String chars) { 14 | alpha = new char[chars.length()]; 15 | for (int i = 0; i < chars.length(); i++) { 16 | alpha[i] = chars.charAt(i); 17 | } 18 | } 19 | 20 | /** A default alphabet of all upper-case characters. */ 21 | Alphabet() { 22 | this("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 23 | } 24 | 25 | /** Returns the size of the alphabet. */ 26 | int size() { 27 | return alpha.length; 28 | } 29 | 30 | /** Returns true if CH is in this alphabet. */ 31 | boolean contains(char ch) { 32 | for (int i = 0; i < alpha.length; i++) { 33 | if (alpha[i] == ch) { 34 | return true; 35 | } 36 | } 37 | return false; 38 | } 39 | 40 | /** Returns character number INDEX in the alphabet, where 41 | * 0 <= INDEX < size(). */ 42 | char toChar(int index) { 43 | return alpha[index]; 44 | } 45 | 46 | /** Returns the index of character CH which must be in 47 | * the alphabet. This is the inverse of toChar(). */ 48 | int toInt(char ch) { 49 | for (int i = 0; i < alpha.length; i++) { 50 | if (alpha[i] == ch) { 51 | return i; 52 | } 53 | } 54 | return -1; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Projects/proj1/enigma/EnigmaException.java: -------------------------------------------------------------------------------- 1 | package enigma; 2 | 3 | /** A general-purpose error-reporting exception for this package. All 4 | * anticipated user or I/O errors should be reported through this 5 | * exception, with the message being the error message to be printed. 6 | * @author P. N. Hilfinger 7 | */ 8 | class EnigmaException extends RuntimeException { 9 | 10 | /** An exception whose getMessage() value is MSG. */ 11 | EnigmaException(String msg) { 12 | super(msg); 13 | } 14 | 15 | /** A utility method that returns a new exception with a message 16 | * formed from MSGFORMAT and ARGUMENTS, interpreted as for the 17 | * String.format method or the standard printf methods. 18 | * 19 | * The use is thus 'throw error(...)', which tells the compiler that 20 | * execution will terminate at that point, and avoid insistance on 21 | * an explicit return in a value-returning function.) */ 22 | static EnigmaException error(String msgFormat, Object... arguments) { 23 | return new EnigmaException(String.format(msgFormat, arguments)); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Projects/proj1/enigma/FixedRotor.java: -------------------------------------------------------------------------------- 1 | package enigma; 2 | 3 | import static enigma.EnigmaException.*; 4 | 5 | /** Class that represents a rotor that has no ratchet and does not advance. 6 | * @author Brian Faun 7 | */ 8 | class FixedRotor extends Rotor { 9 | 10 | /** A non-moving rotor named NAME whose permutation at the 0 setting 11 | * is given by PERM. */ 12 | FixedRotor(String name, Permutation perm) { 13 | super(name, perm); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Projects/proj1/enigma/MovingRotor.java: -------------------------------------------------------------------------------- 1 | package enigma; 2 | 3 | import static enigma.EnigmaException.*; 4 | 5 | /** Class that represents a rotating rotor in the enigma machine. 6 | * @author Brian Faun 7 | */ 8 | class MovingRotor extends Rotor { 9 | /** Position of notches. */ 10 | private String _notches; 11 | 12 | /** A rotor named NAME whose permutation in its default setting is 13 | * PERM, and whose notches are at the positions indicated in NOTCHES. 14 | * The Rotor is initially in its 0 setting (first character of its 15 | * alphabet). 16 | */ 17 | MovingRotor(String name, Permutation perm, String notches) { 18 | super(name, perm); 19 | _notches = notches; 20 | } 21 | 22 | @Override 23 | boolean rotates() { 24 | return true; 25 | } 26 | 27 | @Override 28 | boolean atNotch() { 29 | for (int i = 0; i < _notches.length(); i++) { 30 | char a = _notches.charAt(i); 31 | if (alphabet().toChar(setting()) == a) { 32 | return true; 33 | } 34 | } 35 | return false; 36 | } 37 | 38 | @Override 39 | void advance() { 40 | int next = permutation().wrap(setting() + 1); 41 | super.set(next); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Projects/proj1/enigma/Reflector.java: -------------------------------------------------------------------------------- 1 | package enigma; 2 | 3 | import static enigma.EnigmaException.*; 4 | 5 | /** Class that represents a reflector in the enigma. 6 | * @author Brian Faun 7 | */ 8 | class Reflector extends FixedRotor { 9 | 10 | /** A non-moving rotor named NAME whose permutation at the 0 setting 11 | * is PERM. */ 12 | Reflector(String name, Permutation perm) { 13 | super(name, perm); 14 | } 15 | 16 | @Override 17 | boolean reflecting() { 18 | return true; 19 | } 20 | 21 | @Override 22 | void set(int posn) { 23 | if (posn != 0) { 24 | throw error("reflector has only one position"); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Projects/proj1/enigma/UnitTest.java: -------------------------------------------------------------------------------- 1 | package enigma; 2 | 3 | import ucb.junit.textui; 4 | 5 | /** The suite of all JUnit tests for the enigma package. 6 | * @author 7 | */ 8 | public class UnitTest { 9 | 10 | /** Run the JUnit tests in this package. Add xxxTest.class entries to 11 | * the arguments of runClasses to run other JUnit tests. */ 12 | public static void main(String[] ignored) { 13 | System.exit(textui.runClasses(PermutationTest.class, 14 | MovingRotorTest.class)); 15 | } 16 | 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /Projects/proj1/testing/Makefile: -------------------------------------------------------------------------------- 1 | # Targets that don't correspond to files, but are to be treated as commands. 2 | .PHONY: default check clean output 3 | 4 | CPATH = "..:$(CLASSPATH):;..;$(CLASSPATH)" 5 | 6 | default: check 7 | 8 | check: 9 | @echo "Testing correct inputs..." 10 | @CLASSPATH=$(CPATH) bash test-correct correct/*.in 11 | @echo 12 | @echo "Testing erroneous inputs..." 13 | @CLASSPATH=$(CPATH) bash test-error error/*.in 14 | 15 | # 'make clean' will clean up stuff you can reconstruct. 16 | clean: 17 | $(RM) *~ OUT* ERR* 18 | -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/carroll1.in: -------------------------------------------------------------------------------- 1 | * B Beta III IV I AXLE 2 | FROM HIS SHOULDER HIAWATHA 3 | TOOK THE CAMERA OF ROSEWOOD 4 | MADE OF SLIDING FOLDING ROSEWOOD 5 | NEATLY PUT IT ALL TOGETHER 6 | IN ITS CASE IT LAY COMPACTLY 7 | FOLDED INTO NEARLY NOTHING 8 | BUT HE OPENED OUT THE HINGES 9 | PUSHED AND PULLED THE JOINTS 10 | AND HINGES 11 | TILL IT LOOKED ALL SQUARES 12 | AND OBLONGS 13 | LIKE A COMPLICATED FIGURE 14 | IN THE SECOND BOOK OF EUCLID -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/carroll1.out: -------------------------------------------------------------------------------- 1 | HYIHL BKOML IUYDC MPPSF SZW 2 | SQCNJ EXNUO JYRZE KTCNB DGU 3 | FLIIE GEPGR SJUJT CALGX SNCTM KUF 4 | WMFCK WIPRY SODJC VCFYQ LV 5 | QLMBY UQRIR XEPOV EUHFI RIF 6 | KCGVS FPBGP KDRFY RTVMW GFU 7 | NMXEH FHVPQ IDOAC GUIWG TNM 8 | KVCKC FDZIO PYEVX NTBXY AHAO 9 | BMQOP GTZX 10 | VXQXO LEDRW YCMMW AONVU KQ 11 | OUFAS RHACK 12 | KXOMZ TDALH UNVXK PXBHA VQ 13 | XVXEP UNUXT XYNIF FMDYJ VKH -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/carroll2.in: -------------------------------------------------------------------------------- 1 | * B Beta III IV I AXLE (BZ) (AR) (PD) (TQ) 2 | HOIHL ZKOML IUEPH MDESO KBJ 3 | CTCNP EXNIO JQRBE IQCNZ PGX 4 | FCYIE GEDGY SJUJQ CZLGX YNCQM KUX 5 | WMIBK WVDXY PIPJY VCFZT LP 6 | TLMRY UMAIA GESOV EUUZI MIF 7 | KCGFS LDZLD KPROY AQVFW GFU 8 | IMLEH FEVDT TPOMS GUIWG QNM 9 | AVCKC NOBCB DYEVF IQZXY RHLO 10 | EMNOD GQBX 11 | WXTXO XEPAW YQXMW RSNDF KT 12 | LUVRV AHRCK 13 | KXOMG QPRVH UNPGK PXZHR YT 14 | XVYED UNUXQ KMNIF FMPYJ VKC -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/carroll2.out: -------------------------------------------------------------------------------- 1 | FROMH ISSHO ULDER HIAWA THA 2 | TOOKT HECAM ERAOF ROSEW OOD 3 | MADEO FSLID INGFO LDING ROSEW OOD 4 | NEATL YPUTI TALLT OGETH ER 5 | INITS CASEI TLAYC OMPAC TLY 6 | FOLDE DINTO NEARL YNOTH ING 7 | BUTHE OPENE DOUTT HEHIN GES 8 | PUSHE DANDP ULLED THEJO INTS 9 | ANDHI NGES 10 | TILLI TLOOK EDALL SQUAR ES 11 | ANDOB LONGS 12 | LIKEA COMPL ICATE DFIGU RE 13 | INTHE SECON DBOOK OFEUC LID -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/carroll3.conf: -------------------------------------------------------------------------------- 1 | ABCDEFGHIJKLMNOPQRSTUVWXYZ 2 | 7 4 3 | I MQ (AELTPHQXRU) (BKNW) (CMOY) (DFG) (IV) (JZ) (S) 4 | II ME (FIXVYOMW) (CDKLHUP) (ESZ) (BJ) (GR) (NT) (A) (Q) 5 | III MV (ABDHPEJT) (CFLVMZOYQIRWUKXSG) (N) 6 | IV MJ (AEPLIYWCOXMRFZBSTGJQNH) (DV) (KU) 7 | V MZ (AVOLDRWFIUQ)(BZKSMNHYC) (EGTJPX) 8 | VI MZM (AJQDVLEOZWIYTS) (CGMNHFUX) (BPRK) 9 | VII MZM (ANOUPFRIMBZTLWKSVEGCJYDHXQ) 10 | VIII MZM (AFLSETWUNDHOZVICQ) (BKJ) (GXY) (MPR) 11 | Beta N (ALBEVFCYODJWUGNMQTZSKPR) (HIX) 12 | Gamma N (AFNIRLBSQWVXGUZDKMTPCOYJHE) 13 | B R (AE) (BN) (CK) (DQ) (FU) (GY) (HW) (IJ) (LO) (MP) 14 | (RX) (SZ) (TV) 15 | C R (AR) (BD) (CO) (EJ) (FN) (GT) (HK) (IV) (LM) (PW) 16 | (QZ) (SX) (UY) -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/carroll3.in: -------------------------------------------------------------------------------- 1 | * B Beta Gamma III IV I II UNSEEN 2 | FROM HIS SHOULDER HIAWATHA 3 | TOOK THE CAMERA OF ROSEWOOD 4 | MADE OF SLIDING FOLDING ROSEWOOD 5 | NEATLY PUT IT ALL TOGETHER 6 | IN ITS CASE IT LAY COMPACTLY 7 | FOLDED INTO NEARLY NOTHING 8 | BUT HE OPENED OUT THE HINGES 9 | PUSHED AND PULLED THE JOINTS 10 | AND HINGES 11 | TILL IT LOOKED ALL SQUARES 12 | AND OBLONGS 13 | LIKE A COMPLICATED FIGURE 14 | IN THE SECOND BOOK OF EUCLID 15 | 16 | * B Beta Gamma III IV I II UNSEEN 17 | BKGSK WHCBT ZENAW AHOED MUW 18 | DJXTP DNQMY PNQJH AEPVL DAM 19 | WXNUU GXGEZ LLBGI ENVCY IJNRC SKT 20 | VUXET QXRXZ SYPQP PICNS BS 21 | FZWCO MVZFB EKFET RTIXM PCK 22 | GPRKX RKTRR YKMDB ZSJRL LBX 23 | RVHRJ ZWVQO ZIIYL ISKEM JTT 24 | CDWZZ CMEAV BWZQP KPVUB YPRJ 25 | YVXED MHAI 26 | LTIDJ ODULX LBWTU WPTHQ KR 27 | RFNSI AQZUR 28 | HTGNT FSIAW TTBGZ IDDPF IV 29 | GRYXL LWFMR IEWWM PXRNA FMC -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/carroll3.out: -------------------------------------------------------------------------------- 1 | BKGSK WHCBT ZENAW AHOED MUW 2 | DJXTP DNQMY PNQJH AEPVL DAM 3 | WXNUU GXGEZ LLBGI ENVCY IJNRC SKT 4 | VUXET QXRXZ SYPQP PICNS BS 5 | FZWCO MVZFB EKFET RTIXM PCK 6 | GPRKX RKTRR YKMDB ZSJRL LBX 7 | RVHRJ ZWVQO ZIIYL ISKEM JTT 8 | CDWZZ CMEAV BWZQP KPVUB YPRJ 9 | YVXED MHAI 10 | LTIDJ ODULX LBWTU WPTHQ KR 11 | RFNSI AQZUR 12 | HTGNT FSIAW TTBGZ IDDPF IV 13 | GRYXL LWFMR IEWWM PXRNA FMC 14 | 15 | FROMH ISSHO ULDER HIAWA THA 16 | TOOKT HECAM ERAOF ROSEW OOD 17 | MADEO FSLID INGFO LDING ROSEW OOD 18 | NEATL YPUTI TALLT OGETH ER 19 | INITS CASEI TLAYC OMPAC TLY 20 | FOLDE DINTO NEARL YNOTH ING 21 | BUTHE OPENE DOUTT HEHIN GES 22 | PUSHE DANDP ULLED THEJO INTS 23 | ANDHI NGES 24 | TILLI TLOOK EDALL SQUAR ES 25 | ANDOB LONGS 26 | LIKEA COMPL ICATE DFIGU RE 27 | INTHE SECON DBOOK OFEUC LID -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/carroll4.conf: -------------------------------------------------------------------------------- 1 | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_. 2 | 5 3 3 | I MQ (AELT_PHQXRU) (BKNW) (CMOY) (DFG) (IV) (JZ) (S) 4 | (aelt.phqxru) (bknw) (cmoy) (dfg) (iv) (jz) (s) 5 | II ME (FIXVY_OMW) (CDKLHUP) (ESZ) (BJ) (GR) (NT) (A) (Q) 6 | (fixvy.omw) (cdklhup) (esz) (bj) (gr) (nt) (a) (q) 7 | III MV (ABDH_PEJT) (CFLVMZOYQIRWUKXSG) (N) (abdh.pejt) (cflvmzoyqirwukxsg) (n) 8 | IV MJ (AEPLI_YWCOXMRFZBSTGJQNH) (DV) (KU) (aepli.ywcoxmrfzbstgjqnh) (dv) (ku) 9 | V MZ (AVOLDR_WFIUQ)(BZKSMNHYC) (EGTJPX) (avoldr.wfiuq)(bzksmnhyc) (egtjpx) 10 | VI MZM (AJQDVLE_OZWIYTS) (CGMNHFUX) (BPRK) (ajqdvle.ozwiyts) (cgmnhfux) (bprk) 11 | VII MZM (ANOUPFRI_MBZTLWKSVEGCJYDHXQ) (anoupfri.mbztlwksvegcjydhxq) 12 | VIII MZM (AFLSETWUN_DHOZVICQ) (BKJ) (GXY) (MPR) (aflsetwun.dhozvicq) (bkj) (gxy) (mpr) 13 | Beta N (ALBEVFCYOD_JWUGNMQTZSKPR) (HIX) (albevfcyod.jwugnmqtzskpr) (hix) 14 | Gamma N (AFNIRLBSQWV_XGUZDKMTPCOYJHE) (afnirlbsqwv.xguzdkmtpcoyjhe) 15 | B R (AE) (BN) (CK) (DQ) (FU) (GY) (HW) (IJ) (LO) (MP) (ae) (bn) (ck) (dq) (fu) (gy) (hw) (ij) (lo) (mp) 16 | (RX) (SZ) (TV) (rx) (sz) (tv) (_.) 17 | C R (AR) (BD) (CO) (EJ) (FN) (GT) (HK) (IV) (LM) (PW) (ar) (bd) (co) (ej) (fn) (gt) (hk) (iv) (lm) (pw) 18 | (QZ) (SX) (UY) (qz) (sx) (uy) (_.) 19 | -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/carroll4.in: -------------------------------------------------------------------------------- 1 | * B Beta III IV I AxlE 2 | From_his_shoulder_Hiawatha 3 | took_the_camera_of_rosewood. 4 | Made_of_sliding_folding_rosewood. 5 | Neatly_put_it_all_together. 6 | In_its_case_it_lay_compactly 7 | folded_into_nearly_nothing. 8 | But_he_opened_out_the_hinges 9 | pushed_and_pulled_the_joints 10 | and_hinges 11 | till_it_looked_all_squares 12 | and_oblongs 13 | like_a_complicated_figure 14 | in_the_second_book_of_Euclid. -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/carroll4.out: -------------------------------------------------------------------------------- 1 | JeDWM LqdZX J.CLB CaeUQ rDNOE G 2 | qMFsn WFChY BDUHu mxjJD Qpscm tpK 3 | cLNOp rRThO CNDVs YoWwK BVuyE _wFzl _mV 4 | irvXa ZTKHd PMQFY MBHnE VMJKc AO 5 | qUTum bKHWE BomYK cqjTk XGLVn Hgp 6 | gRuLX HOCtG xWbCu ugKTV LSoaz Zw 7 | sdYxp gNqdZ spQox GCjoi wEbmJ GgC 8 | nSwsY HFWsu EttdE YYyoQ QEsCH TgC 9 | KxPOx u.jBW 10 | P._eE .fOBV djfjA FWqTW pTEkT O 11 | eeuKZ IkJtZ . 12 | WrFXK FyXGG OvDAz QvKVC oLYaG 13 | qBkhB _q.gU LqHnS iy.JF DJmJB AqJI -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/default.conf: -------------------------------------------------------------------------------- 1 | ABCDEFGHIJKLMNOPQRSTUVWXYZ 2 | 5 3 3 | I MQ (AELTPHQXRU) (BKNW) (CMOY) (DFG) (IV) (JZ) (S) 4 | II ME (FIXVYOMW) (CDKLHUP) (ESZ) (BJ) (GR) (NT) (A) (Q) 5 | III MV (ABDHPEJT) (CFLVMZOYQIRWUKXSG) (N) 6 | IV MJ (AEPLIYWCOXMRFZBSTGJQNH) (DV) (KU) 7 | V MZ (AVOLDRWFIUQ)(BZKSMNHYC) (EGTJPX) 8 | VI MZM (AJQDVLEOZWIYTS) (CGMNHFUX) (BPRK) 9 | VII MZM (ANOUPFRIMBZTLWKSVEGCJYDHXQ) 10 | VIII MZM (AFLSETWUNDHOZVICQ) (BKJ) (GXY) (MPR) 11 | Beta N (ALBEVFCYODJWUGNMQTZSKPR) (HIX) 12 | Gamma N (AFNIRLBSQWVXGUZDKMTPCOYJHE) 13 | B R (AE) (BN) (CK) (DQ) (FU) (GY) (HW) (IJ) (LO) (MP) 14 | (RX) (SZ) (TV) 15 | C R (AR) (BD) (CO) (EJ) (FN) (GT) (HK) (IV) (LM) (PW) 16 | (QZ) (SX) (UY) 17 | -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/format3.in: -------------------------------------------------------------------------------- 1 | * B Beta III II I AAAZ 2 | A 3 | AA 4 | AAA 5 | AAAA 6 | AAAAA 7 | AAAAAA 8 | AAAAAAA 9 | AAAAAAAA 10 | AAAAAAAAA 11 | AAAAAAAAAA -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/format3.out: -------------------------------------------------------------------------------- 1 | N 2 | FT 3 | ZMG 4 | ISXI 5 | PJWGD 6 | NJJCO Q 7 | TYRIG DM 8 | XFIES RWZ 9 | GTOIU IEKK 10 | DCSHT PYOEP -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/newchars1.conf: -------------------------------------------------------------------------------- 1 | 012345 2 | 2 1 3 | RF R (01) (23) (45) 4 | Rot1 M3 (123) (450) 5 | Rot2 M0 (0) -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/newchars1.in: -------------------------------------------------------------------------------- 1 | * RF Rot1 2 2 | 3141502 3 | 3141502 4 | 5 | * RF Rot1 2 6 | 55221 51 7 | 43050 40 -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/newchars1.out: -------------------------------------------------------------------------------- 1 | 55221 51 2 | 43050 40 3 | 4 | 31415 02 5 | 31415 02 6 | -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/permuted1.conf: -------------------------------------------------------------------------------- 1 | NOPQRSTUVWXYZABCDEFGHIJKLM 2 | 5 3 3 | I MQ (AELTPHQXRU) (BKNW) (CMOY) (DFG) (IV) (JZ) (S) 4 | II ME (FIXVYOMW) (CDKLHUP) (ESZ) (BJ) (GR) (NT) (A) (Q) 5 | III MV (ABDHPEJT) (CFLVMZOYQIRWUKXSG) (N) 6 | IV MJ (AEPLIYWCOXMRFZBSTGJQNH) (DV) (KU) 7 | V MZ (AVOLDRWFIUQ)(BZKSMNHYC) (EGTJPX) 8 | VI MZM (AJQDVLEOZWIYTS) (CGMNHFUX) (BPRK) 9 | VII MZM (ANOUPFRIMBZTLWKSVEGCJYDHXQ) 10 | VIII MZM (AFLSETWUNDHOZVICQ) (BKJ) (GXY) (MPR) 11 | Beta N (ALBEVFCYODJWUGNMQTZSKPR) (HIX) 12 | Gamma N (AFNIRLBSQWVXGUZDKMTPCOYJHE) 13 | B R (AE) (BN) (CK) (DQ) (FU) (GY) (HW) (IJ) (LO) (MP) 14 | (RX) (SZ) (TV) 15 | C R (AR) (BD) (CO) (EJ) (FN) (GT) (HK) (IV) (LM) (PW) 16 | (QZ) (SX) (UY) -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/permuted1.in: -------------------------------------------------------------------------------- 1 | * B Beta III IV I AXLE 2 | FROM HIS SHOULDER HIAWATHA 3 | TOOK THE CAMERA OF ROSEWOOD 4 | MADE OF SLIDING FOLDING ROSEWOOD 5 | NEATLY PUT IT ALL TOGETHER 6 | IN ITS CASE IT LAY COMPACTLY 7 | FOLDED INTO NEARLY NOTHING 8 | BUT HE OPENED OUT THE HINGES 9 | PUSHED AND PULLED THE JOINTS 10 | AND HINGES 11 | TILL IT LOOKED ALL SQUARES 12 | AND OBLONGS 13 | LIKE A COMPLICATED FIGURE 14 | IN THE SECOND BOOK OF EUCLID 15 | 16 | * B Beta III IV I AXLE 17 | IUGOS MDHTY KMGDD XRXYB MGL 18 | NEBDN SZPNL OHJAD CQDGK LUK 19 | TBXRA ARYOM ZAKNY NUNAA YBNTX QVL 20 | YPPGQ WJYAP QNFZG ZUMKU LV 21 | UBMJH FXBPU ZSTBF DHJGO XDR 22 | YQSZA QXZJR KZDCC JWJMS NIB 23 | JAAEO GRGHI BLVDV VYUGF ETY 24 | AWJNN VUTHV KITBZ VCQXK LHMT 25 | QJYOP RMAY 26 | HGYIK KAWEB KQEBH VGHHE GO 27 | SZGPU BZIXV 28 | VHMRP LSKKT YSXAL TMVRF NH 29 | YQCJX EUZCO GQMMX AOCJY QSV 30 | -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/permuted1.out: -------------------------------------------------------------------------------- 1 | IUGOS MDHTY KMGDD XRXYB MGL 2 | NEBDN SZPNL OHJAD CQDGK LUK 3 | TBXRA ARYOM ZAKNY NUNAA YBNTX QVL 4 | YPPGQ WJYAP QNFZG ZUMKU LV 5 | UBMJH FXBPU ZSTBF DHJGO XDR 6 | YQSZA QXZJR KZDCC JWJMS NIB 7 | JAAEO GRGHI BLVDV VYUGF ETY 8 | AWJNN VUTHV KITBZ VCQXK LHMT 9 | QJYOP RMAY 10 | HGYIK KAWEB KQEBH VGHHE GO 11 | SZGPU BZIXV 12 | VHMRP LSKKT YSXAL TMVRF NH 13 | YQCJX EUZCO GQMMX AOCJY QSV 14 | 15 | FROMH ISSHO ULDER HIAWA THA 16 | TOOKT HECAM ERAOF ROSEW OOD 17 | MADEO FSLID INGFO LDING ROSEW OOD 18 | NEATL YPUTI TALLT OGETH ER 19 | INITS CASEI TLAYC OMPAC TLY 20 | FOLDE DINTO NEARL YNOTH ING 21 | BUTHE OPENE DOUTT HEHIN GES 22 | PUSHE DANDP ULLED THEJO INTS 23 | ANDHI NGES 24 | TILLI TLOOK EDALL SQUAR ES 25 | ANDOB LONGS 26 | LIKEA COMPL ICATE DFIGU RE 27 | INTHE SECON DBOOK OFEUC LID 28 | -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/reduced1.conf: -------------------------------------------------------------------------------- 1 | HIJKLMNOPQ 2 | 3 2 3 | RF R (HI) (JK) (LM) (NO) (PQ) 4 | Rot1 MJ (HIJK) (LMNOPQ) 5 | Rot2 MN (IHKJMLONQP) 6 | -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/reduced1.in: -------------------------------------------------------------------------------- 1 | * RF Rot1 Rot2 HQ 2 | MILLION LOLLIPOP JILL 3 | * RF Rot1 Rot2 HQ 4 | NHQOH LMIJI KLQHQ MNIK 5 | -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/reduced1.out: -------------------------------------------------------------------------------- 1 | NHQOH LMIJI KLQHQ MNIK 2 | MILLI ONLOL LIPOP JILL -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/reduced2.conf: -------------------------------------------------------------------------------- 1 | ABCDEF 2 | 2 1 3 | RF R (AB) (CD) (EF) 4 | Rot1 MA (BCD) (EFA) 5 | Rot2 MA (A) -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/reduced2.in: -------------------------------------------------------------------------------- 1 | * RF Rot1 D 2 | ABCDE 3 | ABCDE 4 | 5 | * RF Rot1 D 6 | CDBEC 7 | EFEFD -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/reduced2.out: -------------------------------------------------------------------------------- 1 | CDBEC 2 | EFEFD 3 | 4 | ABCDE 5 | ABCDE -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/riptide.in: -------------------------------------------------------------------------------- 1 | * B Beta I II III AAAA (TD) (KC) (JZ) 2 | I WAS SCARED OF CODING IN JAVA 3 | I WAS SCARED OF USING GIT 4 | AND STARTING ALL THESE PROJECTS 5 | COMPILER KEEPS GETTING MAD AT ME 6 | NOW MY PROJECT ONLY RUNS IN MY DREAMS 7 | OH OH ALL THESE MERGE CONFLICTS 8 | -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/riptide.out: -------------------------------------------------------------------------------- 1 | HGJNB OKDWA LBFKU CMUTJ ZUIO 2 | XTYQF BDZRG BYFZC ASYRU 3 | UAAFW OAGFK OCJGM UMOPC HTAVR SA 4 | HXHFR UXOFC BLRYS DXFCZ XGVFA NA 5 | CNBZH SNQMC MNIRW MTTTQ BRNKR XDRPN 6 | AJIRV IFOVC TKGNU CKUMB ITFEN V -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/trivial.in: -------------------------------------------------------------------------------- 1 | * B Beta I II III AAAA 2 | HELLO WORLD 3 | * B Beta I II III AAAA 4 | ILBDA AMTAZ 5 | -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/trivial.out: -------------------------------------------------------------------------------- 1 | ILBDA AMTAZ 2 | HELLO WORLD 3 | -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/trivial1.in: -------------------------------------------------------------------------------- 1 | * B Beta I II III AAAA (AQ) (EP) 2 | HELLO WORLD 3 | * B Beta I II III AAAA (AQ) (EP) 4 | IHBDQ QMTQZ 5 | -------------------------------------------------------------------------------- /Projects/proj1/testing/correct/trivial1.out: -------------------------------------------------------------------------------- 1 | IHBDQ QMTQZ 2 | HELLO WORLD 3 | -------------------------------------------------------------------------------- /Projects/proj1/testing/error/default.conf: -------------------------------------------------------------------------------- 1 | ABCDEFGHIJKLMNOPQRSTUVWXYZ 2 | 5 3 3 | I MQ (AELTPHQXRU) (BKNW) (CMOY) (DFG) (IV) (JZ) (S) 4 | II ME (FIXVYOMW) (CDKLHUP) (ESZ) (BJ) (GR) (NT) (A) (Q) 5 | III MV (ABDHPEJT) (CFLVMZOYQIRWUKXSG) (N) 6 | IV MJ (AEPLIYWCOXMRFZBSTGJQNH) (DV) (KU) 7 | V MZ (AVOLDRWFIUQ)(BZKSMNHYC) (EGTJPX) 8 | VI MZM (AJQDVLEOZWIYTS) (CGMNHFUX) (BPRK) 9 | VII MZM (ANOUPFRIMBZTLWKSVEGCJYDHXQ) 10 | VIII MZM (AFLSETWUNDHOZVICQ) (BKJ) (GXY) (MPR) 11 | Beta N (ALBEVFCYODJWUGNMQTZSKPR) (HIX) 12 | Gamma N (AFNIRLBSQWVXGUZDKMTPCOYJHE) 13 | B R (AE) (BN) (CK) (DQ) (FU) (GY) (HW) (IJ) (LO) (MP) 14 | (RX) (SZ) (TV) 15 | C R (AR) (BD) (CO) (EJ) (FN) (GT) (HK) (IV) (LM) (PW) 16 | (QZ) (SX) (UY) 17 | -------------------------------------------------------------------------------- /Projects/proj1/testing/error/trivialerr.in: -------------------------------------------------------------------------------- 1 | Message without a configuration. 2 | -------------------------------------------------------------------------------- /Projects/proj1/testing/test-correct: -------------------------------------------------------------------------------- 1 | 2 | # Usage: bash test-correct F1.inp F2.inp ... 3 | # Runs each F.inp through java enigma.Main and compares the output to 4 | # F.out. Uses F.conf as configuration file, if it exists, and otherwise 5 | # default.conf. Briefly reports results. Exits normally if all 6 | # tests pass, and otherwise exits with code 1. 7 | 8 | rm -rf OUT.txt ERR.txt 9 | code=0 10 | 11 | if [[ "$OSTYPE" != "msys" ]]; then 12 | ULIMIT="ulimit -t 5; ulimit -f 100" 13 | fi 14 | 15 | for f in "$@"; do 16 | echo -n "$(basename $(dirname $f))/$(basename $f): "; 17 | if [ -f "${f%.in}.conf" ]; then 18 | config="${f%.in}.conf"; 19 | else 20 | config="$(dirname "$f")/default.conf" 21 | fi 22 | if (eval $ULIMIT; 23 | java -ea enigma.Main "$config" "$f" OUT.txt >ERR.txt 2>&1); then 24 | if diff -b <(cat OUT.txt ERR.txt) "${f%.in}.out" >/dev/null; then 25 | echo "OK"; 26 | else 27 | code=1; echo "ERROR (output)"; 28 | fi; 29 | else 30 | exitCode=$? 31 | case $exitCode in 32 | 158) echo "ERROR (time limit exceeded)";; 33 | 159) echo "ERROR (too much output)";; 34 | *) if grep '^Exception in thread "main"' ERR.txt >/dev/null; then 35 | code=1; echo "ERROR (uncaught exception)"; 36 | else 37 | echo "ERROR (bad exit code: $? instead of 0)"; 38 | fi;; 39 | esac 40 | code=1; echo 41 | fi; 42 | rm -rf OUT.txt ERR.txt; 43 | done; 44 | 45 | exit $code 46 | 47 | -------------------------------------------------------------------------------- /Projects/proj1/testing/test-error: -------------------------------------------------------------------------------- 1 | 2 | # Usage: bash test-error F1 F2 ... 3 | # Runs each file F through java enigma.Main and checks that it returns 4 | # a non-zero exit code and produces no exception backtrace. 5 | # Uses F.conf as configuration file, if it exists, and otherwise 6 | # default.conf. Briefly reports results. Exits normally if all 7 | # tests pass, and otherwise exits with code 1. 8 | 9 | code=0 10 | rm -rf ERR.txt 11 | 12 | if [[ "$OSTYPE" != "msys" ]]; then 13 | ULIMIT="ulimit -t 5; ulimit -f 100" 14 | fi 15 | 16 | for f in "$@"; do 17 | echo -n "$(basename $(dirname $f))/$(basename $f): "; 18 | if [ -f "${f%.in}.conf" ]; then 19 | config="${f%.in}.conf"; 20 | else 21 | config="$(dirname "$f")/default.conf" 22 | fi 23 | if (eval $ULIMIT; 24 | java -ea enigma.Main "$config" "$f" > /dev/null 2> ERR.txt); then 25 | code=1; echo "ERROR (did not report error; exit code was 0)"; 26 | else 27 | case $? in 28 | 158) code=1; echo "ERROR (time limit exceeded)";; 29 | 159) code=1; echo "ERROR (too much output)";; 30 | *) if grep '^Exception in thread "main"' ERR.txt >/dev/null; then 31 | code=1; echo "ERROR (uncaught exception)"; 32 | else 33 | echo OK; 34 | fi;; 35 | esac 36 | fi 37 | rm -rf ERR.txt; 38 | done; 39 | 40 | exit $code 41 | -------------------------------------------------------------------------------- /Projects/proj2/Makefile: -------------------------------------------------------------------------------- 1 | # This makefile is defined to give you the following targets: 2 | # 3 | # default: The default target: Compiles the program in package loa. 4 | # style: Run our style checker on the project source files. Requires that 5 | # the source files compile. 6 | # check: Compiles the db61b package, if needed, and then performs the 7 | # tests described in testing/Makefile. 8 | # clean: Remove regeneratable files (such as .class files) produced by 9 | # other targets and Emacs backup files. 10 | # 11 | # In other words, type 'make' to compile everything; 'make check' to 12 | # compile and test everything, and 'make clean' to clean things up. 13 | # 14 | # You can use this file without understanding most of it, of course, but 15 | # I strongly recommend that you try to figure it out, and where you cannot, 16 | # that you ask questions. The Lab Reader contains documentation. 17 | 18 | # Name of package containing main procedure 19 | PACKAGE = loa 20 | 21 | STYLEPROG = style61b 22 | 23 | # Targets that don't correspond to files, but are to be treated as commands. 24 | .PHONY: default check integration unit clean style jar 25 | 26 | default: 27 | "$(MAKE)" -C $(PACKAGE) default 28 | 29 | check: integration unit 30 | 31 | integration: default 32 | "$(MAKE)" -C testing check 33 | 34 | unit: default 35 | "$(MAKE)" -C loa unit 36 | 37 | style: 38 | "$(MAKE)" -C $(PACKAGE) STYLEPROG=$(STYLEPROG) style 39 | 40 | # 'make clean' will clean up stuff you can reconstruct. 41 | clean: 42 | $(RM) *~ 43 | "$(MAKE)" -C $(PACKAGE) clean 44 | "$(MAKE)" -C testing clean 45 | 46 | 47 | -------------------------------------------------------------------------------- /Projects/proj2/loa/About.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 |

8 | LOA CS61B, Version 2.0. 9 |

10 | 11 |

12 | This is an implementation of a version of the board game Lines of Action. 13 |

14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Projects/proj2/loa/GUIPlayer.java: -------------------------------------------------------------------------------- 1 | /* Skeleton Copyright (C) 2015, 2020 Paul N. Hilfinger and the Regents of the 2 | * University of California. All rights reserved. */ 3 | package loa; 4 | 5 | /** A Player that takes input from a GUI. 6 | * @author P. N. Hilfinger 7 | */ 8 | class GUIPlayer extends Player implements Reporter { 9 | 10 | /** A new GUIPlayer that takes moves and commands from GUI. */ 11 | GUIPlayer(GUI gui) { 12 | this(null, null, gui); 13 | } 14 | 15 | /** A new GUIPlayer playing PIECE under control of CONTROLLER, taking 16 | * moves and commands from GUI. */ 17 | GUIPlayer(Piece piece, Game controller, GUI gui) { 18 | super(piece, controller); 19 | _gui = gui; 20 | } 21 | 22 | @Override 23 | Player create(Piece piece, Game game) { 24 | return new GUIPlayer(piece, game, _gui); 25 | } 26 | 27 | @Override 28 | boolean isManual() { 29 | return true; 30 | } 31 | 32 | @Override 33 | String getMove() { 34 | while (true) { 35 | String command; 36 | command = getGame().readLine(false); 37 | if (command == null) { 38 | command = _gui.readCommand(); 39 | } 40 | Move move = Move.mv(command); 41 | if (move == null || getBoard().isLegal(move)) { 42 | return command; 43 | } 44 | } 45 | } 46 | 47 | @Override 48 | public void reportError(String fmt, Object... args) { 49 | _gui.reportError(fmt, args); 50 | } 51 | 52 | @Override 53 | public void reportNote(String fmt, Object... args) { 54 | _gui.reportNote(fmt, args); 55 | } 56 | 57 | @Override 58 | public void reportMove(Move unused) { 59 | } 60 | 61 | /** The GUI I use for input. */ 62 | private GUI _gui; 63 | } 64 | -------------------------------------------------------------------------------- /Projects/proj2/loa/Help.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 |

Lines of Action

9 | 10 |

11 | Lines of Action (LOA) is a board game invented by Claude Soucie. 12 |

13 | 14 |

Rules

15 | 16 | 17 |

Controlling Play

18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Projects/proj2/loa/HelpText.txt: -------------------------------------------------------------------------------- 1 | Commands: Commands are whitespace-delimited. Other trailing text on a line 2 | is ignored. Comment lines begin with # and are ignored. 3 | 4 | uv-xy A move from square uv to square xy. Here u and v are column 5 | designations (a-h) and v and y are row designations (1-8): 6 | new Stop game and return to initial position. 7 | seed N Seed the random number with integer N. 8 | auto P P is white or black; makes P into an AI. 9 | manual P P is white or black; takes moves for P from terminal. 10 | set cr P N 11 | Put P ('white', 'black', or '-') into square cr, and set the 12 | next player to move to N ('white' or 'black'). Used to 13 | set up a position, not for play. 14 | dump Display the board in standard format. 15 | quit End program. 16 | help 17 | ? This text. 18 | -------------------------------------------------------------------------------- /Projects/proj2/loa/HumanPlayer.java: -------------------------------------------------------------------------------- 1 | /* Skeleton Copyright (C) 2015, 2020 Paul N. Hilfinger and the Regents of the 2 | * University of California. All rights reserved. */ 3 | package loa; 4 | 5 | /** A Player that prompts for moves and reads them from its Game. 6 | * @author Brian Faun 7 | */ 8 | class HumanPlayer extends Player { 9 | 10 | /** A new HumanPlayer with no piece or controller (intended to produce 11 | * a template). */ 12 | HumanPlayer() { 13 | this(null, null); 14 | } 15 | 16 | /** A HumanPlayer that plays the SIDE pieces in GAME. It uses 17 | * GAME.getMove() as a source of moves. */ 18 | HumanPlayer(Piece side, Game game) { 19 | super(side, game); 20 | } 21 | 22 | @Override 23 | String getMove() { 24 | return getGame().readLine(true); 25 | } 26 | 27 | @Override 28 | Player create(Piece piece, Game game) { 29 | return new HumanPlayer(piece, game); 30 | } 31 | 32 | @Override 33 | boolean isManual() { 34 | return true; 35 | } 36 | 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Projects/proj2/loa/NullView.java: -------------------------------------------------------------------------------- 1 | /* Skeleton Copyright (C) 2015, 2020 Paul N. Hilfinger and the Regents of the 2 | * University of California. All rights reserved. */ 3 | package loa; 4 | 5 | /** A View that does nothing. 6 | * @author P. N. Hilfinger 7 | */ 8 | class NullView implements View { 9 | 10 | @Override 11 | public void update(Game controller) { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Projects/proj2/loa/Player.java: -------------------------------------------------------------------------------- 1 | /* Skeleton Copyright (C) 2015, 2020 Paul N. Hilfinger and the Regents of the 2 | * University of California. All rights reserved. */ 3 | package loa; 4 | 5 | import static loa.Piece.*; 6 | 7 | /** Represents a player. Extensions of this class do the actual playing. 8 | * @author P. N. Hilfinger 9 | */ 10 | public abstract class Player { 11 | 12 | /** A player that plays the SIDE pieces in GAME. */ 13 | Player(Piece side, Game game) { 14 | _side = side; 15 | _game = game; 16 | } 17 | 18 | /** Return my next move from the current position in getBoard(), assuming 19 | * that side() == getBoard.turn(). Assumes the game has not ended. */ 20 | abstract String getMove(); 21 | 22 | /** Return which side I'm playing. */ 23 | Piece side() { 24 | return _side; 25 | } 26 | 27 | /** Return the board I am using. */ 28 | Board getBoard() { 29 | return _game.getBoard(); 30 | } 31 | 32 | /** Return the game I am playing. */ 33 | Game getGame() { 34 | return _game; 35 | } 36 | 37 | /** Return true iff I am a manual (human or non-automated) player. */ 38 | abstract boolean isManual(); 39 | 40 | /** A factory method that returns a Player with my concrete type that 41 | * plays the side indicated by PIECE in a game controlled by 42 | * GAME. This typically will call the constructor for the class 43 | * it appears in. */ 44 | abstract Player create(Piece piece, Game game); 45 | 46 | /** This player's side. */ 47 | private final Piece _side; 48 | /** The game this player is part of. */ 49 | private Game _game; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Projects/proj2/loa/Reporter.java: -------------------------------------------------------------------------------- 1 | /* Skeleton Copyright (C) 2015, 2020 Paul N. Hilfinger and the Regents of the 2 | * University of California. All rights reserved. */ 3 | package loa; 4 | 5 | /** An object that reports errors and other notifications to the user. 6 | * @author P. N. Hilfinger 7 | */ 8 | interface Reporter { 9 | 10 | /** Report an error as indicated by FORMAT and ARGS, which have 11 | * the same meaning as in String.format. */ 12 | void reportError(String format, Object... args); 13 | 14 | /** Display a message indicated by FORMAT and ARGS, which have 15 | * the same meaning as in String.format. */ 16 | void reportNote(String format, Object... args); 17 | 18 | /** Display MOVE as needed. */ 19 | void reportMove(Move move); 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Projects/proj2/loa/TextReporter.java: -------------------------------------------------------------------------------- 1 | /* Skeleton Copyright (C) 2015, 2020 Paul N. Hilfinger and the Regents of the 2 | * University of California. All rights reserved. */ 3 | package loa; 4 | 5 | /** A Reporter that uses the standard output for messaeges. 6 | * @author P. N. Hilfinger 7 | */ 8 | class TextReporter implements Reporter { 9 | 10 | @Override 11 | public void reportError(String fmt, Object... args) { 12 | System.err.printf(fmt, args); 13 | System.err.println(); 14 | } 15 | 16 | @Override 17 | public void reportNote(String fmt, Object... args) { 18 | System.out.printf("* " + fmt, args); 19 | System.out.println(); 20 | } 21 | 22 | @Override 23 | public void reportMove(Move move) { 24 | System.out.printf("* %s%n", move); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Projects/proj2/loa/UnitTests.java: -------------------------------------------------------------------------------- 1 | /* Skeleton Copyright (C) 2015, 2020 Paul N. Hilfinger and the Regents of the 2 | * University of California. All rights reserved. */ 3 | package loa; 4 | 5 | import ucb.junit.textui; 6 | import org.junit.Test; 7 | import static org.junit.Assert.*; 8 | 9 | /** The suite of all JUnit tests for the loa package. 10 | * @author Brian Faun 11 | */ 12 | public class UnitTests { 13 | 14 | /** Run the JUnit tests in the loa package. */ 15 | public static void main(String[] ignored) { 16 | textui.runClasses(UnitTests.class); 17 | textui.runClasses(BoardTest.class); 18 | } 19 | 20 | /** Test 1. */ 21 | @Test 22 | public void initTest() { 23 | Board b = new Board(); 24 | assertTrue(true); 25 | } 26 | 27 | /** Test 2. */ 28 | @Test 29 | public void winTest() { 30 | assertTrue(true); 31 | } 32 | 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /Projects/proj2/loa/Usage.txt: -------------------------------------------------------------------------------- 1 | Usage: java loa.Main [ --debug=NUM ] [ --strict ] 2 | -------------------------------------------------------------------------------- /Projects/proj2/loa/View.java: -------------------------------------------------------------------------------- 1 | /* Skeleton Copyright (C) 2015, 2020 Paul N. Hilfinger and the Regents of the 2 | * University of California. All rights reserved. */ 3 | package loa; 4 | 5 | /** An updateable view of a LOA board. 6 | * @author P. N. Hilfinger */ 7 | interface View { 8 | 9 | /** Update the current view according to the game on CONTROLLER. */ 10 | void update(Game controller); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Projects/proj2/testing/.gitignore: -------------------------------------------------------------------------------- 1 | *.err 2 | *.out 3 | -------------------------------------------------------------------------------- /Projects/proj2/testing/Makefile: -------------------------------------------------------------------------------- 1 | # This makefile is defined to give you the following targets: 2 | # 3 | # default: Same as check 4 | # check: For each file, F.in, use F.in as input to "java $(MAIN_CLASS)" and 5 | # compare the output to the contents of the file names F.out. 6 | # Report discrepencies. 7 | # clean: Remove all the .class files produced by java compilation, 8 | # all Emacs backup files, and testing output files. 9 | # 10 | # You can use this file without understanding most of it, of course, but 11 | # I strongly recommend that you try to figure it out, and where you cannot, 12 | # that you ask questions. The Lab Reader contains documentation. 13 | 14 | SHELL = /bin/bash 15 | 16 | # If your python3 implementation has a different name (like just 'python'), 17 | # simply run 18 | # make PYTHON=python check 19 | # No need to change this file. 20 | PYTHON = python3 21 | 22 | # Flags to Java interpreter: check assertions 23 | JFLAGS = -ea 24 | 25 | # A non-standard classpath that works Linux, Mac, and Windows. 26 | # We include everything in CLASSPATH, plus the proj2 directory itself 27 | # (from which one should be able to find the amazons classes). 28 | CPATH = "..:$(CLASSPATH):;..;$(CLASSPATH)" 29 | 30 | TESTER_FLAGS = 31 | 32 | TESTS := *-1.in 33 | 34 | .PHONY: default check clean std 35 | 36 | # First, and therefore default, target. 37 | default: 38 | "$(MAKE)" -C .. 39 | "$(MAKE)" check 40 | 41 | # The "CLASSPATH=..." clause in front of the command below temporarily 42 | # changes the location in which Java searches for classes to be the directory 43 | # that contains your project. 44 | check: 45 | @echo "Testing application loa.Main..." 46 | @CLASSPATH=$(CPATH) "$(PYTHON)" tester.py $(TESTER_FLAGS) $(TESTS) 47 | 48 | # 'make clean' will clean up stuff you can reconstruct. 49 | clean: 50 | $(RM) -r *~ OUTPUT* *.log *.out __pycache__ 51 | -------------------------------------------------------------------------------- /Projects/proj2/testing/ai-v-staff-1.in: -------------------------------------------------------------------------------- 1 | # Run your AI against the staff program. 2 | #* java -ea loa.Main 3 | seed 129384 4 | manual white 5 | auto black 6 | #*move 7 | #*remote move/win 8 | -------------------------------------------------------------------------------- /Projects/proj2/testing/ai-v-staff-1.std: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Projects/proj2/testing/ai-v-staff-1.std -------------------------------------------------------------------------------- /Projects/proj2/testing/ai-v-staff-2.in: -------------------------------------------------------------------------------- 1 | #* staff-loa --strict 2 | seed 384293 3 | #*remote move/win 4 | -------------------------------------------------------------------------------- /Projects/proj2/testing/ai-v-staff-2.std: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Projects/proj2/testing/ai-v-staff-2.std -------------------------------------------------------------------------------- /Projects/proj2/testing/ai2-1.in: -------------------------------------------------------------------------------- 1 | # Have the program play against itself. Make sure somebody wins. 2 | #* java -ea loa.Main 3 | seed 12347 4 | auto Black 5 | #*move/win 6 | -------------------------------------------------------------------------------- /Projects/proj2/testing/ai2-1.std: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brianfaun/CS61B/dd491e7eac0ce8eb6b9e5748f3bf764c7a6d6850/Projects/proj2/testing/ai2-1.std -------------------------------------------------------------------------------- /Projects/proj2/testing/init-1.in: -------------------------------------------------------------------------------- 1 | # Check that the initial position is right. 2 | #* java -ea loa.Main 3 | dump 4 | quit 5 | -------------------------------------------------------------------------------- /Projects/proj2/testing/init-1.std: -------------------------------------------------------------------------------- 1 | === 2 | - b b b b b b - 3 | w - - - - - - w 4 | w - - - - - - w 5 | w - - - - - - w 6 | w - - - - - - w 7 | w - - - - - - w 8 | w - - - - - - w 9 | - b b b b b b - 10 | Next move: black 11 | === 12 | -------------------------------------------------------------------------------- /Projects/proj2/testing/simplemoves-1.in: -------------------------------------------------------------------------------- 1 | #*java -ea loa.Main 2 | # Check that some simple moves entered by hand work. The AI is never started. 3 | manual White 4 | dump 5 | b1-d3 6 | dump 7 | a3-d3 8 | dump 9 | f1-a1 10 | dump 11 | quit 12 | -------------------------------------------------------------------------------- /Projects/proj2/testing/simplemoves-1.std: -------------------------------------------------------------------------------- 1 | === 2 | - b b b b b b - 3 | w - - - - - - w 4 | w - - - - - - w 5 | w - - - - - - w 6 | w - - - - - - w 7 | w - - - - - - w 8 | w - - - - - - w 9 | - b b b b b b - 10 | Next move: black 11 | === 12 | === 13 | - b b b b b b - 14 | w - - - - - - w 15 | w - - - - - - w 16 | w - - - - - - w 17 | w - - - - - - w 18 | w - - b - - - w 19 | w - - - - - - w 20 | - - b b b b b - 21 | Next move: white 22 | === 23 | === 24 | - b b b b b b - 25 | w - - - - - - w 26 | w - - - - - - w 27 | w - - - - - - w 28 | w - - - - - - w 29 | - - - w - - - w 30 | w - - - - - - w 31 | - - b b b b b - 32 | Next move: black 33 | === 34 | === 35 | - b b b b b b - 36 | w - - - - - - w 37 | w - - - - - - w 38 | w - - - - - - w 39 | w - - - - - - w 40 | - - - w - - - w 41 | w - - - - - - w 42 | b - b b b - b - 43 | Next move: white 44 | === 45 | -------------------------------------------------------------------------------- /Projects/proj3/Makefile: -------------------------------------------------------------------------------- 1 | # This makefile is defined to give you the following targets: 2 | # 3 | # default: The default target: Compiles the program in package db61b. 4 | # style: Run our style checker on the project source files. Requires that 5 | # the source files compile. 6 | # check: Compiles the db61b package, if needed, and then performs the 7 | # tests described in testing/Makefile. 8 | # clean: Remove regeneratable files (such as .class files) produced by 9 | # other targets and Emacs backup files. 10 | # 11 | # In other words, type 'make' to compile everything; 'make check' to 12 | # compile and test everything, and 'make clean' to clean things up. 13 | # 14 | # You can use this file without understanding most of it, of course, but 15 | # I strongly recommend that you try to figure it out, and where you cannot, 16 | # that you ask questions. The Lab Reader contains documentation. 17 | 18 | # Name of package containing main procedure 19 | PACKAGE = gitlet 20 | 21 | STYLEPROG = style61b 22 | 23 | # The name of the Python 3 program, used in the 'check' target. If your system 24 | # has a different name for this program (such as just "python"), run 25 | # the Makefile with 26 | # make PYTHON=python check 27 | PYTHON = python3 28 | 29 | # Flags to pass to tester.py. 30 | TESTER_FLAGS = 31 | 32 | RMAKE = "$(MAKE)" 33 | 34 | # Targets that don't correspond to files, but are to be treated as commands. 35 | .PHONY: default check integration unit clean style 36 | 37 | default: 38 | $(RMAKE) -C $(PACKAGE) default 39 | 40 | check: integration unit 41 | 42 | integration: default 43 | $(RMAKE) -C testing PYTHON=$(PYTHON) TESTER_FLAGS="$(TESTER_FLAGS)" check 44 | 45 | unit: default 46 | $(RMAKE) -C gitlet unit 47 | 48 | style: 49 | $(RMAKE) -C $(PACKAGE) STYLEPROG=$(STYLEPROG) style 50 | 51 | # 'make clean' will clean up stuff you can reconstruct. 52 | clean: 53 | $(RM) *~ 54 | $(RMAKE) -C $(PACKAGE) clean 55 | $(RMAKE) -C testing clean 56 | 57 | 58 | -------------------------------------------------------------------------------- /Projects/proj3/gitlet/Driver.java: -------------------------------------------------------------------------------- 1 | package gitlet; 2 | import java.io.*; 3 | import java.util.*; 4 | 5 | /** Driver for gitlet. 6 | * @author Brian Faun 7 | */ 8 | public class Driver { 9 | 10 | /** New Driver. */ 11 | public Driver() { 12 | 13 | } 14 | 15 | /** New Gitlet. */ 16 | public void init() { 17 | File git = new File(".gitlet"); 18 | if (git.mkdir()) { 19 | 20 | } else { 21 | System.out.println("A gitlet version-control " 22 | + "system already exists in the current directory."); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Projects/proj3/gitlet/DumpObj.java: -------------------------------------------------------------------------------- 1 | package gitlet; 2 | 3 | import java.io.File; 4 | 5 | /** A debugging class whose main program may be invoked as follows: 6 | * java gitlet.DumpObj FILE... 7 | * where each FILE is a file produced by Utils.writeObject (or any file 8 | * containing a serialized object). This will simply read FILE, 9 | * deserialize it, and call the dump method on the resulting Object. 10 | * The object must implement the gitlet.Dumpable interface for this 11 | * to work. For example, you might define your class like this: 12 | * 13 | * import java.io.Serializable; 14 | * import java.util.TreeMap; 15 | * class MyClass implements Serializeable, Dumpable { 16 | * ... 17 | * @Override 18 | * public void dump() { 19 | * System.out.printf("size: %d%nmapping: %s%n", _size, _mapping); 20 | * } 21 | * ... 22 | * int _size; 23 | * TreeMap _mapping = new TreeMap<>(); 24 | * } 25 | * 26 | * As illustrated, your dump method should print useful information from 27 | * objects of your class. 28 | * @author P. N. Hilfinger 29 | */ 30 | public class DumpObj { 31 | 32 | /** Deserialize and apply dump to the contents of each of the files 33 | * in FILES. */ 34 | public static void main(String... files) { 35 | for (String fileName : files) { 36 | Dumpable obj = Utils.readObject(new File(fileName), 37 | Dumpable.class); 38 | obj.dump(); 39 | System.out.println("---"); 40 | } 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Projects/proj3/gitlet/Dumpable.java: -------------------------------------------------------------------------------- 1 | package gitlet; 2 | 3 | import java.io.Serializable; 4 | 5 | /** An interface describing dumpable objects. 6 | * @author P. N. Hilfinger 7 | */ 8 | interface Dumpable extends Serializable { 9 | /** Print useful information about this object on System.out. */ 10 | void dump(); 11 | } 12 | -------------------------------------------------------------------------------- /Projects/proj3/gitlet/GitletException.java: -------------------------------------------------------------------------------- 1 | package gitlet; 2 | 3 | /** General exception indicating a Gitlet error. For fatal errors, the 4 | * result of .getMessage() is the error message to be printed. 5 | * @author P. N. Hilfinger 6 | */ 7 | class GitletException extends RuntimeException { 8 | 9 | 10 | /** A GitletException with no message. */ 11 | GitletException() { 12 | super(); 13 | } 14 | 15 | /** A GitletException MSG as its message. */ 16 | GitletException(String msg) { 17 | super(msg); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Projects/proj3/gitlet/Main.java: -------------------------------------------------------------------------------- 1 | package gitlet; 2 | 3 | /** Driver class for Gitlet, the tiny stupid version-control system. 4 | * @author Brian Faun 5 | */ 6 | public class Main { 7 | 8 | /** Usage: java gitlet.Main ARGS, where ARGS contains 9 | * .... */ 10 | public static void main(String... args) { 11 | // FILL THIS IN 12 | Driver gitlet = new Driver(); 13 | if (args.length == 0) { 14 | System.err.println("Please enter a command."); 15 | return; 16 | } 17 | switch (args[0].toLowerCase()) { 18 | case "init": 19 | gitlet.init(); 20 | return; 21 | case "add": 22 | gitlet.add(args[1]); 23 | return; 24 | case "commit": 25 | try { 26 | gitlet.commit(args[1]); 27 | } catch (ArrayIndexOutOfBoundsException e) { 28 | System.err.println("Please enter a commit message."); 29 | } 30 | return; 31 | case "checkout": 32 | if (args.length == 3) { 33 | gitlet.fileCheckout(args[2]); 34 | } else if (args.length == 4) { 35 | if (args[2].equals("--")) { 36 | gitlet.checkout(args[1], args[3]); 37 | } else { 38 | System.out.println("Incorrect operands."); return; 39 | } 40 | } else if (args.length == 2) { 41 | gitlet.branchCheckout(args[1]); 42 | } 43 | return; 44 | case "log": 45 | gitlet.log(); return; 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Projects/proj3/gitlet/UnitTest.java: -------------------------------------------------------------------------------- 1 | package gitlet; 2 | 3 | import ucb.junit.textui; 4 | import org.junit.Test; 5 | import static org.junit.Assert.*; 6 | 7 | /** The suite of all JUnit tests for the gitlet package. 8 | * @author 9 | */ 10 | public class UnitTest { 11 | 12 | /** Run the JUnit tests in the loa package. Add xxxTest.class entries to 13 | * the arguments of runClasses to run other JUnit tests. */ 14 | public static void main(String[] ignored) { 15 | System.exit(textui.runClasses(UnitTest.class)); 16 | } 17 | 18 | /** A dummy test to avoid complaint. */ 19 | @Test 20 | public void placeholderTest() { 21 | } 22 | 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /Projects/proj3/gitlet/gitlet-design.md: -------------------------------------------------------------------------------- 1 | # Gitlet Design Document 2 | 3 | **Name**: 4 | 5 | ## Classes and Data Structures 6 | 7 | 8 | 9 | ## Algorithms 10 | 11 | 12 | 13 | ## Persistence 14 | 15 | -------------------------------------------------------------------------------- /Projects/proj3/testing/Makefile: -------------------------------------------------------------------------------- 1 | # This makefile is defined to give you the following targets: 2 | # 3 | # default: Same as check 4 | # check: Run the integration tests. 5 | # clean: Remove all files and directories generated by testing. 6 | # 7 | 8 | SHELL = /bin/bash 9 | 10 | # Flags to Java interpreter: check assertions 11 | JFLAGS = -ea 12 | 13 | # See comment in ../Makefile 14 | PYTHON = python3 15 | 16 | RMAKE = "$(MAKE)" 17 | 18 | TESTER = CLASSPATH="$$(pwd)/..:$(CLASSPATH):;$$(pwd)/..;$(CLASSPATH)" $(PYTHON) tester.py 19 | 20 | TESTER_FLAGS = 21 | 22 | TESTS = samples/*.in *.in 23 | 24 | .PHONY: default check clean std 25 | 26 | # First, and therefore default, target. 27 | default: 28 | $(RMAKE) -C .. 29 | $(RMAKE) PYTHON=$(PYTHON) check 30 | 31 | check: 32 | @echo "Testing application gitlet.Main..." 33 | $(TESTER) $(TESTER_FLAGS) $(TESTS) 34 | 35 | # 'make clean' will clean up stuff you can reconstruct. 36 | clean: 37 | $(RM) -r */*~ *~ __pycache__ 38 | -------------------------------------------------------------------------------- /Projects/proj3/testing/samples/test01-init.in: -------------------------------------------------------------------------------- 1 | # Basic initialization 2 | > init 3 | <<< 4 | E .gitlet 5 | -------------------------------------------------------------------------------- /Projects/proj3/testing/samples/test02-basic-checkout.in: -------------------------------------------------------------------------------- 1 | # A simple test of adding, committing, modifying, and checking out. 2 | > init 3 | <<< 4 | + wug.txt wug.txt 5 | > add wug.txt 6 | <<< 7 | > commit "added wug" 8 | <<< 9 | + wug.txt notwug.txt 10 | # Must change 11 | > checkout -- wug.txt 12 | <<< 13 | = wug.txt wug.txt 14 | -------------------------------------------------------------------------------- /Projects/proj3/testing/samples/test03-basic-log.in: -------------------------------------------------------------------------------- 1 | # Set up a simple chain of commits and check their log. 2 | > init 3 | <<< 4 | + wug.txt wug.txt 5 | > add wug.txt 6 | <<< 7 | > commit "added wug" 8 | <<< 9 | D HEADER "commit [a-f0-9]+" 10 | D DATE "Date: \w\w\w \w\w\w \d+ \d\d:\d\d:\d\d \d\d\d\d [-+]\d\d\d\d" 11 | > log 12 | === 13 | ${HEADER} 14 | ${DATE} 15 | added wug 16 | 17 | === 18 | ${HEADER} 19 | ${DATE} 20 | initial commit 21 | 22 | <<<* 23 | -------------------------------------------------------------------------------- /Projects/proj3/testing/samples/test04-prev-checkout.in: -------------------------------------------------------------------------------- 1 | # Check that we can check out a previous version. 2 | > init 3 | <<< 4 | + wug.txt wug.txt 5 | > add wug.txt 6 | <<< 7 | > commit "version 1 of wug.txt" 8 | <<< 9 | + wug.txt notwug.txt 10 | > add wug.txt 11 | <<< 12 | > commit "version 2 of wug.txt" 13 | <<< 14 | = wug.txt notwug.txt 15 | # Each ${HEADER} captures its commit UID. 16 | D UID "[a-f0-9]+" 17 | D HEADER "commit (${UID})" 18 | D DATE "Date: \w\w\w \w\w\w \d+ \d\d:\d\d:\d\d \d\d\d\d [-+]\d\d\d\d" 19 | > log 20 | === 21 | ${HEADER} 22 | ${DATE} 23 | version 2 of wug.txt 24 | 25 | === 26 | ${HEADER} 27 | ${DATE} 28 | version 1 of wug.txt 29 | 30 | === 31 | ${HEADER} 32 | ${DATE} 33 | initial commit 34 | 35 | <<<* 36 | # UID of second version 37 | D UID2 "${1}" 38 | # UID of current version 39 | D UID1 "${2}" 40 | > checkout ${UID1} -- wug.txt 41 | <<< 42 | = wug.txt wug.txt 43 | > checkout ${UID2} -- wug.txt 44 | <<< 45 | = wug.txt notwug.txt 46 | -------------------------------------------------------------------------------- /Projects/proj3/testing/src/notwug.txt: -------------------------------------------------------------------------------- 1 | This is not a wug. 2 | -------------------------------------------------------------------------------- /Projects/proj3/testing/src/wug.txt: -------------------------------------------------------------------------------- 1 | This is a wug. 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Brian Faun CS61B (Spring 2020) 2 | Data Structures 3 | 4 | Welcome to CS 61B. The CS 61 series is an introduction to computer science, with particular emphasis on software and machines from a programmer's point of view. CS 61A covered high-level approaches to problem-solving, providing you with a variety of ways to organize solutions to programming problems as compositions of functions, collections of objects, or sets of rules. In CS 61B, we move to a somewhat more detailed (and to some extent, more basic) level of programming. 5 | 6 | In CS 61B, we're concerned also with engineering. An engineer, it is said, is someone who can do for a dime what any fool can do for a dollar. Much of 61B will be concerned with the tradeoffs in time and memory for a variety of methods for structuring data. We'll also be concerned with the engineering knowledge and skills needed to build and maintain moderately large programs. 7 | --------------------------------------------------------------------------------