Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* You are given an array of strings. The jumper can be anywhere in the array and is denoted by the 'o' symbol.
- * You need to determine the movement of the jumper in iterations. On each iteration the jumper moves
- * one line down, pulled by gravity. Additionally, the jumper moves sideways by the wind on the current line.
- * The '>' symbol means the wind is moving the jumper one position to the right.
- * The '<' symbol means the wind is moving the jumper one position to the left.
- * The total direction of the wind on a single line may stack (e.g. '>>>' moves the jumper 3 positions to
- * the right; '><<' moves the jumper 1 position to the left).
- * The jumper will never fly off the map!
- * The jumper can move only through 'air' (the '-' symbol). When the jumper hits the ground, water or a cliff,
- * the jump is finished!
- * Your task is to determine how the jumper will finish his jump and where he will land exactly, based on
- * the gravity and wind parameters!
- * The symbols in input strings will not separated by anything!
- * The output should consist of two lines. On the first line you must display 1 of 3 possible messages:
- * If you have landed on the ground ('_' symbol), the message is: "Landed on the ground like a boss!";
- *If you have landed in the water ('~' symbol), the message is: "Drowned in the water like a cat!";
- *If you have landed on a cliff ('/', '\' or '|' symbol), the message is: "Got smacked on the rock like a dog!".
- *The second line holds the position (the row and col, space-separated) of your landing. */
- "use strict";
- function solve(args) {
- var startRow = 0;
- var col = 0;
- for (var row = 0; row < args.length; row += 1) {
- if (args[row].indexOf('o') > -1) {
- startRow = row;
- col = args[row].indexOf('o');
- }
- }
- for (row = startRow + 1; row < args.length; row += 1) {
- var rightMoves = 0;
- var leftMoves = 0;
- for (var j = 0; j < args[row].length; j += 1) {
- if (args[row][j] == '>') {
- rightMoves += 1;
- } else if (args[row][j] == '<') {
- leftMoves += 1;
- }
- }
- col += (rightMoves - leftMoves);
- switch (args[row][col]) {
- case '/':
- case '\\':
- case '|':
- console.log("Got smacked on the rock like a dog!\n%d %d", row, col);
- return;
- case '~':
- console.log("Drowned in the water like a cat!\n%d %d", row, col);
- return;
- case '_':
- console.log("Landed on the ground like a boss!\n%d %d", row, col);
- return;
- }
- }
- }
- solve(['--o----------------------',
- '>------------------------',
- '>------------------------',
- '>-----------------/\\-----',
- '-----------------/--\\----',
- '>---------/\\----/----\\---',
- '---------/--\\--/------\\--',
- '<-------/----\\/--------\\-',
- '\\------/----------------\\',
- '-\\____/------------------']);
- solve(['-------------o-<<--------',
- '-------->>>>>------------',
- '---------------->-<---<--',
- '------<<<<<-------/\\--<--',
- '--------------<--/-<\\----',
- '>>--------/\\----/<-<-\\---',
- '---------/<-\\--/------\\--',
- '<-------/----\\/--------\\-',
- '\\------/--------------<-\\',
- '-\\___~/------<-----------']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement