-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavascript.js
48 lines (48 loc) · 1.15 KB
/
Javascript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
let str = ""; //
for (let i = 0; i < 3; i++) {
// build a string with the positions of the dice
str += readline().replace(" ", ""); //
} //
let commands = readline();
let myPos = [str[2]];
let front = [str[0]];
let behind = [str[5]];
let left = [str[1]];
let right = [str[3]];
let opposite = [str[4]]; //Dice variable
for (let i = 0; i < commands.length; i++) {
//
switch (
commands[i] //
) {
case "U": //
swap(myPos, front); //
swap(front, behind); //
swap(front, opposite); //
break; //
case "L": // Process Walk on the dice
swap(myPos, left); //
swap(left, behind); //
swap(right, front); //
swap(front, opposite); //
break; //
case "D": //
swap(myPos, behind); //
swap(left, right); //
swap(front, opposite); //
break; //
case "R": //
swap(myPos, right); //
swap(right, behind); //
swap(left, front); //
swap(front, opposite); //
break; //
} //
} //
console.log(myPos[0]);
function swap(a, b) {
//
let temp = a[0]; // function for swap
a[0] = b[0]; // i pass 2 array as input
b[0] = temp; // because they are references
} //