2

In the context of puzzles such as this:

Write a program that outputs all possibilities to put + or - or nothing between the numbers 1,2,…,9 (in this order) such that the result is 100. For example 1 + 2 + 3 - 4 + 5 + 6 + 78 + 9 = 100.

Is there a name for the "nothing"-operation between 7 and 8?

What it would do is I think: let a,b be positive integers

$a$ nothing $b= a\times 10 +b$

Also if you think this belongs to a special Tag please edit the Tag in there.

Blue
  • 75,673
SAJW
  • 1,327

1 Answers1

4

It's called concatenation. And it's not $a \times 10 + b$. That fails for numbers with more than one digit.

The correct formula is $a \cdot 10^{1 + \lfloor\log_{10}(b)\rfloor} + b$ where we define $\log_{10}(0) = 0$.

orlp
  • 10,508
  • 3
    Even your formula fails if $b$ has leading zeros. Unfortunately, no operation can distinguish between $21$ and $201$ by referring only to the values of $2$ and either $1$ and $01$. However, inasmuch as no parentheses appear, we can impose a convention that the operation always associates to the left, and then the simple formula $a\times10+b$ will still work. (So ‘$2(01)$’ evaluates to $2\times10+(0\times10+1)=21$ if we use decimal concatenation for both operations, but ‘$201$’ is interpreted as ‘$(20)1$’, which correctly evaluates to $(2\times10+0)\times10+1=201$ using the simple formula.) – Toby Bartels Sep 07 '18 at 23:20
  • @TobyBartels My formula doesn't fail for any non-negative integer $a, b$. It's a function over the integers, not strings. There is no such thing as an integer with leading zeroes. – orlp Sep 08 '18 at 02:59