QUESTION

import java.util.*;

public class Puzzle {

private static Map<String, Integer> checkList = new HashMap<String, Integer>();

public static void main(String[] args) {

int[] inputList = new int[7];

Scanner input = new Scanner(System.in);

int count = 0;

while(input.hasNextInt()) {

inputList[count] = input.nextInt();

count++;

}

int[][][][] finalOutput = new int[7][3][3][3];

int[][][] workPlace = new int[3][3][3];

ThreeDMatrix shap = new ThreeDMatrix();

int x = 0;

int n = 7;

for(int i = 0; i < count; i++) {

System.err.println(inputList[i]);

}

//System.err.println(shap.toString(shap.startpoint(shap.RotaZ(shap.ValueOf(3)))));

while(x < count) {

try{

if(moveP(inputList, workPlace, x, shap) != null){

int[][][]seek = add(moveP(inputList, workPlace, x, shap), workPlace);

if(checkL(seek)) {

workPlace = seek;

finalOutput[x] = workPlace;

checkList.put(shap.toString(workPlace), x);

x++;

} else {

x–;

workPlace = finalOutput[x];

}

} else {

x = x-1;

workPlace = finalOutput[x];

}

} catch(ArrayIndexOutOfBoundsException e) {

System.err.println(“this is not right one.”);

break;

}

}

System.out.println(printFinal(finalOutput));

}

public static int[][][] moveP(int[] inputlist, int[][][] workPlace, int num, ThreeDMatrix shap) {

int[][][] output = shap.ValueOf(inputlist[num]);

//System.out.println(“output is ” + shap.toString(output));

//System.out.println(“num is ” + num + “\noutput is \n” + shap.toString(output));

for(int l = 0; l < 3; l++) {

output = shap.moveZ(output, l);

for(int i = 0; i < 12; i++) {

output = shap.moveR(output, i);

for(int j = 0; j < 3; j++) {

output = shap.moveY(output, j);

for(int k = 0; k < 3; k++) {

output = shap.moveX(output, k);

int[][][] seek = add(workPlace, output);

if(check(seek) && !checkList.containsKey(shap.toString(seek))) {

System.out.println(“output is\n” + shap.toString(output));

return output;

}

}output = shap.startpoint(output);

}output = shap.startpoint(output);

}output = shap.startpoint(output);

}

return null;

}

public static int[][][] add(int[][][] list1, int[][][] list2) {

int[][][] output = new int[3][3][3];

for(int i = 0; i < 3; i++) {

for(int j = 0; j < 3; j++) {

for(int k = 0; k < 3; k++) {

output[i][j][k] = list1[i][j][k] + list2[i][j][k];

}

}

}

return output;

}

public static boolean check(int[][][] list) {

int x = 2;

for(int i = 0; i < 3; i++) {

for(int j = 0; j < 3; j++) {

for(int n = 0; n < 3; n++) {

if( list[i][j][n] >= x) {

return false;

}

}

}

}

return true;

}

public static boolean checkL(int[][][] list) {

int x = 0;

int y = 1;

for(int j = 0; j < 3; j++) {

for(int n = 0; n < 3; n++) {

if((list[0][j][n] == x && list[1][j][n] == y)|| (list[1][j][n] == x && list[2][j][n] == y)) {

return false;

}

}

}

return true;

}

public static String printFinal(int[][][][] finalOutput) {

String output = “”;

for(int k = 0; k < 7; k++) {

for(int i = 0; i < 3; i++) {

for(int j = 0; j < 3; j++) {

for(int n = 0; n < 3; n++) {

output += finalOutput[k][i][j][n] + ” “;

}

output += “\n”;

}

}output += “\n”;

}

return output;

}

}

SOLUTION

1. On paper perform the following calculations in the required number systems:

(a) In decimal add and then multiply 839 and 926

839 + 926 = 1765.

839 * 926 = 776914.

(b) In binary add and then multiply 111 and 110

In binary addition

X |
Y |
Sum |
Carry |

0 |
0 |
0 |
0 |

0 |
1 |
1 |
0 |

1 |
0 |
1 |
0 |

1 |
1 |
0 |
1 |

Carry à 1

111

+110

——————

1101

Multiplication in binary –

111 * 110 = 101010

(c) In hexadecimal add and then multiply F6D and 5A7

F6D is 15 06 13

5A7 is 05 10 07

Next, I translated everything into base 10. So F6D in base 10 is

15*256 + 06*16 + 13*1 = 3949 and similarly, 5A7 in base 10

is 1447.

Their sum is 5396 in base 10.

And 1514 in Hexadecimal.

4069 256 16 1

———————–

1 5 1 4

Then I converted the results into hexadecimal notation and got 1514.

Multiplication in Hexadecimal –

F6D * 5A7 = 57311B

In decimal it would be 5714203.

2. Write a program that can add two numbers in any given base between base 2 and base 10. Your program must prompt the user for the base, and the two numbers to be added. Numbers may be up to 100 digits long. You may not use packages such as Java’s “BigInteger”.

Ans. See the attached files for working program in Java.

- The program is capable of Adding Binary(base 2), Decimal (base 10) and Hexadecimal (base 16) numbers of variable lengths.
- The hexadecimal addition is done by first converting hexadecimal to binary (i.e. base 2) and then adding it in binary notation. Answer is then converted back to Hexadecimal (i.e. base 16).
- For complete working please see the Java code in the zip file.

LA34

But you can order it from our service and receive complete high-quality custom paper. Our service offers Technology essay sample that was written by professional writer. If you like one, you have an opportunity to buy a similar paper. Any of the academic papers will be written from scratch, according to all customers’ specifications, expectations and highest standards.”