alboig

Forest Road - Javascript Tasks2

Apr 14th, 2020
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Forest Road
  2. // Geeko, a non-stop learning trainee at Telerik Software Academy lived deep into the Lyulin forests. Every time he went to the Academy he had to take a long trip through the forest. Starting from the top left corner of the forest, the road always goes down and right first and when it reaches the border, it goes down and left.
  3. // The Academy is situated in the bottom left corner, and Geeko begins his journey from the top left corner of the forest (see the examples below).
  4. // He wanted to make a program that generates a map of the forest but he couldn’t. Help Geeko on his way to the Academy by writing the program instead of him.
  5. // Input
  6. // Read from the standard input
  7. // On the only line in the console you are given an integer number N, showing the width of the map.
  8. // The map’s height is always 2*N - 1.
  9. // The input data will always be valid and in the format described. There is no need to check it explicitly.
  10. // Output
  11. // Print to the standard output
  12. // You should print the whole map on the standard output
  13. // Use the symbol “*” (asterisk) to mark Geeko’s path and “.” (dot) to illustrate the trees
  14. // Constraints
  15. // The number N is a positive integer between 2 and 79, inclusive.
  16. // Allowed working time for your program: 0.25 second.
  17. // Input Output
  18. // 4
  19. // *...
  20. // .*..
  21. // ..*.
  22. // ...*
  23. // ..*.
  24. // .*..
  25. // *...
  26.  
  27. // 5
  28. // *....
  29. // .*...
  30. // ..*..
  31. // ...*.
  32. // ....*
  33. // ...*.
  34. // ..*..
  35. // .*...
  36. // *....
  37. const input = ['79'];
  38. const print = this.print || console.log;
  39. const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  40. const forestNumber = +gets();
  41. for (let i = 0; i <= forestNumber - 1; i++) {
  42.   const downRight = [];
  43.   for (let j = 0; j <= forestNumber - 1; j++) {
  44.     downRight.push('.');
  45.   }
  46.   downRight[i] = '*';
  47.   print(downRight.join(''));
  48. }
  49. for (let i = 0; i <= forestNumber - 2; i++) {
  50.   const downLeft = [];
  51.   for (let j = 0; j <= forestNumber - 1; j++) {
  52.     downLeft.push('.');
  53.   }
  54.   downLeft[forestNumber - i - 2] = '*';
  55.   print(downLeft.join(''));
  56. }
Advertisement
Add Comment
Please, Sign In to add comment