Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >> Military Tanks
- const input = ['UDLRRR'];
- const print = this.print || console.log;
- const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- /* Задача 1: Military Tanks
- Military scientists are training battle tanks using artificial intelligence. The first lesson is to teach them to move across the (x,y) - plane. They give them a sequence of moves and observe whether the tanks get to the correct (x, y) position on the field.
- This sequence is represented by string, and the character at position i represents the tank’s i-th move.
- There are several commands – R – moves right, L – moves left, U – moves up and D – moves down.
- To help the scientists, you have to write a program that collects the learning results of the tanks.
- + танкът започва движение с координати 0, 0 - това се виждаше и от картинката */
- const iMove = gets().split(''); // [ 'U', 'D', 'L', 'R', 'R', 'R' ]
- let x = 0;
- let y = 0;
- for (let i = 0; i < iMove.length; i++) {
- if (iMove[i] === 'U') {
- y += 1;
- } else if (iMove[i] === 'D') {
- y -= 1;
- } else if (iMove[i] === 'L') {
- x -= 1;
- } else if (iMove[i] === 'R') {
- x += 1;
- }
- }
- print(`(${x}, ${y})`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement