I would like to write a code (in javascript) that solves this problem:
The 24 Game tests a person’s mental arithmetic.
The aim of the game is to arrange four numbers in a way that when evaluated, the result is 24
Implement a function that takes a string of four digits as its argument, with each digit from 1 to 9 (inclusive) with repetitions allowed, and returns an arithmetic expression that evaluates to the number 24. If no such solution exists, return “no solution exists”.
Rules:
Only the following operators/functions are allowed: multiplication, division, addition, subtraction.
Division should use floating point or rational arithmetic, etc, to preserve remainders.
Forming multiple digit numbers from the supplied digits is disallowed. (So an answer of 12+12 when given 1, 2, 2, and 1 is wrong).
The order of the digits when given does not have to be preserved.
Can sb explain the way how to achieve it and then I can write the code?
thanks:)
Levente Lencses is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.