Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- let row, col;
- [row, col] = args[0].split(' ').map(Number);
- let rowM = Math.floor(row / 2);
- let colM = Math.floor(col / 2);
- let maze = [];
- for (let i = 0; i < row; i += 1) {
- maze.push(args[i + 1].split(' ').map(Number));
- }
- let escape = false;
- let moveB;
- let numberPos;
- let i;
- let move;
- while (!escape) {
- numberPos = maze[rowM][colM];
- maze[rowM][colM] = -1;
- moveB = false;
- for (i = 0; i < 4 && !moveB; i += 1) {
- move = numberPos & (1 << i);
- if (move !== 0) {
- switch (i) {
- case 0:
- if (rowM - 1 < 0) {
- escape = true;
- moveB = true;
- } else {
- if (maze[rowM - 1][colM] >= 0) {
- rowM -= 1;
- moveB = true;
- }
- }
- break;
- case 1:
- if (colM + 1 === col) {
- escape = true;
- moveB = true;
- } else {
- if (maze[rowM][colM + 1] >= 0) {
- colM += 1;
- moveB = true;
- }
- }
- break;
- case 2:
- if (rowM + 1 === row) {
- escape = true;
- moveB = true;
- } else {
- if (maze[rowM + 1][colM] >= 0) {
- rowM += 1;
- moveB = true;
- }
- }
- break;
- case 3:
- if (colM < 0) {
- escape = true;
- moveB = true;
- } else {
- if (maze[rowM][colM - 1] >= 0) {
- colM -= 1;
- moveB = true;
- }
- }
- default:
- }
- }
- }
- if (!moveB) {
- console.log(`No JavaScript, only rakiya ${rowM} ${colM}`);
- break;
- }
- }
- if (escape) {
- console.log(`No rakiya, only JavaScript ${rowM} ${colM}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement