Recursion programs/data/questions finished

This commit is contained in:
Xevion
2020-11-27 00:30:18 -06:00
parent cd721c514a
commit cec8ed8317
20 changed files with 363 additions and 0 deletions

1
other/Recursion/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.idea/**

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,8 @@
16 256
1000 2000
1254 2546
214 356
90 99
21 28
55 5
315 211

View File

@@ -0,0 +1,5 @@
0 0
2 5
5 0
9 9
3 9

View File

@@ -0,0 +1,37 @@
5
X O O O X
X X X X O
O O X O X
O X X X O
O O O O X
7
X O O O O X X
X X X X O X O
O O X O O X O
O O O X O O O
O X O X O X X
O X O X X X O
O X O X O O X
7
X O O O O X O
X X X X O O X
O O X O O X X
O O X O O X X
O X O X O X X
X X O X O X X
X X O O O X X
7
X O X O O X O
X O X O X X O
X O O O X O O
O X X O X O X
O X O O O O X
X O X O X O O
X X O O X X X
3
X X X
X X X
X X X
2
O O
O O

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

@@ -0,0 +1,55 @@
//<2F> A+ Computer Science - www.apluscompsci.com
//Name - Ryan Walters
//Date - November 12th, 2020
//Class - Computer Science II Honors
//Lab - Labs 09b (AtCounter)
public class AtCounter {
private static final char[][] atMat = new char[][]{{'@', '-', '@', '-', '-', '@', '-', '@', '@', '@'},
{'@', '@', '@', '-', '@', '@', '-', '@', '-', '@'},
{'-', '-', '-', '-', '-', '-', '-', '@', '@', '@'},
{'-', '@', '@', '@', '@', '@', '-', '@', '-', '@'},
{'-', '@', '-', '@', '-', '@', '-', '@', '-', '@'},
{'@', '@', '@', '@', '@', '@', '-', '@', '@', '@'},
{'-', '@', '-', '@', '-', '@', '-', '-', '-', '@'},
{'-', '@', '@', '@', '-', '@', '-', '-', '-', '-'},
{'-', '@', '-', '@', '-', '@', '-', '@', '@', '@'},
{'-', '@', '@', '@', '@', '@', '-', '@', '@', '@'}};
/**
* @param r Row index
* @param c Column index
* @return Returns the number of
*/
public static int countAts(int r, int c) {
if (valid(r, c) && AtCounter.atMat[r][c] == '@') {
AtCounter.atMat[r][c] = 'v'; // mark as visited
return 1 + countAts(r + 1, c) + countAts(r - 1, c) + countAts(r, c + 1) + countAts(r, c - 1);
}
return 0;
}
/**
* @param r Row index
* @param c Column index
* @return True if the indexes provided are a valid location within the array
*/
private static boolean valid(int r, int c) {
return r >= 0 && c >= 0 && r < 10 && c < 10;
}
/**
* Resets the static map field to it's original state, changing visited nodes back to unvisited @ nodes.
*/
public static void reset() {
// iterate through all positions in character matrix
for (int r = 0; r < AtCounter.atMat.length; r++) {
for (int c = 0; c < AtCounter.atMat[0].length; c++) {
// if visited, set back to unvisited @ node
if(AtCounter.atMat[r][c] == 'v')
AtCounter.atMat[r][c] = '@';
}
}
}
}

View File

@@ -0,0 +1,13 @@
//<2F> A+ Computer Science - www.apluscompsci.com
//Name - Ryan Walters
//Date - November 12th, 2020
//Class - Computer Science II Honors
//Lab - Labs
public class GCF {
public static int gcf(int n1, int n2) {
if (n2 != 0)
return gcf(n2, n1 % n2);
return n1;
}
}

View File

@@ -0,0 +1,44 @@
//<2F> A+ Computer Science - www.apluscompsci.com
//Name -
//Date -
//Class -
//Lab -
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import static java.lang.System.*;
public class Grid
{
private String[][] grid;
public Grid()
{
}
public Grid(int rows, int cols, String[] vals)
{
}
public void setGrid(int rows, int cols, String[] vals)
{
}
public int findMax(String val)
{
int count=-1;
return count;
}
private int findMax(int r, int c, String search)
{
return 0;
}
public String toString()
{
String output="";
return output;
}
}

View File

@@ -0,0 +1,31 @@
//<2F> A+ Computer Science - www.apluscompsci.com
//Name - Ryan Walters
//Date - November 12th, 2020
//Class - Computer Science II Honors
//Lab - Labs 09a
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import static java.lang.System.*;
public class Lab09a {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("./src/lab09a.dat"));
while (input.hasNextLine()) {
Scanner line = new Scanner(input.nextLine());
int a = line.nextInt();
int b = line.nextInt();
out.println(
String.format(
"%-16s ----- %d", // Right pad spaces 16 characters
String.format("GCF(%d, %d)", a, b),
GCF.gcf(a, b) // Calculate GCF recursively
)
);
}
}
}

View File

@@ -0,0 +1,26 @@
//<2F> A+ Computer Science - www.apluscompsci.com
//Name - Ryan Walters
//Date - November 12th, 2020
//Class - Computer Science II Honors
//Lab - Labs 09b
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import static java.lang.System.out;
public class Lab09b {
public static void main(String args[]) throws FileNotFoundException {
Scanner input = new Scanner(new File("./src/lab09b.dat"));
while (input.hasNextLine()) {
Scanner line = new Scanner(input.nextLine());
// Get inputs, begin counting at defined coordinate
int r = line.nextInt();
int c = line.nextInt();
out.println(String.format("%d %d has %d @s connected.", r, c, AtCounter.countAts(r, c)));
AtCounter.reset();
}
}
}

View File

@@ -0,0 +1,18 @@
//<2F> A+ Computer Science - www.apluscompsci.com
//Name - Ryan Walters
//Date - November 12th, 2020
//Class - Computer Science II Honors
//Lab - Labs 09c
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import static java.lang.System.*;
public class Lab09c
{
public static void main( String args[] ) throws IOException
{
Scanner input = new Scanner("./src/lab09c.dat");
}
}

View File

@@ -0,0 +1,16 @@
//<2F> A+ Computer Science - www.apluscompsci.com
//Name -
//Date -
//Class -
//Lab -
import java.util.*;
import static java.lang.System.*;
public class Lab09e
{
public static void main( String args[] )
{
//add test cases
}
}

View File

@@ -0,0 +1,48 @@
//<2F> A+ Computer Science - www.apluscompsci.com
//Name -
//Date -
//Class -
//Lab -
import java.util.*;
import static java.lang.System.*;
public class Permutation
{
private String orig;
private String list;
public Permutation(String word)
{
orig=word;
list="";
}
public void permutation()
{
out.println("\nPERMUTATION OF WORD :: "+orig);
permutation(orig,"");
}
private void permutation(String orig, String sent)
{
}
public String toString()
{
return list;
}
}

View File

@@ -0,0 +1,8 @@
16 256
1000 2000
1254 2546
214 356
90 99
21 28
55 5
315 211

View File

@@ -0,0 +1,5 @@
0 0
2 5
5 0
9 9
3 9

View File

@@ -0,0 +1,37 @@
5
X O O O X
X X X X O
O O X O X
O X X X O
O O O O X
7
X O O O O X X
X X X X O X O
O O X O O X O
O O O X O O O
O X O X O X X
O X O X X X O
O X O X O O X
7
X O O O O X O
X X X X O O X
O O X O O X X
O O X O O X X
O X O X O X X
X X O X O X X
X X O O O X X
7
X O X O O X O
X O X O X X O
X O O O X O O
O X X O X O X
O X O O O O X
X O X O X O O
X X O O X X X
3
X X X
X X X
X X X
2
O O
O O