[Question]
  [
## Challenge:
There's a silly puzzle circulating on social networks that reads:
```
8 + 2 = 16106
5 + 4 = 2091
9 + 6 = ?
```
Implement a function or operator that, when given two positive integer numbers `x` and `y` such that `x > y > 0`, yields the correct answer as an **integer**, where the answer's digits are the digits of `x * y` followed by the digits of `x + y` followed by the digits of `x - y`. Very simple.
## Rules:
* [Standard loopholes are disallowed.](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default)
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so shortest code in bytes wins.
* Input data validation is **not** required. This program may crash or return garbage when given invalid input.
* You're allowed to use numeric functions and operators (including integer and floating point, math library functions, and other functions that accept and return numbers).
* You're allowed to use a function that returns the number of digits of a number, if applicable.
* You're **not** allowed to use strings or any kind of concatenation anywhere in your code.
* The result may be returned or pushed to the stack, whichever applies in the language. The result must be an integer number, not a string.
## Sample code:
**[Dyalog APL](http://tryapl.org/):**
The following code creates a dyadic operator named `X`.
> 
> X←{(⍺-⍵)+((⍺+⍵)×10\*1+⌊10⍟⍺-⍵)+⍺×⍵×10\*(2+⌊10⍟⍺+⍵)+⌊10⍟⍺-⍵}
> 
> 
> 
Explanation:
* In APL, you evaluate from right to left.
* `⍺ and ⍵` are the left and right operand, respectively
* `⌊10⍟⍺-⍵` reads: `floor of log10(⍺-⍵)`. First performs substraction then logarithm then floor. From right to left. log10 is done in order to count the digits of `⍺-⍵` (you must sum 1 afterwards).
* `⍺×⍵×10*(...)` reads: `10 to the (...)th power, multiplied by ⍵, multiplied by ⍺`
* Hence, `⍺×⍵×10*(2+⌊10⍟⍺+⍵)+⌊10⍟⍺-⍵` is the product, shifted to the left by the sum of the number of digits of the sum and the difference. Multiplying by a power of 10 will shift an integer to the left.
* `((⍺+⍵)×10*1+⌊10⍟⍺-⍵)` is the sum, shifted to the left by the number of digits of the difference.
* `(⍺-⍵)` is the difference. No shifting is necessary here.
* `X←{...}` is how you define an operator in APL.
Examples:
```
      8 X 2
16106
      5 X 4
2091
      9 X 6
54153
```
**GNU dc:**
The following code creates a macro named `a`:
```
[sysx10lxly-dseZdsclxly+dsd+Z1+^lxly**10lc^ld*+le+]sa
```
Explanation:
* `sx` and `sy` pop an element from the stack and save it on the registers `x` and `y`, respectively.
* `lx` and `ly` load an element from registers `x` and `y` respectively and push it to the stack.
* `d` duplicates the last element in the stack.
* `^` computes the power of two numbers.
* `Z` pops a number and returns its number of digits. This is done because `dc` has no logarithm function.
* `[...]sa` stores a macro in register `a`. `la` loads it. `x` executes the macro at the top of the stack.
Examples:
```
8 2 laxn
16106
5 4 laxn
2091
9 6 laxn
54153
```
  
[Answer]
# JavaScript (ES7), ~~63~~ ~~61~~ 59 bytes
Saved 4 bytes thanks to [Neil](https://codegolf.stackexchange.com/users/17602/neil).
```
(a,b)=>[a*b,a+b,a-b].reduce((p,c)=>p*10**-~Math.log10(c)+c)
```
```
<input id=a type=number oninput="c.innerText=((a,b)=>[a*b,a+b,a-b].reduce((p,c)=>p*10**-~Math.log10(c)+c))(+a.value,+b.value)">
<input id=b type=number oninput="c.innerText=((a,b)=>[a*b,a+b,a-b].reduce((p,c)=>p*10**-!Math.log10(c)+c))(+a.value,+b.value)">
<p id=c>
```
[Answer]
# C, ~~79~~ 75 bytes
*Thanks to @G B for saving 4 bytes!*
```
#define X for(c=1;(c*=10)<=a
c,d;f(a,b){X+b;);d=c*a*b+a+b;X-b;);a=d*c+a-b;}
```
[Try it online!](https://tio.run/nexus/c-gcc#JYjBCsIwEETv@YpQEXaTFayoVGL@Iwcvm6SBHBql9Fb67THVgeHNvHqIY8pllE6m9wzB9gaCsv0Zn5ZFoGgSMHlcnfYGTbRBsfKa23On3bCNKmhue6u5LHLiXADFKmTLZ24qQXeMr/JvRzLBQBfceaPrjw@6Ixqx1S8)
[Answer]
# Bash, 66
* 2 bytes saved thanks to @chepner.
```
f()(s=$[$1+$2]
d=$[$1-$2]
echo $[($1*$2*10**${#s}+s)*10**${#d}+d])
```
[Try it online](https://tio.run/nexus/bash#@5@moalRbKsSrWKorWIUy5UCZuqCmKnJGfkKKtEaKoZaKkZahgZaWirVysW12sWaME5KrXZKrOb/NAULBSOuNAVTBRMgaalg9h8A).
[Answer]
# EXCEL, 61 Bytes
```
=A1-B1+(A1+B1)*10^LEN(A1-B1)+A1*B1*10^(LEN(A1-B1)+LEN(A1+B1))
```
Excel, 18 Bytes not valid
```
=A1*B1&A1+B1&A1-B1
```
[Answer]
# [Stacked](https://github.com/ConorOBrien-Foxx/stacked), 36 bytes
```
,@A$(*+-){!A...n!}"!{%y#'10\^x*y+}#\
```
[Try it online!](https://tio.run/nexus/stacked#s1Aw@q/j4KiioaWtq1mt6Kinp5enWKukWK1aqaxuaBATV6FVqV2rHPM/v7TkPwA "Stacked – TIO Nexus")
Previously: `,@A$(-+*){!A...n!}"!:inits$#'"!$summap:[[email protected]](/cdn-cgi/l/email-protection)\^1\,\*sum`
I'm going to try to squeeze out a byte or two before writing an explanation. (`#'` = size of, and `"` is "do on each", no strings attached here.)
Noncompeting at 26 bytes: `$(*+-)#!!:{%y#'10\^x*y+}#\`.
[Answer]
# TI-Basic, ~~34~~ 33 bytes
```
Prompt A,B
A-B+(A+B)10^(1+int(log(A-B
Ans+AB10^(1+int(log(Ans
```
[Answer]
# GNU dc, 36
Defines a macro `m` that takes the top two members of the stack, applies the macro and leaves the result on the stack (as per the example in the question):
```
[sadsbla-dZAr^lalb+*+dZAr^lalb**+]sm
```
[Try it online](https://tio.run/nexus/dc#@x9dnJhSnJSTqJsS5VgUl5OYk6StpQ1na2lpxxbn/rdQMFLIya0o4DJVMIEwLBXMwIz/AA).
[Answer]
# [Perl 6](https://perl6.org), ~~81 61~~ 58 bytes
```
->\x,\y{($/=($/=x- y)+(x+y)*({10**$++}...*>$/).tail)+x*y*({10**$++}...*>$/).tail}
```
[Try it](https://tio.run/nexus/perl6#dY7NCoJAHMTv@xR/ZIn9cv2gJBHXHsSLqYGgCa3FLuKTdevFbC06dpjDb2YY5q5beCSyztBgYVePTQv56qvSiNLOBAf5JuODpZwYbikjcxQyhjlfpJRM4YDKqep6yg2z/8JldeOnqdWThhz67tpqQl9PWY/DmQRlwwOaIXQZb7@Sr4BgI7AVuKAwIwBdWfA@FuQKPLE9/VYoWtYjcIjddJREYYIOjvaO4jCNUOogcVC8AQ "Perl 6 – TIO Nexus")
```
->\x,\y{(x*y,x+y,x- y).reduce:{$^a*10**Int(1+log10($^b))+$b}}
```
[Try it](https://tio.run/nexus/perl6#NY7fCoIwHIXv9xQ/ZMTmpm5Soz9o3fYOEqSuCErBWWyIT9ZdL2ar6OJcfIePw7kbDQ8VVxt0czCr2lpDNkV5YXnhBmJDxy3zicDRuNP1vdLrAR@OoRRhuG96Itm1PUtB8KGklOFyHCc/tOu16Q1kcL002hD6esZVeytJUtQsoRuETm33l6IcCLYcO463FAYEYI4Ogm8FWQ4B/7z6KRSN0xIYpH5aKikUWniae0rFSqKVB@Vh@wY "Perl 6 – TIO Nexus")
```
->\x,\y{[[&({$^a*10**Int(1+$^b.log10)+$b})]] x*y,x+y,x- y}
```
[Try it](https://tio.run/nexus/perl6#NY7LCoJAGIX38xQ/MsTcNCdKktDa9gxeQM0iKAcaixnEJ2vXi9lUtDiL7/BxOHfdwiMKmg26Wpg16tBCMvlpbkRuhyybkQGXFZMhY/uuJ5Ljsg4u6iRDynE90qIAw6ww3MUHO05uZde3uteQwOXctZrQ1zNo1LUm8/zA53SD0FHd/pKfAsFGYCvwlsKAAHRlwftWkKTgic@ln0LROK2Bw8JNy0iGEVo5WjpahLFEsYPIwfYN "Perl 6 – TIO Nexus")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 27 bytes
```
+,ạ,.1Fl⁵Ḟ‘€Ṛ+\⁵*
ạ,+,×Fæ.ç
```
Defines a dyadic link / function, callable with `ç`. Takes two integers as input and returns an integer. It has the added bonus of being able to take x`<`y or x`>`y by using absolute difference.
[Try it online!](https://tio.run/nexus/jelly#@6@t83DXQh09Q7ecR41bH@6Y96hhxqOmNQ93ztKOAQpocYFktXUOT3c7vEzv8PL/pgqHlyuY/AcA "Jelly – TIO Nexus")
Explanation:
```
+,ạ,.1Fl⁵Ḟ‘€Ṛ+\⁵* -- Create link which computes what order of magnitude
                        to multiply the difference, sum, and product by
ạ,+,×Fæ.ç         -- Main link, applies this using dot product
```
Details: 
```
+,ạ,.1Fl⁵Ḟ‘€Ṛ+\⁵* -- Create dyadic like which does the following:
       l⁵Ḟ‘       -- Create operation which computes number of digits
                       (log base 10 (⁵ is the literal 10), floored, incremented)
           €      -- Apply this to each element in
+,ạ,.1F           -- ... the list [sum,difference,.1]
            R     -- Reverse the list
             +\   -- Add up first n elements to get list.
               ⁵* -- Raise 10 (⁵ is literal 10) to the power of each element
ạ,+,×Fæ.ç         -- Main link, applies above link
ạ,+,×F            -- The list [difference, sum, product]
      æ.          -- Dot product (multiply corresponding elements) with
        ç         -- The above link.
```
[Answer]
# PHP, ~~79~~ 75 bytes
two versions:
```
[,$a,$b]=$argv;echo(10**strlen($s=$a+$b)*$a*$b+$s)*10**strlen($d=$a-$b)+$d;
[,$a,$b]=$argv;echo(10**strlen($a+$b)*$a*$b+$a+$b)*10**strlen($a-$b)+$a-$b;
```
takes input from command line arguments; run with `-r`.
I guess `strlen` qualifies as "function that returns the number of digits",  
although it uses the number as a string. Let me know if not.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 70 bytes
```
#define _ for(c=1;a+b>=(c*=10););d=c*d+a-(b=-b);
c,d;f(a,b){d=a*b;_ _}
```
[Try it online!](https://tio.run/nexus/c-gcc#JYzLCsIwEEX3@YqhIsykU7CiooTxS4SQRwNZNEpxV/rtMeqBy4G7OHUXp5TLBBbSc8Ego3G9vwsGLeOBDJkoQcfeDehl8GRU4GgSOva0RnHaGwt2q7m8YXa5IKlVQeO1tCtht4@P8l/HkPDKR/r6zKefb3yhFt3qBw "C (gcc) – TIO Nexus")
based on [Steadybox](https://codegolf.stackexchange.com/a/115402/18535) answer, putting everything in a macro to golf it a little more.
(Note: assigning the result to `d` instead of `a` works, unexpectedly. I had a look at the generated assembly code and it seems to be ok.)
[Answer]
# Haskell, 54 bytes
```
a%0=a
a%b=10*a%div b 10+mod b 10
a#b=(a*b)%(a+b)%(a-b)
```
The puzzle is implemented via an infix function `#`, e.g. `8#2 = 16106`. The other function, `%`, defines base-10 concatenation (assuming the RHS is greater than 0).
[Answer]
# Dyalog APL, 31 bytes
[`{a⊥⍨10*1+⌊10⍟a←(⍺×⍵)(⍺+⍵)(⍺-⍵)}`](http://tryapl.org/?a=f%u2190%7Ba%u22A5%u236810*1+%u230A10%u235Fa%u2190%28%u237A%D7%u2375%29%28%u237A+%u2375%29%28%u237A-%u2375%29%7D%20%u22C4%20f/%A8%288%202%29%285%204%29%289%206%29&run)
based on the sample APL code from the problem statement
[Answer]
# PHP, 87 Bytes
```
[,$a,$b]=$argv;echo($s=$a-$b)+($t=$a+$b)*10**($l=strlen($s))+$a*$b*10**($l+strlen($t));
```
and a not valid solution for 37 Bytes
```
[,$a,$b]=$argv;echo$a*$b,$a+$b,$a-$b;
```
[Answer]
# Ruby, 61 bytes
```
->a,b{[a*b,a+b,a-b].reduce{|x,y|z=y;x*=10while(z>z/=10);x+y}}
```
Which suspiciously looks a lot like [this](https://codegolf.stackexchange.com/a/115432/18535) Javascript answer, but without using a logarithm.
[Answer]
# Python, 92 91 Chars
```
def g(x,y):
    l=lambda x,i=0:l(x/10,i+1)if x else 10**i
    a=x-y
    a+=(x+y)*l(a)
    return x*y*l(a)+a
```
Thanks to Wizards suggestion;)
[Answer]
# R (3.3.1), 104 bytes
```
function(x,y)Reduce(function(p,q)p*10^(floor(log10(q)+1))+q,lapply(c(`*`,`+`,`-`),function(z)z(x,y)),0)
```
returns an anonymous function.
This is my first golfing attempt, so any feedback is appreciated.
[Answer]
## REXX, 70 bytes
```
f:arg a b
c=a-b
c=(a+b)*10**length(c)+c
c=a*b*10**length(c)+c
return c
```
Of course, the native way would be much shorter:
```
f:arg a b
return a*b||a+b||a-b
```
[Answer]
## PowerShell, 88 Bytes
```
param($x,$y)$l=2;if(($a=$x+$y)-gt9){$l++};($x*$y)*[math]::Pow(10,$l)+$a*10+$x-$y
```
PowerShell does not have a to the power operator which does not help. Also can't count the length of an integer unless you count it as a string, which we can not do, so I check to see if it is `-gt` 9 to get know the length. Likely could be more terse but I have to get back to work.
[Answer]
## Python 2.7, ~~109~~ 96 bytes
```
import math
a=lambda n:10**int(math.log10(10*n))
b,c=input()
d=b-c+(b+c)*a(b-c)
print d+b*c*a(d)
```
Corrected after following rules of contest.
Credits to [mbomb007](https://codegolf.stackexchange.com/users/34718/mbomb007) for bringing down the code from 109 bytes to [96 bytes](https://tio.run/nexus/python2#FctNCoAgEEDhvadwOaMVugkKPMyMQgn@EXZ@s93jgzdibvXpMlO/BblEmQPJclqjVCwdft9SvayBSQVR8OJdLO3tgCI4Xr0G1h4VwWwU7ZmbDJqVnxRwjGPZPw)
[Answer]
# [J](http://www.jsoftware.com), 25 bytes
```
X=.10#.[:;10#.inv&.>*;+;-
```
1. `*;+;-` Box the results of each operation.
2. `10#.inv&.>` Convert each result into an array of base-10 digits. (`inv` is `^:_1`)
3. `[:;` Unbox and join the arrays.
4. `10#.` Convert array of base-10 digits into an integer.
5. `X=.` define the above as the operator `X`.
Results:
```
   8 X 2
16106
   5 X 4
2091
   9 X 6
54153
```
[Answer]
# Mathematica, 67 bytes
```
c=Ceiling;l=Log10;#-#2+(#+#2)10^(c@l[#-#2]/. 0->1)+10^c@l[2#]10#2#&
```
Takes `x-y`, then takes the log10 of `x-y`, rounds it up, calculates 10 to the power of that and then multiplies it by `x+y`. But we also need to consider `log10(x-y)` being 0, so we replace 0 with 1. Then we take the log10 of `2x`, rounded up, plus 1, and find 10 to the power of that. Multiply that by `xy`, and add that on.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~23~~ ~~22~~ 16 bytes
```
-Dg°¹²+*Dg°¹²**O
```
[Try it online!](https://tio.run/nexus/05ab1e#@6/rkn5ow6GdhzZpa8FYWlr@//@bcVkCAA "05AB1E – TIO Nexus")
We could have saved a few bytes if we'd been allowed to use strings in the program (but not in calculations) by looping over a string containing the operations `"-+*"`, as the code performed for each operation is the same.  
Of course, if we'd been allowed to use concatenation we'd saved a lot more.
[Answer]
## R, 64 bytes
```
x=scan();(b=(a=diff(-x))+10^nchar(a)*sum(x))+10^nchar(b)*prod(x)
```
Usage:
```
> x=scan();(b=(a=diff(-x))+10^nchar(a)*sum(x))+10^nchar(b)*prod(x)
1: 8 2
3: 
Read 2 items
[1] 16106
```
]