mirror of
https://github.com/Xevion/contest.git
synced 2025-12-11 00:06:50 -06:00
Recursion programs/data/questions finished
This commit is contained in:
1
other/Recursion/.gitignore
vendored
Normal file
1
other/Recursion/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.idea/**
|
||||||
11
other/Recursion/Recursion.iml
Normal file
11
other/Recursion/Recursion.iml
Normal 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>
|
||||||
8
other/Recursion/out/production/Recursion/lab09a.dat
Normal file
8
other/Recursion/out/production/Recursion/lab09a.dat
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
16 256
|
||||||
|
1000 2000
|
||||||
|
1254 2546
|
||||||
|
214 356
|
||||||
|
90 99
|
||||||
|
21 28
|
||||||
|
55 5
|
||||||
|
315 211
|
||||||
5
other/Recursion/out/production/Recursion/lab09b.dat
Normal file
5
other/Recursion/out/production/Recursion/lab09b.dat
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
0 0
|
||||||
|
2 5
|
||||||
|
5 0
|
||||||
|
9 9
|
||||||
|
3 9
|
||||||
37
other/Recursion/out/production/Recursion/lab09c.dat
Normal file
37
other/Recursion/out/production/Recursion/lab09c.dat
Normal 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
|
||||||
BIN
other/Recursion/questions/lab09a.DOC
Normal file
BIN
other/Recursion/questions/lab09a.DOC
Normal file
Binary file not shown.
BIN
other/Recursion/questions/lab09b.DOC
Normal file
BIN
other/Recursion/questions/lab09b.DOC
Normal file
Binary file not shown.
BIN
other/Recursion/questions/lab09c.doc
Normal file
BIN
other/Recursion/questions/lab09c.doc
Normal file
Binary file not shown.
BIN
other/Recursion/questions/lab09e.DOC
Normal file
BIN
other/Recursion/questions/lab09e.DOC
Normal file
Binary file not shown.
55
other/Recursion/src/AtCounter.java
Normal file
55
other/Recursion/src/AtCounter.java
Normal 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] = '@';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
other/Recursion/src/GCF.java
Normal file
13
other/Recursion/src/GCF.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
44
other/Recursion/src/Grid.java
Normal file
44
other/Recursion/src/Grid.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
31
other/Recursion/src/Lab09a.java
Normal file
31
other/Recursion/src/Lab09a.java
Normal 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
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
26
other/Recursion/src/Lab09b.java
Normal file
26
other/Recursion/src/Lab09b.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
other/Recursion/src/Lab09c.java
Normal file
18
other/Recursion/src/Lab09c.java
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
16
other/Recursion/src/Lab09e.java
Normal file
16
other/Recursion/src/Lab09e.java
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
48
other/Recursion/src/Permutation.java
Normal file
48
other/Recursion/src/Permutation.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
other/Recursion/src/lab09a.dat
Normal file
8
other/Recursion/src/lab09a.dat
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
16 256
|
||||||
|
1000 2000
|
||||||
|
1254 2546
|
||||||
|
214 356
|
||||||
|
90 99
|
||||||
|
21 28
|
||||||
|
55 5
|
||||||
|
315 211
|
||||||
5
other/Recursion/src/lab09b.dat
Normal file
5
other/Recursion/src/lab09b.dat
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
0 0
|
||||||
|
2 5
|
||||||
|
5 0
|
||||||
|
9 9
|
||||||
|
3 9
|
||||||
37
other/Recursion/src/lab09c.dat
Normal file
37
other/Recursion/src/lab09c.dat
Normal 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
|
||||||
Reference in New Issue
Block a user