From b9ad30f3928bb2d3487e13bb3dc6c2c3b4fcfd31 Mon Sep 17 00:00:00 2001 From: npminit-dev Date: Fri, 29 Sep 2023 10:04:10 -0300 Subject: [PATCH 1/3] Reto #38 - JavaScript --- .../javascript/npminit-dev.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Retos/Reto #38 - LAS SUMAS [Media]/javascript/npminit-dev.js b/Retos/Reto #38 - LAS SUMAS [Media]/javascript/npminit-dev.js index 8ab574c347..2dcd62428e 100644 --- a/Retos/Reto #38 - LAS SUMAS [Media]/javascript/npminit-dev.js +++ b/Retos/Reto #38 - LAS SUMAS [Media]/javascript/npminit-dev.js @@ -15,15 +15,14 @@ function getSumsLists(list, target) { let sList = list.filter(num => num <= target).sort() let result = [] - function backTracking(sub, start) { - let sum = sub?.reduce((acc, curr) => acc += curr, 0) || 0 + function backTracking(sub, start, sum) { if(sum === target) result.push(sub) for(let i = start; i < sList.length; i++) - if(sum + list[i] <= target) backTracking([...sub, list[i]], i + 1) + if(sum + list[i] <= target) backTracking([...sub, list[i]], i + 1, sum + list[i]) } for(let i = 0; i < sList.length - 1; i++) - backTracking([list[i]], i + 1) + backTracking([list[i]], i + 1, list[i]) return result } @@ -35,6 +34,6 @@ console.log(getSumsLists([3, 2, 1, 6, 8, 4, 3, 10], 12)) console.log(getSumsLists([3, 6, 9, 12, 15], 30)) /* result = [[ 3, 6, 9, 12 ], [ 3, 12, 15 ], [ 6, 9, 15 ]] */ console.log(getSumsLists([15, 10, 5, 2, 8, 10], 50)) -/* result = [[ 3, 6, 9, 12 ], [ 3, 12, 15 ], [ 6, 9, 15 ]] */ +/* result = [[15, 10, 5, 2, 8, 10]] */ console.log(getSumsLists([1, 2, 3, 2, 1], 3)) -/* result = [[ 3, 6, 9, 12 ], [ 3, 12, 15 ], [ 6, 9, 15 ]] */ +/* result = [[ 1, 2 ], [ 1, 2 ], [ 2, 1 ], [ 3 ], [ 2, 1 ]] */ From 956731dc08e8b89438f073acd7e478dad67e98f6 Mon Sep 17 00:00:00 2001 From: Jorge Antonio Balsamo Date: Thu, 23 Nov 2023 02:20:12 -0300 Subject: [PATCH 2/3] Reto #44 - javascript --- .../javascript/npminit-dev.js" | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 "Retos/Reto #44 - ADIVINANZAS MATEM\303\201TICAS [Media]/javascript/npminit-dev.js" diff --git "a/Retos/Reto #44 - ADIVINANZAS MATEM\303\201TICAS [Media]/javascript/npminit-dev.js" "b/Retos/Reto #44 - ADIVINANZAS MATEM\303\201TICAS [Media]/javascript/npminit-dev.js" new file mode 100644 index 0000000000..a44c522508 --- /dev/null +++ "b/Retos/Reto #44 - ADIVINANZAS MATEM\303\201TICAS [Media]/javascript/npminit-dev.js" @@ -0,0 +1,79 @@ +const readline = require('readline') + +let questCount = 1 +let correct = 0 +const ops = ['+', '-'] + +const createIF = (readline) => readline.createInterface({ + input: process.stdin, + output: process.stdout +}) + +const getOperation = (ops, quesCount) => { + const op = ops[Math.round(Math.random() * (ops.length - 1))] + let left + let right + if(quesCount <= 5) { + left = Math.round(Math.random() * 9) + right = Math.round(Math.random() * 9) + } else if(quesCount > 5 && quesCount <= 10) { + left = Math.round(Math.random() * 90) + right = Math.round(Math.random() * 9) + } else if(quesCount > 10 && quesCount <= 15) { + left = Math.round(Math.random() * 99) + right = Math.round(Math.random() * 99) + } else { + left = Math.round(Math.random() * 999) + right = Math.round(Math.random() * 99) + } + return [ + `${left}${op}${right}`, + eval(`Math.trunc(${left}${op}${right})`) + ] +} + +console.clear() +console.log( +` ---- MATH OPS GAME ---- +All result must be rounded to nearest the integer +3 seconds contown per question...`) + +const question =() => { + return new Promise((res, rej) => { + let rl = createIF(readline) + let [opstring, expect] = getOperation(ops, questCount) + rl.question( + `- Question ${questCount}: + Which is the result of ${opstring}?\n`, (result) => { + if(parseInt(result) === expect) correct++ + rl.close() + console.clear() + res('') + }) + setTimeout(() => { + rl.close() + rej('') + }, 3000) + }) +} + +setTimeout(async () => { + console.clear() + while(questCount <= 20) { + try { await question() } + catch(_) { break } + questCount ++ + } + console.clear() + console.log(` + GAME END!!! + Correct answers: ${correct}/20 + ${correct <= 10 ? + 'Meh... better luck next time' : + correct > 10 && correct <= 15 ? + 'Not bad, but you can improve' : + correct > 15 && correct <= 19 ? + 'Great work!' : 'Perfect!!!' + }`) + process.exit(0) +}, 4000) From 182dd31eca0c8b2a29f7c3571b3f7dcfc1377cd3 Mon Sep 17 00:00:00 2001 From: Jorge Antonio Balsamo Date: Thu, 23 Nov 2023 05:47:50 -0300 Subject: [PATCH 3/3] Correciones minimas --- .../javascript/npminit-dev.js" | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git "a/Retos/Reto #44 - ADIVINANZAS MATEM\303\201TICAS [Media]/javascript/npminit-dev.js" "b/Retos/Reto #44 - ADIVINANZAS MATEM\303\201TICAS [Media]/javascript/npminit-dev.js" index a44c522508..c965774ec6 100644 --- "a/Retos/Reto #44 - ADIVINANZAS MATEM\303\201TICAS [Media]/javascript/npminit-dev.js" +++ "b/Retos/Reto #44 - ADIVINANZAS MATEM\303\201TICAS [Media]/javascript/npminit-dev.js" @@ -2,7 +2,7 @@ const readline = require('readline') let questCount = 1 let correct = 0 -const ops = ['+', '-'] +const ops = ['+', '-', '*', '/'] const createIF = (readline) => readline.createInterface({ input: process.stdin, @@ -34,9 +34,9 @@ const getOperation = (ops, quesCount) => { console.clear() console.log( -` ---- MATH OPS GAME ---- -All result must be rounded to nearest the integer -3 seconds contown per question...`) +` <--- MATH OPS GAME ---> +All results must be rounded to the nearest integer +3 seconds contdown per question...`) const question =() => { return new Promise((res, rej) => {