Advertisement
Neri0817

Sum and product

Apr 18th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sumAndProduct(input) {
  2.     let n = Number(input[0]);
  3.  
  4.     for (let a = 1; a <= 9; a++) {
  5.         for (let b = 9; b >= a; b--) {
  6.             for (let c = 0; c <= 9; c++) {
  7.                 for (let d = 9; d >= c; d--) {
  8.                     let sum = a + b + c + d;
  9.                     let umnojenie = a * b * c * d;
  10.  
  11.                     if (sum == umnojenie && n % 10 == 5) {
  12.                         console.log(`${a}${b}${c}${d}`);
  13.                         return;
  14.                     } else if (umnojenie / sum == 3 && n % 3 == 0) {
  15.                         console.log(`${d}${c}${b}${a}`);
  16.                         return;
  17.                     }
  18.                 }
  19.             }
  20.         }
  21.     }
  22.     console.log("Nothing found");
  23. }
  24. sumAndProduct(["123"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement