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
a585857a
Commit
a585857a
authored
Dec 06, 2018
by
samuel.boulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
4 questions left
parent
08fe03db
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
111 deletions
+121
-111
Program.java
src/Program.java
+121
-111
No files found.
src/Program.java
View file @
a585857a
...
...
@@ -70,125 +70,81 @@ public class Program {
public
static
int
[]
ConvertBinaryToInt
(
String
[]
binaryArray
)
{
// DONE AND PASSED TEST
int
[]
resultsArray
=
new
int
[
binaryArray
.
length
];
for
(
int
i
=
0
;
i
<
binaryArray
.
length
;
i
++)
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
;
}
/*for(int i = 0; i<wordArray.length; i++) {
resultsArray[i] = ConvertASingleWordToInt(
word
Array[i]);
resultsArray
[
i
]
=
ConvertASingleWordToInt
(
binary
Array
[
i
]);
}*//*
int binTotal = 0;
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')
{
binTotal = binTotal + binCM;
}
binCM = binCM * 2;
}
System.out.println(binTotal);
*//*
char[] binCA = binaryArray[0].toCharArray();
return
resultsArray
;
}
public
static
int
ConvertASingleWordToInt
(
String
someWord
)
{
int binTotal = 0;
int
result
=
0
;
int
binCM
=
1
;
for (int i = 0; i < binCA.length; i++)
char
[]
binChar
=
someWord
.
toCharArray
();
for
(
int
i
=
0
;
i
<
binChar
.
length
;
i
++)
{
int binIndex = binC
A
.length - i - 1;
if (binC
A
[binIndex] == '1')
int
binIndex
=
binC
har
.
length
-
i
-
1
;
if
(
binC
har
[
binIndex
]
==
'1'
)
{
binTotal = binTotal
+ binCM;
result
=
result
+
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
;
}
/*
public static int[] ConvertWordsToInt(String[] wordArray) {
int[] resultsArray = new int[wordArray.length];
public
static
int
[]
ConvertHexToInt
(
String
[]
hexArray
)
{
// DONE AND PASSED TEST
int
[]
resultsArray
=
new
int
[
hexArray
.
length
];
for(int i = 0; i<
word
Array.length; i++) {
for
(
int
i
=
0
;
i
<
hex
Array
.
length
;
i
++)
{
resultsArray[i] = Convert
ASingleWordToInt(word
Array[i]);
resultsArray
[
i
]
=
Convert
HexToInt
(
hex
Array
[
i
]);
}
return
resultsArray
;
}
public static int ConvertASingleWordToInt(String someWord) {
public
static
int
ConvertHexToInt
(
String
hexWord
)
{
int
result
=
0
;
if(someWord == "eleven") {result = 11;}
int
hexCM
=
1
;
char
[]
hexChar
=
hexWord
.
toCharArray
();
for
(
int
i
=
0
;
i
<
hexChar
.
length
;
i
++)
{
int
hexIndex
=
hexChar
.
length
-
i
-
1
;
if
(
hexChar
[
hexIndex
]
==
'1'
)
{
result
=
result
+
(
hexCM
*
1
);}
if
(
hexChar
[
hexIndex
]
==
'2'
)
{
result
=
result
+
(
hexCM
*
2
);}
if
(
hexChar
[
hexIndex
]
==
'3'
)
{
result
=
result
+
(
hexCM
*
3
);}
if
(
hexChar
[
hexIndex
]
==
'4'
)
{
result
=
result
+
(
hexCM
*
4
);}
if
(
hexChar
[
hexIndex
]
==
'5'
)
{
result
=
result
+
(
hexCM
*
5
);}
if
(
hexChar
[
hexIndex
]
==
'6'
)
{
result
=
result
+
(
hexCM
*
6
);}
if
(
hexChar
[
hexIndex
]
==
'7'
)
{
result
=
result
+
(
hexCM
*
7
);}
if
(
hexChar
[
hexIndex
]
==
'8'
)
{
result
=
result
+
(
hexCM
*
8
);}
if
(
hexChar
[
hexIndex
]
==
'9'
)
{
result
=
result
+
(
hexCM
*
9
);}
if
(
hexChar
[
hexIndex
]
==
'A'
)
{
result
=
result
+
(
hexCM
*
10
);}
if
(
hexChar
[
hexIndex
]
==
'B'
)
{
result
=
result
+
(
hexCM
*
11
);}
if
(
hexChar
[
hexIndex
]
==
'C'
)
{
result
=
result
+
(
hexCM
*
12
);}
if
(
hexChar
[
hexIndex
]
==
'D'
)
{
result
=
result
+
(
hexCM
*
13
);}
if
(
hexChar
[
hexIndex
]
==
'E'
)
{
result
=
result
+
(
hexCM
*
14
);}
if
(
hexChar
[
hexIndex
]
==
'F'
)
{
result
=
result
+
(
hexCM
*
15
);}
hexCM
=
hexCM
*
16
;
}
return
result
;
}
*/
public
static
int
[]
ConvertHexToInt
(
String
[]
hexArray
)
{
int
[]
resultsArray
=
new
int
[
hexArray
.
length
];
// same on this question
return
resultsArray
;
}
...
...
@@ -253,8 +209,6 @@ public class Program {
resultsArray
[
i
]
=
intersectList
.
get
(
i
);
}
return
resultsArray
;
}
public
static
int
[]
Difference
(
int
[]
intArrayA
,
int
[]
intArrayB
)
{
...
...
@@ -262,22 +216,25 @@ public class Program {
ArrayList
<
Integer
>
differenceList
=
new
ArrayList
<
Integer
>();
for
(
int
j
=
0
;
j
<
intArrayA
.
length
;
j
++)
for
(
int
i
=
0
;
i
<
intArrayA
.
length
;
i
++)
{
for
(
int
k
=
0
;
k
<
intArrayB
.
length
;
k
++)
differenceList
.
add
(
intArrayA
[
i
]);
}
for
(
int
j
=
0
;
j
<
intArrayB
.
length
;
j
++)
{
differenceList
.
add
(
intArrayB
[
j
]);
}
for
(
int
k
=
0
;
k
<
differenceList
.
size
();
k
++)
{
for
(
int
l
=
0
;
l
<
intArrayB
.
length
;
l
++)
{
if
(
intArrayA
[
j
]
!=
intArrayB
[
k
])
if
(
differenceList
.
get
(
k
)
==
intArrayB
[
l
])
{
differenceList
.
add
(
intArrayA
[
j
]
);
differenceList
.
remove
(
k
);
}
}
}
int
[]
resultsArray
=
new
int
[
differenceList
.
size
()];
for
(
int
i
=
0
;
i
<
differenceList
.
size
();
i
++)
{
...
...
@@ -287,10 +244,6 @@ public class Program {
return
resultsArray
;
}
public
static
int
Sum
(
int
[]
input
)
{
int
result
=
0
;
...
...
@@ -323,16 +276,57 @@ public class Program {
return
output
/
input
.
length
;
}
public
static
int
[]
ConvertBase20ToInt
(
String
[]
b20array
)
{
// DONE AND PASSED TEST
int
[]
resultsArray
=
new
int
[
b20array
.
length
];
for
(
int
i
=
0
;
i
<
b20array
.
length
;
i
++)
{
resultsArray
[
i
]
=
Convert20ToInt
(
b20array
[
i
]);
}
return
resultsArray
;
}
public
static
int
Convert20ToInt
(
String
twentyWord
)
{
int
result
=
0
;
int
hexCM
=
1
;
char
[]
hexChar
=
twentyWord
.
toCharArray
();
for
(
int
i
=
0
;
i
<
hexChar
.
length
;
i
++)
{
int
hexIndex
=
hexChar
.
length
-
i
-
1
;
if
(
hexChar
[
hexIndex
]
==
'0'
)
{
result
=
result
+
(
hexCM
*
0
);}
if
(
hexChar
[
hexIndex
]
==
'1'
)
{
result
=
result
+
(
hexCM
*
1
);}
if
(
hexChar
[
hexIndex
]
==
'2'
)
{
result
=
result
+
(
hexCM
*
2
);}
if
(
hexChar
[
hexIndex
]
==
'3'
)
{
result
=
result
+
(
hexCM
*
3
);}
if
(
hexChar
[
hexIndex
]
==
'4'
)
{
result
=
result
+
(
hexCM
*
4
);}
if
(
hexChar
[
hexIndex
]
==
'5'
)
{
result
=
result
+
(
hexCM
*
5
);}
if
(
hexChar
[
hexIndex
]
==
'6'
)
{
result
=
result
+
(
hexCM
*
6
);}
if
(
hexChar
[
hexIndex
]
==
'7'
)
{
result
=
result
+
(
hexCM
*
7
);}
if
(
hexChar
[
hexIndex
]
==
'8'
)
{
result
=
result
+
(
hexCM
*
8
);}
if
(
hexChar
[
hexIndex
]
==
'9'
)
{
result
=
result
+
(
hexCM
*
9
);}
if
(
hexChar
[
hexIndex
]
==
'A'
)
{
result
=
result
+
(
hexCM
*
10
);}
if
(
hexChar
[
hexIndex
]
==
'B'
)
{
result
=
result
+
(
hexCM
*
11
);}
if
(
hexChar
[
hexIndex
]
==
'C'
)
{
result
=
result
+
(
hexCM
*
12
);}
if
(
hexChar
[
hexIndex
]
==
'D'
)
{
result
=
result
+
(
hexCM
*
13
);}
if
(
hexChar
[
hexIndex
]
==
'E'
)
{
result
=
result
+
(
hexCM
*
14
);}
if
(
hexChar
[
hexIndex
]
==
'F'
)
{
result
=
result
+
(
hexCM
*
15
);}
if
(
hexChar
[
hexIndex
]
==
'G'
)
{
result
=
result
+
(
hexCM
*
16
);}
if
(
hexChar
[
hexIndex
]
==
'H'
)
{
result
=
result
+
(
hexCM
*
17
);}
if
(
hexChar
[
hexIndex
]
==
'I'
)
{
result
=
result
+
(
hexCM
*
18
);}
if
(
hexChar
[
hexIndex
]
==
'J'
)
{
result
=
result
+
(
hexCM
*
19
);}
hexCM
=
hexCM
*
20
;
}
return
result
;
}
...
...
@@ -371,19 +365,35 @@ public static int Range (int[] input) {
public
static
int
[]
ConvertBase3ToInt
(
String
[]
b3array
)
{
// DONE AND PASSED TEST
int
[]
resultsArray
=
new
int
[
b3array
.
length
];
for
(
int
i
=
0
;
i
<
b3array
.
length
;
i
++)
{
resultsArray
[
i
]
=
Convert3ToInt
(
b3array
[
i
]);
}
return
resultsArray
;
}
public
static
int
Convert3ToInt
(
String
someWord
)
{
int
result
=
0
;
int
binCM
=
1
;
char
[]
binChar
=
someWord
.
toCharArray
();
for
(
int
i
=
0
;
i
<
binChar
.
length
;
i
++)
{
int
binIndex
=
binChar
.
length
-
i
-
1
;
if
(
binChar
[
binIndex
]
==
'1'
)
{
result
=
result
+
binCM
;}
if
(
binChar
[
binIndex
]
==
'2'
)
{
result
=
result
+
(
binCM
*
2
);}
binCM
=
binCM
*
3
;
}
return
result
;
}
...
...
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