A question that I am stuck on

The1thatAsks

New member
Joined
Nov 12, 2020
Messages
1
can someone do this without negative numbers you can fill the squares with + - : * and you can add brackets for example (1+2) you can also remove the squares so you will have 23 instead of 2[]3 thanks for the help!

unknown.png
 
The numbers add up to 8, an even number, so only changing some + to - will not help. Hmm?
 
I’m not sure we know what the entire list of permitted operations is or what brackets can be used.

[MATH]\left \lfloor \ \dfrac{1}{2} \ \right \rfloor + 3 + 4 = 7.[/MATH]
 
Some original posts do contain mistakes, heh. Otherwise, it looks like we may place one of the four given arithmetic operators in each box (I'm thinking the colon represents ÷).

Instead of filling in a box, it looks like we may remove it, concatenating the digits on either side.

It looks like we may add as many grouping symbols as we desire.

?
 
I couldn't figure this out, so I did what I always do when I can't figure it out: I made a computer do it. It considers the following operations:
  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Concatenation
It considers every possible assortment of grouping with parentheses.

It did not find any matching results, even when I allowed negative numbers.

Granted, I may have done something wrong, as this isn't an easy problem to write a program for. But for now, I'm willing to go on record saying it can't be done with the above set of operations.

Here's my code, if anyone's curious. Caution: it's tricky!
JavaScript:
// Concatenate the digits of two numbers
function concatenate(a, b) {

    // To get some kind of meaningful result from negative numbers, take the
    // exclusive OR of the operands' signs
    let sign = Math.sign(a) * Math.sign(b);

    // Alias the operands as positive numbers
    a = Math.abs(a);
    b = Math.abs(b);

    // Calculate the number of digits in the right operand
    let digits = b == 0 ? 1 : Math.floor(Math.log(b) / Math.LN10 + 1);

    // Shift the left operand the number of digits and incorporate the sign
    return sign * (a * Math.pow(10, digits) + b);
}

// Conceptual operation descriptor
let Operation = function(type, precedence) {
    this.precedence = precedence;
    this.text       = Operation.TEXT[type];
    this.type       = type;
};

// Evaluate the operation
Operation.prototype.evaluate = function() {
    let a = typeof this.left  == "number" ? this.left  : this.left .evaluate();
    let b = typeof this.right == "number" ? this.right : this.right.evaluate();
    if (a === null || b === null)
        return null;
    let ret = Operation.EVAL[this.type](a, b);
    return ret; // Comment this line to restrict to non-negative integers
    return ret < 0 || ret != Math.floor(ret) ? null : ret;
};

// Format the operation as a string
Operation.prototype.print = function() {
    let a = typeof this.left  == "number" ? this.left  : this.left .print();
    let b = typeof this.right == "number" ? this.right : this.right.print();
    return "(" + a + " " + this.text + " " + b + ")";
};

// Evaluation by type
Operation.EVAL = [
    (a,b)=> a + b, // Add
    (a,b)=> a - b, // Subtract
    (a,b)=> a * b, // Multiply
    (a,b)=> a / b, // Divide
    (a,b)=> concatenate(a, b)
];

// Operator text
Operation.TEXT = [ "+", "-", "*", "/", "||" ];

// Operator types
Operation.ADD         = 0;
Operation.SUBTRACT    = 1;
Operation.MULTIPLY    = 2;
Operation.DIVIDE      = 3;
Operation.CONCATENATE = 4;

// Precedence ordering
let PRECEDENCE = [
    [ 2, 1, 0 ],
    [ 2, 0, 1 ],
    [ 1, 2, 0 ],
    [ 1, 0, 2 ],
    [ 0, 2, 1 ],
    [ 0, 1, 2 ]
];

// Extract left and right nodes in the expression for an operation
function node(nodes, offset, operation) {
    let node      = Object.create(operation);
    node.right    = nodes.splice(offset + 1)[0];
    node.left     = nodes[offset];
    nodes[offset] = node;
}

// Process all combinations of operations
for (let x = 0; x < 5; x++)
for (let y = 0; y < 5; y++)
for (let z = 0; z < 5; z++)
for (let p of PRECEDENCE) {

    // Produce operation objects for the current combination
    let nodes = [
        1,
        new Operation(x, p[0]),
        2,
        new Operation(y, p[1]),
        3,
        new Operation(z, p[2]),
        4
    ];

    // Build an expression tree using the order of precedence
    let nodes = [ 1, ops[0], 2, ops[1], 3, ops[2], 4 ];
    for (let a = 2; a >= 0; a--) {
        for (let n = 0; n < nodes.length; n++) {
            let node = nodes[n];
            if (node.precedence != a)
                continue;
            node.right = nodes.splice(n + 1, 1)[0];
            node.left  = nodes.splice(--n  , 1)[0];
            break;
        }
    }

    // Evaluate the expression
    if (nodes[0].evaluate() == 7)
        console.log(nodes[0].print(), nodes[0].evaluate());
}

// Processing has completed
console.log("Done");
 
… [could] not find any matching results, even when I allowed negative numbers.
I don't know what the OP means, by mentioning the use of negative numbers. None of the given numbers are negative, and only arithmetic operators are allowed in the boxes.

:confused:
 
The1thatAsks, why are you allowing subtraction!?

[MATH]1 + 2 * 3 - 4[/MATH] does not produce any negative numbers.

I don't know what the OP means, by mentioning the use of negative numbers.

If you start with [MATH]1 - 2[/MATH], for instance, the partial evaluation would be negative. That's what I interpreted it to mean.
 
In the past some helpers here put a negative (not a subtraction) sign in front of the first number to get an answer. I suspect that you can't do it this time.
 
In the past some helpers here put a negative (not a subtraction) sign in front of the first number to get an answer. I suspect that you can't do it this time
 
Unary negation is an operator too! And there's only room in the box for one operator.
 
The list of allowable operators does not include that one.

;)
I see no reason to assume that the OP gave an accurate rendition of the puzzle.

According to Mr. Bland, if the only operations allowed are addition, subtraction, multiplication, division, and string concatenation, the puzzle is unsolvable. We should either prove Mr. Bland is wrong or stop squabbling about a meaningless puzzle.

There are only six concatenations possible.

With respect to the two possible three-digit concatenations, that leaves open only eight possibilities.
With respect to the four possible two-digit concatenations, that leaves open fifty-two possibilities. Without concatenation, that leaves open 64 possibilities. Thus there are only 124 possibilities.

I am reasonably confident that Mr. Bland is correct that there is no solution if the operations are limited to addition, subtraction, multiplication, and division so I shall not waste my time working out each of the 124 possibilities, but those who suspect Mr. Bland is wrong have simply to compute the 124 possibilities to end discussion on what I suspect is a grossly deficient statement of a puzzle.
 
I see no reason to assume that the OP gave an accurate rendition of the puzzle …
Agree! (Like I did in post 6.) Looks like a puzzle taken from that Augean stable called Facebook.

… I am reasonably confident that Mr. Bland is correct that there is no solution [as posted] …
Me, too. That's why I'm making fun.

:p
 
It's 0215 hours, and my brain just awakened me.

If we replace "brackets" with "grouping symbols", in the op, then I have an answer.

I'm going back to bed, now.

\(\;\)
 
It's 0215 hours, and my brain just awakened me.

If we replace "brackets" with "grouping symbols", in the op, then I have an answer.

I'm going back to bed, now.

\(\;\)
So did I: see post 5.
 
Top