[Question]
  [
\$ 1089 \$ is a very special number. To prove why, select any 3-digit number whose first and last digits differ by at least 2. Then, reverse the digits, and take the *difference* of these two numbers. Reverse the digits once more, and *add* these two numbers together. You will get \$ 1089 \$. The magic is left as an exercise to the reader.
Taking this a step further, let's define an algorithm for all possible integers:
* Choose any positive integer \$ n \$
* Reverse the digits of \$ n \$, and call it \$ x \$
* Set \$ n \$ equal to \$ n - x \$ if \$ x < n \$, and \$ n + x \$ otherwise
* Repeat the above step until \$ n \$ reaches a number it has already visited
In turns out that this algorithm gets stuck in an infinite loop, for certain numbers. Let's call a number *1089-able™*, if it does in fact terminate (in other words, a duplicate is reached at some point). For example, everyone's favorite number, `2022`, is *1089-able™*:
```
2022 + 2202 ->
4224 + 4224 ->
8448 + 8448 ->
16896 + 69861 ->
86757 - 75768 ->
10989 + 98901 ->
109890 - 98901 ->
10989 (*)
```
In this challenge, you are given a positive integer, and are required to determine whether it is *1089-able™*. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest solution in bytes wins.
The first 50 *non-1089-able™* numbers are as follows:
```
[10057, 10118, 10168, 10254, 10458, 10598, 10698, 10798, 10898, 11047, 11108, 11158, 11244, 11448, 11499, 11588, 11688, 11788, 11888, 11998, 11999, 12037, 12148, 12234, 12438, 12489, 12578, 12678, 12778, 12878, 12988, 12989, 13027, 13138, 13224, 13428, 13479, 13568, 13668, 13768, 13868, 13978, 13979, 14017, 14128, 14198, 14214, 14418, 14469, 14558]
```
  
[Answer]
# [Python](https://www.python.org), 117 bytes
```
def f(n):
    v={n}
    while 1:
        x=int(str(n)[::-1]);n-=[-x,x][x<n]
        if n in v:return 1
        if n/100in v:return 0
        v|={n}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TZJNTsMwEEbFsjmF2TmiERl7HDuBnCTKohIJjQQuStMSBJyETVnAneA0eMZBajZP3-jN-C8f308v03bnT6evw9Rn7udw1_Wilz6tktWxfvXvyep5Ozx0AkJhNdeDn-R-GoPQVFUGbXrjs7rJ5vXcNvOtb4M09MKLwYtjNXbTYfQCluI15Pl5PQ_14xstEhf_vfj0O183QTN2LSAHcIyCoQwS0HAyJaOIsBGOERxqD-QE3AAKqR0QOWFZEozjVETYCBdRlgvIVLmmmQq4XSlNwxRqTuhYMZZTEWEjXETpFpCpc0XDNHC7VoqGaVSc0LJi-NC6iLARLqK0C8jEHGgYArcj8K4xbJSAfIOIBZvGuDZJ-t0oZnqgcePvOwnrx80sw8WnVxBeXYRvs9934yRkL-dUXNZCsk5KGl_q_3f5Aw)
It works for all positive integers less or equal to the 50th *non-1089-able™* number.
Haven't proven that it works for numbers greater than `14558`.
[Answer]
# [Python](https://www.python.org), ~~162~~ ~~136~~ 128 bytes
```
def h(n,e=0):e=(e or[])+[n];n+=(x:=int(str(n)[::-1]),-x)[x<n];return f"1089{(len(z:=str(n))-7)*'9'}099"!=z and(n in e or h(n,e))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TZLRSsMwFIbx1qeIu1niWkjSkyap5klKkYGtK0g2ug62ieB7eLMbxVfSp7HnpIJXHz_8_5-TnLx_7k7jZhsvl4_D2OXu--2x7diGx6wNUlRt4C3bDnUjVnVs7uIq8GMV-jjy_TjwKOqqylUjsvwo6uP95Bja8TBE1i2UdP6FP7eRn6uQzCK34nbpl6_S-8VNOLN1fOSR9ZHhGelQIdIcP1dfXT_sx4eu78YTC6xWUhqbMSWVcoSSoA0gwJAynlAm2ARHmDwYn0hKUUBpwLgCIAXeI4wjVSbYBJfg_Qx0allgp1YU17rAMg0FKXBkMZZUmWATXIJ3M9BZSI1lhaJ4oTWWFaBJgSWLoUsXZYJNcAnezkAnSIVloCgOiqaGaVAE0AsClOQ0xjXXuwGX-u_JQ6h71k1r6XFBwzo-tVxl6PaC9R2L23HaWC-aeWF_H-gX)
Haven't proven that it works for *non-1089-able™* numbers past the first 50.
-26 bytes thanks to benrg and ovs (and for pointing out the rules with reusable functions)
-8 bytes thanks to Jo King
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 70 bytes
```
^
$($^$%')*_;$%'*_¶
^(_+);\1\B|;
_+
$.&
D^`
/^./}s`^1099+8900+¶.+
^¶
```
[Try it online!](https://tio.run/##K0otycxLNPyvqqHhnvA/jktFQyVORVVdUyveGkhpxR/axhWnEa@taR1jGONUY83FFa/NpaKnxuUSl8ClH6enX1ucEGdoYGmpbWFpYKB9aJueNhdX3KFt//8bGRgZcRkaGJiaAwA "Retina – Try It Online") Link only includes two test cases as it's too slow otherwise. Explanation:
```
^
$($^$%')*_;$%'*_¶
```
Take the first number and its reverse and convert them both to unary with the reversed number first.
```
^(_+);\1\B|;
```
Subtract the two numbers of the second is larger otherwise add them.
```
_+
$.&
```
Convert back to decimal.
```
D^`
```
Delete the total if it's been seen before.
```
s`^1099+8900+¶.+
```
But delete the entire buffer if the value will increase infinitely.
```
/^./}`
```
Repeat until at least the current total was deleted.
```
^¶
```
Check to see whether an infinite loop was detected.
[Answer]
## [Javascript](https://www.javascript.com/), 149 145 137 128 bytes
```
c=n=>{a=[n];while(n){x=+[...''+n].reverse().join``;n=x<n?n-x:n+x;if(a[i='includes'](n))return 1;if(a[i](n/100))break;a.push(n)}}
```
* Thanks to [@Radvylf Programs](https://codegolf.stackexchange.com/users/79857/radvylf-programs) for saving 4 bytes!
* Saved 8 bytes replacing `return false` with `break` now that the loop is wrapped
* Thanks to [@Steffan](https://codegolf.stackexchange.com/users/92689/steffan) for saving 9 bytes!
[Try me online.](https://ato.pxeger.com/run?1=NZLBToQwFEXjUr6CzAYaHKTlFYoMuvMnCMkg05lBSTEwoySTSfwPNy507-_o19i-4urklntvHn19_1T9Rn58fB0P26X4eWsKVdye6qJUVf66bzvpK3KaiqAMw9DzAlWFg3yRwyh9Ej72rVqvc1VMK3WnltONCqa83fp12RZeq5ruuJGjV-kGMsjDcVAunT_rs2saRYQ8DLJ-yuvw-Tjute98tnP8XnyrXhWl9vD0yqURpQKRIBgHA-CoeIZILFILgdAeE9dERTFAGZg4BUAFWWbABarEIrUQFlk2wzhZFJtORjHOWGzKGMSoQKCFp6gSi9RCWGRihnHGETNlMcV4zJgpi4GhghQtHH86TixSC2GRpTOMEyJqyoBiHChODXpQA8AbBEjQybmoHGfbD34nD27rFm6Ua6xcfe1hJ9XusNc6CMjJudQra3x9rtdGiNv0auw7GXb9zl_c1_qFbBYkd-bF_T-kPw)
## [Javascript](https://www.javascript.com/), 171 bytes (readable)
```
c=n=>{
    a = [n]
    while(n){
        x=+n.toString().split('').reverse().join('')
        n=x<n?n-x:n+x
        if(a.includes(n)) return true
        if(a.includes(n/100)) break
        a.push(n)
    }
}
```
[Try me online.](https://ato.pxeger.com/run?1=ZZI9TsNAEIVFGZ_CShNbAeNdz9prwNBxAcoohUk2icEaR_6BSFFOQpMCKhquA6dhdjZUuPn0Zt8bjXfn7R2bpTkeP4Z-daG_PxcFFrd7z6ev9At_hnNv9LqpahNguPdGo10xxahvHvq2wnUQRt22rvpgMgmj1ryYtjNUe2oqtCWyY7G7wTu82F3hdEe6WgVlVOGiHpamo5ah35p-aNHv28H8P78UcUyex9aUz3RaRtuh21DMGx28gxv55-wLGyxm5FTZuS9iITQjZUgFFqBYqZyROmQOmkEeGyeyEhwQEmxcALCCPLdQmlXqkDlohzw_wTplnNieUnBcysQ2k5CwAs0WlbFKHTIH7ZDrE6wziaVtlgiOJ1LaZglIVpCxRfFPJ6lD5qAd8uwE64RY2GYgOA6CpwYa1AL4BgFSdiql5563atqgNr1f0VLE14Qbn649qg2u-w3p6dSuBz3fIqD6rJrTsy0a7JraRHWzDsb3JS3Rchxe_z3c3879Ag)
A good chunk of the bytes in this are coming from included functions `.reverse()`, `.includes()`, etc. Have not tested past the 50 provided.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 84 bytes
```
->n,*r{q=0;1while(r!=r|=[n+=(w=n.digits.join.to_i)*(w<n ?-1:1)])&&q=[]!=[n/100]-r;q}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y5PR6uoutDWwNqwPCMzJ1WjSNG2qMY2Ok/bVqPcNk8vJTM9s6RYLys/M0@vJD8@U1NLo9wmT8Fe19DKUDNWU02t0DY6VhGoXt/QwCBWt8i6sPZ/gUJatJGBkVEsF4gFFDc1j/0PAA "Ruby – Try It Online")
[Answer]
# [Javascript](https://www.javascript.com/), ~~94~~ 87 bytes
```
f=(n,s={},x=+[...``+n].reverse().join``,m=x<n?n-x:n+x)=>s[m]?!!(m-11e12+11):f(s[m]=m,s)
```
## How it works!
If the function does get stuck in a forever loop it will max out at the magic number `11e12+11` and this function returns the result minus that number casted to a boolean.
* 7 Bytes thanks to [@Steffan](https://codegolf.stackexchange.com/users/92689/steffan)!
[Try it online!](https://tio.run/##dZHNbsIwEITvPEXggi2c4J91bKMGxIWXQEikNFQg4iBSoUhVnz2N13BAVU@fZj0zayfn8l62h9vp@pX65qPq@2NBPGuL7x/WFbNtlmX7/czvslt1r25tRWh2bk6eTCaU1UX35lc@7RZ@1tFi2W7r3Wo8JnXKuzUXUgmz3mw0XRxJOCpq1tJ@Pk8Et658v1SjQ@Pb5lJll@aTTJ/TKX2ZbwXniiWSS8kSZY1hieNas8TkMEyGU7fL6vJKuqRYJkfSUUpHo2GLb3waOl@3PKf/bNImVAphETlCaggAjUo7RB5hIixi8IT4QFQCA0JCiAsAVOBcgLao8ggTYSOceyA4JVehUwqMS6lCmQSFCixatEGVR5gIG@HsA8GpuAxlSmBcSRnKFEhUYNCi8dEqjzARNsKZB4ITuAhlIDAOAm8Nw0UDAL8gQI5Ore2ff9T/Ag)
]