Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sumAndProduct(input) {
- let num = Number(input[0]);
- let isBreak = false;
- breakpoint:
- for (let i = 1; i < 9; i++) {
- for (let j = 9; j > i; j--) {
- for (let k = 0; k < 9; k++) {
- for (let l = 9; l > k; l--) {
- if ((i + j + k + l) === i * j * k * l && num % 10 == 5) {
- console.log(`${i}${j}${k}${l}`);
- isBreak = true;
- break breakpoint;
- }
- if (parseInt(i * j * k * l / (i + j + k + l)) === 3 && num % 3 == 0) {
- console.log(`${l}${k}${j}${i}`);
- isBreak = true;
- break breakpoint;
- }
- }
- }
- }
- }
- if (!isBreak) {
- console.log("Nothing found");
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- function sumAndProduct(input) {
- let num = Number(input[0]);
- let isBreak = false;
- breakpoint:
- for (let i = 1; i < 9; i++) {
- for (let j = 9; j > i; j--) {
- for (let k = 0; k < 9; k++) {
- for (let l = 9; l > k; l--) {
- if (((i + j + k + l) === i * j * k * l && num % 10 == 5) ||
- (parseInt(i * j * k * l / (i + j + k + l)) === 3 && num % 3 == 0)) {
- console.log((i + j + k + l) === i * j * k * l ? `${i}${j}${k}${l}` : `${l}${k}${j}${i}`);
- isBreak = true;
- break breakpoint;
- }
- }
- }
- }
- }
- if (!isBreak) {
- console.log("Nothing found");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement