Advertisement
ErolKZ

Untitled

Jul 19th, 2021
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4. let n = input[0];
  5.  
  6. let nLast = Number(n[n.length - 1]);
  7.  
  8. let a = 1;
  9.  
  10. let b = 9;
  11.  
  12. let c = 0;
  13.  
  14. let d = 9;
  15.  
  16. let sum = 0;
  17.  
  18. let multiply = 0;
  19.  
  20. let division = 0;
  21.  
  22. let counter = 0;
  23.  
  24.  
  25. label:
  26.  
  27. for (let a = 1; a <= 9; a++) {
  28.  
  29.  
  30.  
  31. for (let b = 9; b >= a; b--) {
  32.  
  33.  
  34.  
  35.  
  36. for (let c = 1; c <= 9; c++) {
  37.  
  38.  
  39.  
  40.  
  41. for (let d = 8; d >= c; d--) {
  42.  
  43.  
  44.  
  45.  
  46. sum = a + b + c + d;
  47.  
  48. multiply = a * b * c * d;
  49.  
  50. division = Math.floor(multiply / 19);
  51.  
  52.  
  53. if (sum === multiply && nLast === 5) {
  54.  
  55.  
  56. console.log(`${a}${b}${c}${d}`);
  57.  
  58. counter += 1;
  59.  
  60. break label;
  61.  
  62. } else if (division === 3 && Number(n) % 3 === 0) {
  63.  
  64. console.log(`${d}${c}${b}${a}`);
  65.  
  66. counter += 1;
  67.  
  68. break label;
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. }
  78.  
  79.  
  80. }
  81.  
  82. }
  83.  
  84. }
  85.  
  86.  
  87.  
  88.  
  89. if (counter === 0) {
  90.  
  91. console.log(`Nothing found`);
  92.  
  93.  
  94. }
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101. }
  102.  
  103. solve([
  104.  
  105. // '123'
  106.  
  107. '145'
  108.  
  109. ]);
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement