Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. const getGets = (arr) => {
  2. let index = 0;
  3.  
  4. return () => {
  5. const toReturn = arr[index];
  6. index += 1;
  7. return toReturn;
  8. };
  9. };
  10. // this is the test
  11. const test = [
  12. "4",
  13. "5",
  14. "1",
  15. "3",
  16. "5"
  17. ];
  18.  
  19. const gets = this.gets || getGets(test);
  20. const print = this.print || console.log;
  21.  
  22. let targets = gets(); // N
  23. let Gs = gets();
  24. let Gl = gets();
  25. let Ps = gets();
  26. let Pl = gets();
  27. let Gtotal = 0;
  28. let Ptotal = 0;
  29.  
  30. Gtotal = (Number(targets) * Number(Gs)) + Number(Gl) + Number(Gl);
  31. Ptotal = (Number(targets) * Number(Ps)) + Number(Pl) + Number(Pl);
  32.  
  33. if (+Gtotal < +Ptotal) print("George");
  34. if (+Ptotal < +Gtotal) print("Peter");
  35. if (+Gtotal == +Ptotal) print("Draw");
  36.  
  37. /*
  38. George and Peter shoot at different speeds and accuracy,
  39. so for example George will hit a target roughly once every Gs seconds, while Peter will need roughy Ps seconds.
  40. So for example, the server sends the targets to George, which takes Gl seconds,
  41. Gosho shoots all targets with his shooting speed, and then the response back to the server take another Gl seconds.
  42. write a program which will determine if George or Peter will win the current round, or there will be a draw.
  43. Input
  44. On the first line - the number N - the number of targets.
  45. On the second line - Gs - George's speed.
  46. On the third line - Gl - George's latency.
  47. On the fourth line - Ps - Peter's speed
  48. On the fifth line Pl - Peter's latency.
  49.  
  50. Output
  51. There is one line of output:
  52. George - if George wins
  53. Peter - if Peter wins
  54. Draw - if the amount it takes is the same for both of them
  55. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement