Skip to content
  • Home
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Lux)
  • No Skin
Collapse
Ukraine Tryzub and Canada Leaf
  1. UKRAINIANS ON THE CANADA MAP
  2. Categories
  3. Вільне спілкування
  4. (UA) IT/Tech Ukrainians in Canada

(UA) IT/Tech Ukrainians in Canada

Scheduled Pinned Locked Moved Вільне спілкування
647.4k Posts 3.6k Posters 371.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Alex
    wrote on last edited by
    #593238
    вообще это я к тому, что реальным примером из жизни не пахнет
    1 Reply Last reply
    0
  • T Offline
    T Offline
    Alex
    wrote on last edited by
    #593239
    аутпут absoluteValue(addition(addition(16296,78),subtraction(multiplication(-1,5263),40))) absoluteValue(addition(16374,subtraction(multiplication(-1,5263),40))) absoluteValue(addition(16374,subtraction(-5263,40))) absoluteValue(addition(16374,-5303)) absoluteValue(11071) 11071
    1 Reply Last reply
    0
  • T Offline
    T Offline
    Alex
    wrote on last edited by
    #593240
    const operations = { addition(p1, p2) { //console.log(p1, p2, 'addition operation'); return p1 + p2; }, subtraction(p1, p2) { //console.log(p1, p2, 'subtr operation'); return p1 - p2; } , multiplication(p1, p2) { //console.log(p1, p2, 'multi operation'); return p1 * p2; }, absoluteValue(p1) { return Math.abs(p1); } } function calculate(commands) { commands = commands.replaceAll(' ', ''); const regex = /(multiplication|addition|subtraction)\(-?\d+,-?\d+\)/g; const regexAbsolute = /absoluteValue\(-?\d+\)/g; while (!/^\d+$/g.test(commands)) { console.log(commands); let match = commands.match(regex); if (match === null) { match = commands.match(regexAbsolute); } match = [...match][0]; const indexOfParenthesis = match.indexOf('('); const operationType = match.substring(0, indexOfParenthesis); if (operationType in operations) { const parameters = [...match.matchAll(/\((.*)\)$/g)][0][1].split(','); //console.log(parameters, match, 'params'); const value = operations[operationType].apply(null, parameters.map(p => parseInt(p))); commands = commands.replace(match, value); } else { throw new Error('something gone wrong'); } } return commands; } console.log(calculate('absoluteValue(addition(addition(16296,78),subtraction(multiplication(-1,5263),40)))'));
    1 Reply Last reply
    0
  • T Offline
    T Offline
    Alex
    wrote on last edited by
    #593241
    уже потом оффлайн
    1 Reply Last reply
    0
  • T Offline
    T Offline
    Alex
    wrote on last edited by
    #593242
    ну вот я через while сделал за 10 минут.
    1 Reply Last reply
    0
  • t379434605T Offline
    t379434605T Offline
    Gwyn Bleidd 🇺🇦
    wrote on last edited by
    #593243
    Fucktards
    1 Reply Last reply
    0
  • t139189834T Offline
    t139189834T Offline
    Ві тя 🇺🇦
    wrote on last edited by
    #593244
    ну що хто грав як вам
    1 Reply Last reply
    0
  • t139189834T Offline
    t139189834T Offline
    Ві тя 🇺🇦
    wrote on last edited by
    #593245
    +1 задача є на літкоді в якомусь форматі схожому
    1 Reply Last reply
    0
  • t335448128T Offline
    t335448128T Offline
    Duck
    wrote on last edited by
    #593246
    ДА ТЫ ЧО ЕБАТЬ
    1 Reply Last reply
    0
  • T Offline
    T Offline
    Artem K. 🇺🇦
    wrote on last edited by
    #593247
    Атмосферу попередніх сталкерів зберегли, традиційно не забули про баги)) який же сталкер без багів
    1 Reply Last reply
    0
  • T Offline
    T Offline
    Artem K. 🇺🇦
    wrote on last edited by
    #593248
    графоній не дуже, як для гри на сучасному unreal engine. хоча може у них там якась дуже стара версія, навіть повноцінний ray-tracing не завезли, там освітлення це якась не сама нова версія Lumen із UE. А так взагалі, ну це мікс із старих сталкерів, але в новій обгортці. В принципі не погано, але не щось нереально круте.
    1 Reply Last reply
    0
  • T Offline
    T Offline
    Alex
    wrote on last edited by
    #593249
    задача была не юзать евал
    1 Reply Last reply
    0
  • t139189834T Offline
    t139189834T Offline
    Ві тя 🇺🇦
    wrote on last edited by
    #593250
    от класичний розв'язок: function evaluateExpression(expression) { const operations = { add: (a, b) => a + b, subtract: (a, b) => a - b, multiply: (a, b) => a * b, divide: (a, b) => a / b, }; function parseArguments(args) { return args.split(',').map(arg => parseFloat(arg.trim())); } function evaluate(expr) { const stack = []; let currentFunction = ''; let currentArgs = ''; for (let i = 0; i < expr.length; i++) { const char = expr[i]; if (char === '(') { // Start of a function call stack.push({ func: currentFunction.trim(), args: '' }); currentFunction = ''; } else if (char === ')') { // End of a function call const { func, args } = stack.pop(); const resolvedArgs = parseArguments(currentArgs.trim()); const result = operations[func](...resolvedArgs); if (stack.length > 0) { // Append result to the parent's arguments stack[stack.length - 1].args += result + ','; } else { // Return the final result return result; } currentArgs = ''; } else if (char === ',') { // Argument separator if (stack.length > 0) { stack[stack.length - 1].args += currentArgs.trim() + ','; } currentArgs = ''; } else if (stack.length > 0) { // Add to the current argument currentArgs += char; } else { // Collect the function name currentFunction += char; } } throw new Error('Invalid expression'); } return evaluate(expression); } // Example usage const input = "multiply(add(subtract(5, multiply(7, 4)), divide(30, 7)), 7)"; console.log(evaluateExpression(input)); // Outputs the evaluated result
    1 Reply Last reply
    0
  • t139189834T Offline
    t139189834T Offline
    Ві тя 🇺🇦
    wrote on last edited by
    #593251
    те ж саме без eval: function evaluateExpression(expression) { // Define the operations const operations = { add: (a, b) => a + b, subtract: (a, b) => a - b, multiply: (a, b) => a * b, divide: (a, b) => a / b, }; // Recursive function to evaluate the expression function parse(expr) { // Match the innermost function and its arguments const regex = /([a-zA-Z]+)\(([^()]*)\)/; const match = expr.match(regex); if (!match) { // If no more functions, return the number directly return parseFloat(expr); } const [_, func, args] = match; const argValues = args.split(',').map(arg => parse(arg.trim())); if (!(func in operations)) { throw new Error(`Unknown function: ${func}`); } // Compute the result for the current function const result = operations[func](...argValues); // Replace the evaluated function call in the expression const newExpr = expr.replace(match[0], result); return parse(newExpr); // Recursively evaluate the remaining expression } // Start parsing and evaluating return parse(expression); } // Example usage const input = "multiply(add(subtract(5, multiply(7, 4)), divide(30, 7)), 7)"; console.log(evaluateExpression(input)); // Outputs the evaluated result
    1 Reply Last reply
    0
  • t139189834T Offline
    t139189834T Offline
    Ві тя 🇺🇦
    wrote on last edited by
    #593252
    чат жпт вміє в корявий жс: function evaluateExpression(expression) { // Define the mathematical operations const operations = { add: (a, b) => a + b, subtract: (a, b) => a - b, multiply: (a, b) => a * b, divide: (a, b) => a / b, }; // Replace function names with JavaScript syntax const sanitizedExpression = expression.replace( /(add|subtract|multiply|divide)\(/g, (_, fn) => `operations.${fn}(` // Replace with operations object reference ); // Evaluate the sanitized expression try { const result = eval(sanitizedExpression); // Caution: eval can be unsafe return result; } catch (error) { throw new Error(`Invalid expression: ${error.message}`); } } // Example usage const input = "multiply(add(subtract(5, multiply(7, 4)), divide(30, 7)), 7)"; console.log(evaluateExpression(input)); // Outputs the evaluated result
    1 Reply Last reply
    0
  • t385897444T Offline
    t385897444T Offline
    Max Vedeneev
    wrote on last edited by
    #593253
    Якщо я правильно поняв що там відбувається, то це не єффективне рішення
    1 Reply Last reply
    0
  • T Offline
    T Offline
    Alex
    wrote on last edited by
    #593254
    фактически это евал только без него
    1 Reply Last reply
    0
  • T Offline
    T Offline
    Alex
    wrote on last edited by
    #593255
    я дома гляну на классическое решение. хотя мне кажется моё с заменой более простым
    1 Reply Last reply
    0
  • t385897444T Offline
    t385897444T Offline
    Max Vedeneev
    wrote on last edited by
    #593256
    То якась дічь з евалом))
    1 Reply Last reply
    0
  • T Offline
    T Offline
    Alex
    wrote on last edited by
    #593257
    но можно и без регекса так же искать открытые/закрытые скобки, тогда будет быстрее на больших объемах операций
    1 Reply Last reply
    0

  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups