Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Maths1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
samuel.boulton
Maths1
Commits
08fe03db
Commit
08fe03db
authored
Dec 06, 2018
by
samuelboulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Done some more quesitons
parent
76667ddc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
157 additions
and
97 deletions
+157
-97
Program.java
src/Program.java
+150
-90
ProgramTest.java
src/ProgramTest.java
+7
-7
No files found.
src/Program.java
View file @
08fe03db
...
...
@@ -2,6 +2,7 @@ import java.awt.List;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Random
;
import
java.util.Scanner
;
public
class
Program
{
...
...
@@ -72,31 +73,73 @@ public class Program {
int
[]
resultsArray
=
new
int
[
binaryArray
.
length
];
for
(
int
i
=
0
;
i
<
binaryArray
.
length
;
i
++)
{
char
[]
binaryString
=
binaryArray
[
i
].
toCharArray
();
int
binTotal
=
0
;
int
binCM
=
1
;
for
(
int
j
=
0
;
j
<
binaryString
.
length
;
j
++)
{
int
binIndex
=
binaryString
.
length
-
i
-
1
;
if
(
binaryString
[
binIndex
]
==
'1'
)
{
binTotal
=
binTotal
+
binCM
;
}
binCM
=
binCM
*
2
;
}
}
return
resultsArray
;
}
char
[]
binCA
=
binaryInput
[
0
].
toCharArray
();
/*for(int i = 0; i<wordArray.length; i++) {
resultsArray[i] = ConvertASingleWordToInt(wordArray[i]);
}*//*
int binTotal = 0;
int
binCM
=
0
;
for
(
int
i
=
0
;
i
<
binCA
.
length
;
i
++)
{
int binCM = 1;
char[] binCA = binaryArray.toCharArray();
for (int i = 0; i < binCA.length; i++)
{
int binIndex = binCA.length - i - 1;
if
(
binCA
[
binIndex
]
==
'1'
)
{
if (binCA[binIndex] == '1')
{
binTotal = binTotal + binCM;
}
binCM = binCM * 2;
}
System.out.println(binTotal);
*//*
char[] binCA = binaryArray[0].toCharArray();
int binTotal = 0;
int binCM = 1;
for (int i = 0; i < binCA.length; i++)
{
int binIndex = binCA.length - i - 1;
if (binCA[binIndex] == '1')
{
binTotal = binTotal + binCM;
}
binCM = binCM * 2;
}
return resultsArray;
}
*//*
/*
public static int ConvertASingleBinaryToInt(String someBinary) {
int result = 0;
for(int i = 0; i < binaryArray.length; i++)
{
}
if(someBinary == ) {result = 11;}
return result;
...
...
@@ -104,7 +147,7 @@ public class Program {
}
/*
public static int[] ConvertWordsToInt(String[] wordArray) {
...
...
@@ -133,9 +176,6 @@ public class Program {
}
*/
public
static
int
[]
ConvertHexToInt
(
String
[]
hexArray
)
{
...
...
@@ -156,45 +196,29 @@ public class Program {
public
static
int
[]
Union
(
int
[]
intArrayA
,
int
[]
intArrayB
)
{
// DONE AND PASSED TEST
ArrayList
<
Integer
>
unionList
=
new
ArrayList
<
Integer
>();
for
(
int
i
=
0
;
i
<
intArrayA
.
length
;
i
++)
{
unionList
.
add
(
intArrayA
[
i
]);
for
(
int
k
=
0
;
k
<
intArrayB
.
length
;
k
++)
{
unionList
.
add
(
intArrayB
[
k
]);
if
(
intArrayA
[
i
]
!=
intArrayB
[
k
])
{
unionList
.
add
(
intArrayB
[
k
]);
unionList
.
add
(
intArrayA
[
i
]);
}
}
}
/*
for (int j = 0; j < unionList.size(); j++)
{
if(unionList.get(j) == intArrayA[i])
{
unionList.remove(j);
}
}
for(int k = 0; k < intArrayB.length; k++)
for
(
int
j
=
0
;
j
<
intArrayB
.
length
;
j
++)
{
unionList.add(intArrayB[k]);
for(int l = 0; l < unionList.size(); l++)
{
if(unionList.get(l) == intArrayB[k])
{
unionList.remove(l);
}
}
unionList
.
add
(
intArrayB
[
j
]);
}
*/
for
(
int
k
=
0
;
k
<
unionList
.
size
();
k
++)
{
for
(
int
l
=
k
+
1
;
l
<
unionList
.
size
();
l
++)
{
if
(
unionList
.
get
(
k
).
equals
(
unionList
.
get
(
l
)))
{
unionList
.
remove
(
l
);
l
--;
}
}
}
int
[]
resultsArray
=
new
int
[
unionList
.
size
()];
for
(
int
i
=
0
;
i
<
unionList
.
size
();
i
++)
{
resultsArray
[
i
]
=
unionList
.
get
(
i
);
...
...
@@ -205,14 +229,10 @@ public class Program {
}
public
static
int
[]
Intersection
(
int
[]
intArrayA
,
int
[]
intArrayB
)
{
// DONE AND PASSED TEST
ArrayList
<
Integer
>
intersectList
=
new
ArrayList
<
Integer
>();
int
results
=
0
;
for
(
int
j
=
0
;
j
<
intArrayA
.
length
;
j
++)
{
for
(
int
k
=
0
;
k
<
intArrayB
.
length
;
k
++)
...
...
@@ -237,26 +257,26 @@ public class Program {
}
public
static
int
[]
Difference
(
int
[]
intArrayA
,
int
[]
intArrayB
)
{
ArrayList
<
Integer
>
differenceList
=
new
ArrayList
<
Integer
>();
/*
for
(
int
j
=
0
;
j
<
intArrayA
.
length
;
j
++)
{
for
(
int
k
=
0
;
k
<
intArrayB
.
length
;
k
++)
{
if
(
intArrayA
[
j
]
!=
intArrayB
[
k
])
{
differenceList
.
add
(
intArrayA
[
j
]);
}
}
}
*/
int
[]
resultsArray
=
new
int
[
differenceList
.
size
()];
...
...
@@ -402,10 +422,20 @@ public static int Range (int[] input) {
public
static
double
Median
(
int
[]
input
)
{
int
output
=
0
;
// DONE AND PASSED TEST
double
output
=
0
;
double
sum
=
0.0
;
Arrays
.
sort
(
input
);
int
totalCount
=
input
.
length
;
if
(
totalCount
%
2
==
0
)
{
sum
=
input
[
totalCount
/
2
]
+
input
[
totalCount
/
2
-
1
];
output
=
sum
/
2
;
}
else
{
output
=
input
[
totalCount
/
2
];
}
return
output
;
}
...
...
@@ -415,27 +445,30 @@ public static int Range (int[] input) {
public
static
double
StandardDeviation
(
int
[]
input
)
{
// ask about calcualtions
// the mean works
double
output
=
0
;
double
mean
=
0
;
double
totalMean
=
0
;
// calculate mean
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
mean
+=
input
[
i
];
}
totalMean
=
mean
/
input
.
length
;
// calculate standard dev
for
(
int
j
=
0
;
j
<
input
.
length
;
j
++)
{
output
=
output
+
j
+
(
j
-
totalMean
)*(
j
-
totalMean
);
}
output
=
output
/
(
input
.
length
-
1
);
output
=
Math
.
sqrt
(
output
);
return
output
;
// DONE AND PASSED TEST
double
output
=
0.0
;
double
length
=
0.0
;
double
totalMean
=
0.0
;
double
sum
=
0.0
;
double
sum2
=
0.0
;
double
variance
=
0.0
;
double
mean
=
0.0
;
length
=
input
.
length
;
for
(
double
i
:
input
)
{
sum
+=
i
;
mean
=
sum
/
length
;
}
totalMean
=
mean
;
for
(
double
j
:
input
)
{
sum2
+=
(
j
-
totalMean
)*(
j
-
totalMean
);
variance
=
sum2
/(
length
-
1
);
}
output
=
Math
.
sqrt
(
variance
);
return
output
;
}
...
...
@@ -443,14 +476,12 @@ public static int Range (int[] input) {
public
static
double
HarmonicMean
(
int
[]
input
)
{
double
output
=
0
;
double
sum
=
0
;
// ASK WHY THIS IS WRONG
//DONE AND PASSED TEST
double
output
=
0.0
;
double
sum
=
0.0
;
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
sum
=
(
sum
+
1
)
/
input
[
i
];
sum
+=
1.0
/
input
[
i
];
}
output
=
input
.
length
/
sum
;
...
...
@@ -462,9 +493,19 @@ public static int Range (int[] input) {
public
static
double
ComplexSumFunctionA
(
int
[]
input
)
{
// ASK MATT
double
output
=
0.0
;
double
sum
=
0.0
;
double
sum2
=
0.0
;
double
sum3
=
0.0
;
double
output
=
0
;
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
sum
+=
input
[
i
]
/
2
;
sum2
+=
Math
.
pow
(
sum
,
i
/
2
);
}
sum3
=
input
.
length
+
3
;
output
=
sum2
/
sum3
;
return
output
;
}
...
...
@@ -477,7 +518,14 @@ public static int Range (int[] input) {
int
[][]
resultMatrix
=
new
int
[
matrix
.
length
][
matrix
[
0
].
length
];
for
(
int
i
=
0
;
i
<
matrix
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
matrix
[
0
].
length
;
j
++)
{
resultMatrix
[
i
][
j
]
=
scalar
*
matrix
[
i
][
j
];
}
}
return
resultMatrix
;
...
...
@@ -487,10 +535,20 @@ public static int Range (int[] input) {
public
static
int
[][]
ComplexMatrixOperation
(
int
[][]
matrix
,
int
scalar
){
public
static
int
[][]
ComplexMatrixOperation
(
int
[][]
matrix
,
int
[][]
matrix2
,
int
scalar
){
int
[][]
resultMatrix
=
new
int
[
matrix
.
length
][
matrix
[
0
].
length
];
// DONE AND PASSED TEST
int
[][]
sum
=
new
int
[
matrix
.
length
][
matrix
[
0
].
length
];
for
(
int
i
=
0
;
i
<
matrix
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
matrix2
[
0
].
length
;
j
++)
{
sum
[
i
][
j
]
=
matrix
[
i
][
j
]
+
matrix2
[
i
][
j
];
resultMatrix
[
i
][
j
]
=
scalar
*
sum
[
i
][
j
];
}
}
return
resultMatrix
;
}
...
...
@@ -504,7 +562,8 @@ public static int Range (int[] input) {
Random
rng
=
new
Random
(
1234
);
for
(
int
i
=
0
;
i
<
iterations
;
i
++)
{
for
(
int
i
=
0
;
i
<
iterations
;
i
++)
{
}
...
...
@@ -523,7 +582,8 @@ public static int Range (int[] input) {
Random
rng
=
new
Random
(
1234
);
for
(
int
i
=
0
;
i
<
iterations
;
i
++)
{
for
(
int
i
=
0
;
i
<
iterations
;
i
++)
{
}
...
...
src/ProgramTest.java
View file @
08fe03db
...
...
@@ -258,25 +258,25 @@ class ProgramTest {
}
/*
@Test
void
testComplexMatrixOperation
()
{
int
[][]
matrix
=
{{
1
,
2
},
{
3
,
4
}};
int[][] matrix2 = Program.ComplexMatrixOperation(matrix,matrix,11);
int
[][]
matrix2
=
Program
.
ComplexMatrixOperation
(
matrix
,
matrix
,
11
);
assertEquals(matrix2[0][0],22);
assertEquals(matrix2[0][1],44);
assertEquals(matrix2[1][0],66);
assertEquals(matrix2[1][1],88);
assertEquals
(
matrix2
[
0
][
0
],
22
);
assertEquals
(
matrix2
[
0
][
1
],
44
);
assertEquals
(
matrix2
[
1
][
0
],
66
);
assertEquals
(
matrix2
[
1
][
1
],
88
);
}
*/
@Test
void
testGenerateDistributionForSpecificDie
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment