-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (40 loc) · 1.12 KB
/
index.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
49
50
const fs = require('fs');
const rov = require('./src/rover');
//import comands
fs.readFile('./input.txt', (err, data) => {
if (err) {
console.log(err);
return;
}
//prepare comands
const comands = data.toString();
let comandLines = comands.trim().split('\n');
comandLines = comandLines.filter((comandLine) => {
return comandLine.trim() !== '';
});
let output = [];
//5 5
let input = readLine(comandLines, 0);
const rover = new rov(input[0], input[1]);
//1 2 N
input = readLine(comandLines, 1);
rover.setPosition(input[0], input[1], input[2]);
//LMLMLMLMM
input = readLine(comandLines, 2);
rover.processRover(input[0]);
output.push(rover.printPosition());
//3 3 E
input = readLine(comandLines, 3);
rover.setPosition(input[0], input[1], input[2]);
//MMRMMRMRRM
input = readLine(comandLines, 4);
rover.processRover(input[0]);
output.push(rover.printPosition());
//result
output.map((x) => {
console.log(x.toString());
});
});
function readLine(data, line) {
return data[line].replace(/\n|\r/g, '').split(' ');
}