Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Maths assessment.
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
daniel.parker
Maths assessment.
Commits
60c70f61
Commit
60c70f61
authored
6 years ago
by
daniel.parker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Second.
parent
e2693a15
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
230 additions
and
47 deletions
+230
-47
Program.java
src/Program.java
+230
-47
No files found.
src/Program.java
View file @
60c70f61
...
@@ -65,47 +65,112 @@ public class Program {
...
@@ -65,47 +65,112 @@ public class Program {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
ConvertBinaryToInt
(
binaryInput
);
ConvertBinaryToInt
(
binaryInput
);
String
[]
input
=
{
"010"
,
"110"
,
"111"
,
"1010101"
};
String
[]
input2
=
{
"50"
,
"110"
,
"FA"
,
"B0"
,
"F"
};
System
.
out
.
println
(
ConvertSingb3ToInt
(
"12"
));
System
.
out
.
println
(
ConvertSingb20ToInt
(
"50"
));
System
.
out
.
println
(
ConvertSingleHexToInt
(
"50"
));
System
.
out
.
println
(
ConvertSingleBinaryToInt
(
"101"
));
System
.
out
.
println
(
Arrays
.
toString
(
ConvertBinaryToInt
(
input
)));
}
}
public
static
int
[]
ConvertBinaryToInt
(
String
[]
binaryArray
)
{
public
static
int
ConvertSingleBinaryToInt
(
String
binary
)
{
int
[]
resultsArray
=
new
int
[
binaryArray
.
length
];
int
result
=
0
;
int
wordTotal
=
0
;
for
(
int
i
=
0
;
i
<
binary
.
length
();
i
++)
{
for
(
int
eachWord
=
0
;
eachWord
<
binaryArray
.
length
;
eachWord
++)
{
int
index
=
(
binary
.
length
()
-
i
-
1
);
char
[]
characters
=
binaryArray
[
eachWord
].
toCharArray
();
double
columnMultiplier
=
Math
.
pow
(
2
,
index
);
for
(
int
i
=
0
;
i
<
characters
.
length
;
i
++)
{
if
(
binary
.
charAt
(
i
)
==
'1'
)
{
int
index
=
(
characters
.
length
-
i
-
1
);
result
=
(
int
)
(
result
+
columnMultiplier
);
double
columnMultiplier
=
Math
.
pow
(
2
,
index
);
if
(
characters
[
index
]==
'1'
)
{
wordTotal
=(
int
)
(
wordTotal
+
columnMultiplier
);
}
}
}
resultsArray
[
eachWord
]
=
wordTotal
;
}
}
System
.
out
.
println
(
Arrays
.
toString
(
resultsArray
));
return
resultsArray
;
return
result
;
}
}
public
static
int
[]
Convert
HexToInt
(
String
[]
hex
Array
)
{
public
static
int
[]
Convert
BinaryToInt
(
String
[]
binary
Array
)
{
int
[]
resultsArray
=
new
int
[
hexArray
.
length
];
int
[]
resultsArray
=
new
int
[
binaryArray
.
length
];
String
hexidecimal
=
"0123456789ABCDEF"
;
for
(
int
i
=
0
;
i
<
binaryArray
.
length
;
i
++)
{
int
total
=
0
;
resultsArray
[
i
]
=
resultsArray
[
i
]
+
ConvertSingleBinaryToInt
(
binaryArray
[
i
]);
for
(
int
eachHex
=
0
;
eachHex
<
hexArray
.
length
;
eachHex
++)
}
{
return
resultsArray
;
char
[]
hexChar
=
hexArray
[
eachHex
].
toCharArray
();
for
(
int
eachChar
=
0
;
eachChar
<
hexChar
.
length
;
eachChar
++
)
{
}
}
resultsArray
[
eachHex
]
=
resultsArray
[
eachHex
]
+
total
;
}
public
static
int
ConvertSingleHexToInt
(
String
hex
)
{
return
resultsArray
;
int
result
=
0
;
for
(
int
i
=
0
;
i
<
hex
.
length
();
i
++)
{
int
index
=
(
hex
.
length
()
-
i
-
1
);
double
columnMultiplier
=
Math
.
pow
(
16
,
index
);
if
(
hex
.
charAt
(
i
)
==
'1'
)
{
result
=
(
int
)
(
result
+
(
1
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'2'
)
{
result
=
(
int
)
(
result
+
(
2
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'3'
)
{
result
=
(
int
)
(
result
+
(
3
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'4'
)
{
result
=
(
int
)
(
result
+
(
4
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'5'
)
{
result
=
(
int
)
(
result
+
(
5
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'6'
)
{
result
=
(
int
)
(
result
+
(
6
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'7'
)
{
result
=
(
int
)
(
result
+
(
7
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'8'
)
{
result
=
(
int
)
(
result
+
(
8
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'9'
)
{
result
=
(
int
)
(
result
+
(
9
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'0'
)
{
result
=
(
int
)
(
result
+
(
0
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'A'
)
{
result
=
(
int
)
(
result
+
(
10
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'B'
)
{
result
=
(
int
)
(
result
+
(
11
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'C'
)
{
result
=
(
int
)
(
result
+
(
12
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'D'
)
{
result
=
(
int
)
(
result
+
(
13
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'E'
)
{
result
=
(
int
)
(
result
+
(
14
*
columnMultiplier
));
}
if
(
hex
.
charAt
(
i
)
==
'F'
)
{
result
=
(
int
)
(
result
+
(
15
*
columnMultiplier
));
}
}
return
result
;
}
public
static
int
[]
ConvertHexToInt
(
String
[]
hexArray
)
{
int
[]
resultsArray
=
new
int
[
hexArray
.
length
];
for
(
int
i
=
0
;
i
<
hexArray
.
length
;
i
++)
{
resultsArray
[
i
]
=
resultsArray
[
i
]
+
ConvertSingleHexToInt
(
hexArray
[
i
]);
}
return
resultsArray
;
}
}
public
static
int
[]
Union
(
int
[]
intArrayA
,
int
[]
intArrayB
)
{
public
static
int
[]
Union
(
int
[]
intArrayA
,
int
[]
intArrayB
)
{
...
@@ -177,16 +242,95 @@ for(int eachHex = 0; eachHex < hexArray.length; eachHex++)
...
@@ -177,16 +242,95 @@ for(int eachHex = 0; eachHex < hexArray.length; eachHex++)
double
output
=
0
;
double
output
=
0
;
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
output
=
(
output
+
input
[
i
])/
input
.
length
;
output
=
output
+
input
[
i
];
}
}
output
=
(
output
/
input
.
length
);
return
output
;
return
output
;
}
}
public
static
int
ConvertSingb20ToInt
(
String
b20
)
{
int
result
=
0
;
for
(
int
i
=
0
;
i
<
b20
.
length
();
i
++)
{
int
index
=
(
b20
.
length
()
-
i
-
1
);
double
columnMultiplier
=
Math
.
pow
(
20
,
index
);
if
(
b20
.
charAt
(
i
)
==
'1'
)
{
result
=
(
int
)
(
result
+
(
1
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'2'
)
{
result
=
(
int
)
(
result
+
(
2
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'3'
)
{
result
=
(
int
)
(
result
+
(
3
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'4'
)
{
result
=
(
int
)
(
result
+
(
4
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'5'
)
{
result
=
(
int
)
(
result
+
(
5
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'6'
)
{
result
=
(
int
)
(
result
+
(
6
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'7'
)
{
result
=
(
int
)
(
result
+
(
7
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'8'
)
{
result
=
(
int
)
(
result
+
(
8
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'9'
)
{
result
=
(
int
)
(
result
+
(
9
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'0'
)
{
result
=
(
int
)
(
result
+
(
0
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'A'
)
{
result
=
(
int
)
(
result
+
(
10
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'B'
)
{
result
=
(
int
)
(
result
+
(
11
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'C'
)
{
result
=
(
int
)
(
result
+
(
12
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'D'
)
{
result
=
(
int
)
(
result
+
(
13
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'E'
)
{
result
=
(
int
)
(
result
+
(
14
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'F'
)
{
result
=
(
int
)
(
result
+
(
15
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'G'
)
{
result
=
(
int
)
(
result
+
(
16
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'H'
)
{
result
=
(
int
)
(
result
+
(
17
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'I'
)
{
result
=
(
int
)
(
result
+
(
18
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'J'
)
{
result
=
(
int
)
(
result
+
(
19
*
columnMultiplier
));
}
if
(
b20
.
charAt
(
i
)
==
'K'
)
{
result
=
(
int
)
(
result
+
(
20
*
columnMultiplier
));
}
}
return
result
;
}
public
static
int
[]
ConvertBase20ToInt
(
String
[]
b20array
)
{
public
static
int
[]
ConvertBase20ToInt
(
String
[]
b20array
)
{
int
[]
resultsArray
=
new
int
[
b20array
.
length
];
int
[]
resultsArray
=
new
int
[
b20array
.
length
];
for
(
int
i
=
0
;
i
<
b20array
.
length
;
i
++)
{
resultsArray
[
i
]
=
resultsArray
[
i
]
+
ConvertSingb20ToInt
(
b20array
[
i
]);
}
return
resultsArray
;
return
resultsArray
;
...
@@ -210,10 +354,31 @@ public static int Range (int[] input) {
...
@@ -210,10 +354,31 @@ public static int Range (int[] input) {
return
output
;
return
output
;
}
}
public
static
int
ConvertSingb3ToInt
(
String
b3
)
{
int
result
=
0
;
for
(
int
i
=
0
;
i
<
b3
.
length
();
i
++)
{
int
index
=
(
b3
.
length
()
-
i
-
1
);
double
columnMultiplier
=
Math
.
pow
(
3
,
index
);
if
(
b3
.
charAt
(
i
)
==
'0'
)
{
result
=
(
int
)
(
result
+
(
0
*
columnMultiplier
));
}
if
(
b3
.
charAt
(
i
)
==
'1'
)
{
result
=
(
int
)
(
result
+
(
1
*
columnMultiplier
));
}
if
(
b3
.
charAt
(
i
)
==
'2'
)
{
result
=
(
int
)
(
result
+
(
2
*
columnMultiplier
));
}
}
return
result
;
}
public
static
int
[]
ConvertBase3ToInt
(
String
[]
b3array
)
{
public
static
int
[]
ConvertBase3ToInt
(
String
[]
b3array
)
{
int
[]
resultsArray
=
new
int
[
b3array
.
length
];
int
[]
resultsArray
=
new
int
[
b3array
.
length
];
for
(
int
i
=
0
;
i
<
b3array
.
length
;
i
++)
{
resultsArray
[
i
]
=
resultsArray
[
i
]
+
ConvertSingb3ToInt
(
b3array
[
i
]);
}
return
resultsArray
;
return
resultsArray
;
...
@@ -237,36 +402,54 @@ public static int Range (int[] input) {
...
@@ -237,36 +402,54 @@ public static int Range (int[] input) {
}
}
public
static
double
StandardDeviation
(
int
[]
input
)
{
public
static
double
StandardDeviation
(
int
[]
input
)
{
double
output
=
0
;
double
output
=
0
;
//mean
double
mean
=
Mean
(
input
);
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
output
=
(
output
+
input
[
i
])/
input
.
length
;
double
result
=
input
[
i
]
-
mean
;
result
=
Math
.
pow
(
result
,
2
);
output
=
output
+
result
;
}
}
int
result
=
0
;
output
=
output
/
(
input
.
length
-
1
);
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
output
=
Math
.
sqrt
(
output
);
result
=
result
+
input
[
i
];
}
output
=
Math
.
sqrt
(((
result
-
output
)*(
result
-
output
)/(
input
.
length
-
1
)));
return
output
;
return
output
;
}
}
public
static
double
HarmonicMean
(
int
[]
input
)
{
public
static
double
HarmonicMean
(
int
[]
input
)
{
double
output
=
0
;
double
output
=
0
;
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
output
=
input
.
length
/(
1
/(
output
+
input
[
i
]));
}
double
inputAsDouble
=
input
[
i
];
output
=
output
+
(
1
/
inputAsDouble
);
}
output
=
input
.
length
/
output
;
return
output
;
return
output
;
}
}
public
static
double
ComplexSumFunctionA
(
int
[]
input
)
{
public
static
double
ComplexSumFunctionA
(
int
[]
input
)
{
double
output
=
0
;
double
output
=
0
;
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
double
index
=
i
;
double
calc
=
0
;
calc
=
input
[
i
];
calc
=
calc
/
2
;
calc
=
Math
.
pow
(
calc
,
(
index
/
2
));
output
=
output
+
calc
;
}
output
=
output
/
(
input
.
length
+
3
);
return
output
;
return
output
;
}
}
...
...
This diff is collapsed.
Click to expand it.
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