ErolKZ

Untitled

Sep 30th, 2021
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1.  
  2. let input = [
  3.  
  4. // '3 1 2'
  5.  
  6. '2 6 2'
  7.  
  8. ];
  9.  
  10.  
  11.  
  12.  
  13. let print = this.print || console.log;
  14. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  15.  
  16.  
  17. let nums = gets().split(' ').map(Number);
  18.  
  19. nums.sort((a, b) => b - a);
  20.  
  21. nums = [... new Set(nums)];
  22.  
  23. let counter = 0;
  24.  
  25. let index = 0;
  26.  
  27.  
  28. while (true) {
  29.  
  30.  
  31. nums[index] -= nums[nums.length - 1];
  32.  
  33.  
  34. if (nums[index] === 0) {
  35.  
  36. index++;
  37.  
  38. }
  39.  
  40.  
  41. counter++;
  42.  
  43. if (index === nums.length) {
  44.  
  45. break;
  46.  
  47. }
  48.  
  49. }
  50.  
  51.  
  52.  
  53.  
  54. print(nums);
  55.  
  56. print(counter);
Advertisement
Add Comment
Please, Sign In to add comment