Skip to content

Finished Game of Apps Assignment #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Challenge 1 - Algorithms/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions Challenge 1 - Algorithms/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions Challenge 1 - Algorithms/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Challenge 1 - Algorithms</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
98 changes: 98 additions & 0 deletions Challenge 1 - Algorithms/src/Algorithms.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

import java.util.Arrays;
import java.util.*;

public class Algorithms {

public static String[] FindPairs(int[] testArray, int targetSum) {

//Arrays.sort(testArray);

Map<Integer, Integer> testArrayMap = new HashMap<Integer, Integer>();
Set<Integer> outputSet = new HashSet<Integer>();

ArrayList<String> outputs = new ArrayList<String>();

for(int i=0;i<testArray.length;i++) {

int num = testArray[i];

int count = testArrayMap.containsKey(num) ? testArrayMap.get(num) : 0;
testArrayMap.put(num, count + 1);
}

for(int i=0;i<testArray.length;i++) {

Integer num = new Integer(testArray[i]);
Integer difference = new Integer(targetSum - num);

//System.out.println(difference);

if(testArrayMap.containsKey(difference)) {

if(difference.equals(num)) {
if(testArrayMap.get(num) < 2) {
continue; //if same numbers and no duplicates then continue
}
}

Integer min = Math.min(num, difference);
Integer max = Math.max(num, difference);

if(!outputSet.contains(min)) { //test if already outputed pair
String output = "(" + min + ", " + max + ")";

System.out.println(output);

outputs.add(output);
outputSet.add(min);
}
}
}

String[] outputsArray = new String[outputs.size()];
outputsArray = outputs.toArray(outputsArray);

return outputsArray;
}

public static boolean isPalindrome(String testString) {
int length = testString.length();

if(length <= 1) {
return true; //base case
}

int mid = Math.floorDiv(length, 2);

for(int i=0;i<mid;i++) {
char front = Character.toLowerCase(testString.charAt(i));
char back = Character.toLowerCase(testString.charAt(length-i-1));

if(!Character.isLetter(front)) {
return false;//bad input
}

if(front != back) {
return false;
}
}

return true;
}

public static void main(String[] args) {
int[] testArray = {2, 4, 5, 1, 3, 5, 4};
int targetSum = 6;
// Expected pairs are (to be printed on the console):
// (2, 4)
// (1, 5)

FindPairs(testArray, targetSum);

System.out.println(isPalindrome("radar"));
System.out.println(isPalindrome("bob"));
System.out.println(isPalindrome("cboba"));

}
}
60 changes: 60 additions & 0 deletions Challenge 1 - Algorithms/src/AlgorithmsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class AlgorithmsTest {

@Test
void FindPairsTest() {
//example
int[] testArray = {2, 4, 5, 1, 3, 5, 4};
int targetSum = 6;

String[] outputs = new String[] {"(2, 4)", "(1, 5)"};

assertArrayEquals(outputs, Algorithms.FindPairs(testArray,targetSum));

//same number pair
testArray = new int[]{2, 4, 5, 1, 3, 3, 5, 4};
targetSum = 6;
outputs = new String[] {"(2, 4)", "(1, 5)", "(3, 3)"};

assertArrayEquals(outputs, Algorithms.FindPairs(testArray,targetSum));

//unique pair
testArray = new int[]{1, 5, 1, 5};
targetSum = 6;
outputs = new String[] {"(1, 5)",};

assertArrayEquals(outputs, Algorithms.FindPairs(testArray,targetSum));

//negative
testArray = new int[]{1, 0, 0, -1};
targetSum = 0;
outputs = new String[] {"(-1, 1)", "(0, 0)"};

assertArrayEquals(outputs, Algorithms.FindPairs(testArray,targetSum));

//negative
testArray = new int[]{1, 0, 0, -1};
targetSum = -1;
outputs = new String[] {"(-1, 0)",};

assertArrayEquals(outputs, Algorithms.FindPairs(testArray,targetSum));
}

@Test
void IsPalindromeTest() {
//examples
assertEquals(true, Algorithms.isPalindrome("radar"));
assertEquals(true, Algorithms.isPalindrome("bob"));
assertEquals(false, Algorithms.isPalindrome("boba"));

//case insensitive
assertEquals(true, Algorithms.isPalindrome("boB"));

//non alpha, bad input
assertEquals(false, Algorithms.isPalindrome("$boB$"));
}

}
Binary file added Challenge 2 - APK/app-release.apk
Binary file not shown.
14 changes: 14 additions & 0 deletions Challenge 2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
1 change: 1 addition & 0 deletions Challenge 2/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 116 additions & 0 deletions Challenge 2/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Challenge 2/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Challenge 2/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Challenge 2/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Challenge 2/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading