[Question]
      [
A [self number](https://en.wikipedia.org/wiki/Self_number) (also called a Colombian or Devlali number) is a natural number, `x`, where the equation `n + <digit sum of n> = x` has no solutions for any natural number `n`. For example, **21** is not a self number, as `n = 15` results in `15 + 1 + 5 = 21`. On the other hand, **20** *is* a self number, as no `n` can be found which satisfies such an equality.
As this definition references the digit sum, it is base dependent. For the purposes of this challenge, we will only be considering base 10 self numbers, which are sequence [A003052](https://oeis.org/A003052) in the OEIS. Binary ([A010061](https://oeis.org/A010061)) and base 100 ([A283002](https://oeis.org/A283002)) self numbers have also been calalogued.
## The Challenge
Given a positive integer `x` as input, output a truthy value if `x` is a self number in base 10, and a falsey value otherwise. For clarification of truthy and falsey values, refer to [this meta post on the subject](https://codegolf.meta.stackexchange.com/a/2194/41020).
You may write a full program or function, and input and output may be provided on any of the usual channels. [Standard loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are, of course, banned.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shorter your answer (in bytes) the better!
## Test cases
Truthy:
```
1
3
5
7
9
20
31
86
154
525
```
Falsey:
```
2
4
6
8
10
15
21
50
100
500
```
[Sandbox link](https://codegolf.meta.stackexchange.com/a/16052/41020)
## Leaderboards
Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.
To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:
```
# Language Name, N bytes
```
where `N` is the size of your submission. If you improve your score, you *can* keep old scores in the headline, by striking them through. For instance:
```
# Ruby, <s>104</s> <s>101</s> 96 bytes
```
If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the *last* number in the header:
```
# Perl, 43 + 2 (-p flag) = 45 bytes
```
You can also make the language name a link which will then show up in the leaderboard snippet:
```
# [><>](http://esolangs.org/wiki/Fish), 121 bytes
```
```
var QUESTION_ID=159881,OVERRIDE_USER=41020;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```
```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```

[Answer]
# [Octave](https://www.gnu.org/software/octave/), 37 bytes
```
@(n)sum(dec2base(t=1:n,10)'-48,1)+t-n
```
Port of my MATL answer.
[Try it online!](https://tio.run/##TY1BCoMwFET3nmJ2RqohPxqbFoTeo3RhNaGCxmJioadPU@iii2GG9xazDqF/mWg7znm8MFf4fWGjGeS994aFjs6uJFHkVaNLKg6hctGuGxw6XAk1FI44QQrUBN2CVAMlFSQatNAgkRAkQaUhRCpxy4DJwqavtIBx8k@Wh20Pj3f@RWb25s/YfvY/4cYsJX4A "Octave – Try It Online")
[Answer]
# [Java (JDK 10)](http://jdk.java.net/), 84 bytes
```
i->{for(int n=i;i-->1;)i|=((""+i).chars().map(x->x-48).sum()+i^n)-1>>-1;return~i<0;}
```
[Try it online!](https://tio.run/##PVDLTsMwELz3K1aRKtnUdpPSQiEkdw5ISD0ikEwerUviRPamalXCrwc7hVqyd9cz4531Xh4k3@dfg6rbxiDsXS06VJUoO52harS4iSdZJa2FF6k0nCcAbfdZqQwsSnTh0KgcaoeRDRqlt2/vIM3W0pEK8Kzx1RS5yiQWUEIyKJ6ey8YQpRF0omLFeRrFVH0nhATBTFGR7aSxhIpatuTI0yNfrqmwXU3oTH1oyqM05VFsCuyM/lFPYdwP8djLPem6Y2HRQvLX36@IwS2DFYN7Bg8MFqGr3d36jkG0Wjpk4bD5HNB0uDtdZQsGDnSkteOFnuu0TrfyeRj6JPSyUlb2X9XHkzFzE8I4onfzePFEr5Y2J4tFLZoORev@DEsSTHPgKUztVAdspDMohY/EH5ReJuwnfvfDLw "Java (JDK 10) – Try It Online")
## Explanation
```
i->{                                    // IntPredicate
  for(int n=i;i-->1;)                   //  for each number below n
    i|=(                                //   keep the sign of
      (""+i).chars().map(x->x-48).sum() //    sum of digits
      +i                                //    plus the number
      ^n                                //    xor n (hoping for a zero)
     )-1>>-1;                           //    changing that into a negative number if equals to zero
  return~i<0;                           //  return i>=0
}
```
## Credits
* -1 byte thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen)
* -1 byte thanks to [Nevay](https://codegolf.stackexchange.com/users/69142/nevay)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 8 bytes
```
LD€SO+ÊW
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fx@VR05pgf@3DXeH//xuamgAA "05AB1E – Try It Online")
or as a [Test suite](https://tio.run/##MzBNTDJM/V9TVln538flUdOaYH/tw13h/yuVDu9X0LVTOLxfSUcz5r8hlzGXKZc5lyWXkQGXsSGXhRmXoakJl6mRKZcRlwmXGZcFl6EBUIjLyJDLFMgwMABSBgA)
**Explanation**
```
L          # push range [1 ... input]
 D         # duplicate
  €S       # split each number into a list of digits
    O      # sum digit lists
     +     # add (n + digitSum(n))
      Ê    # check for inequality with input
       W   # min
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 12 bytes
```
¬{⟦∋Iẹ+;I+?}
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r//9Ca6kfzlz3q6PZ8uGuntrWntn3t//9GBv8B "Brachylog – Try It Online")
### Explanation
```
¬{         }    Fails if succeeds, suceeds if fails:
  ⟦∋I             I ∈ [0, ..., Input]
    Iẹ+           The sum of the elements (i.e. digits) of I...
       ;I+?       ... with I itself results in the Input
```
[Answer]
# [Octave](https://www.gnu.org/software/octave/), ~~49~~ ~~47~~ 44 bytes
```
@(x)arrayfun(@(k)k+sum(num2str(k)-48)-x,1:x)
```
[Try it online!](https://tio.run/##JYxBCsIwFET3PcVspAm2wYqCFAo9iJuo@fCpTctPIvH0MeBi4D14zPaM9uMKTcaYMqusrYj9UvJqVotejiGtyqf1HKJU7y833eduGLMutAmYMWEYr6cGYAIpZl0R2IV9JNUeGBxgEdybUH8eTu6@7f6Z86@mrvwA "Octave – Try It Online")
**Explanation:**
Trying to do the operation on a range is cumbersome and long, since `num2str` returns a string with spaces as separators if there are more than input number. Subtracting 48 would therefore give something like: `1 -16 -16 2 -16 -16 3 -16 -16 4` for an input range **1 ... 4**. Getting rid of all the `-16` takes a lot of bytes.
Therefore, we'll do this with a loop using `arrayfun`. For each of the numbers **k = 1 .. x**, where **x** is the input, we add `k` and its digit sum, and subtract `x`. This will return an array of with the result of that operation for each of the numbers in **k**. If any of the numbers in the array is a zero, the number is not a self number.
For inputs `20` and `21`, the outputs are:
```
20:  -18, -16, -14, -12, -10, -8, -6, -4, -2, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 2
21:  -19, -17, -15, -13, -11, -9, -7, -5, -3, -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 1, 3
```
There are only non-zero elements for input `20`, and at least one non-zero element for input `21`. That means that `20` is a self number, and `21` is not.
Octave treats an array with at least one zero as false, as can be seen in the TIO-link.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~70~~ ~~67~~ 65 bytes
```
i,r,d,j;f(n){for(r=i=n;d=j=--i;r*=d!=n)for(;j;j/=10)d+=j%10;i=r;}
```
[Try it online!](https://tio.run/##NY1BbsIwEEXX@BRupEh2sVUnkBZqzbYn6DIbFDepLTpUJiAhlLOnpB6v3mjm/fmdHrpunr2Kyqlge4Hy3p@iiOABrYMAWnsbn8E9AcrlYoMNL1AZ6dYQyspYD9FO8/XkHR@Ex5GjZHe2@o2PuRdFuXG8dC0WiqPiS4G0bGJsMX8OHkWyL@NZFJ/xMn7f3lvUWhcPbTWIKmGT0CS8JewTakMOubtXijZbStX/udzS4sfheP6inlxUJ1CEXuzok8kfyaWmJu@NyYtlmOY/ "C (gcc) – Try It Online")
To shave off another 2 bytes, the truthy value returned is no longer 1, but the number itself.
[Answer]
# [J](http://jsoftware.com/), 28, 24, 22 21 bytes
-1 byte thanks to Conor O'Brien
-2 byts thanks to ngn
```
$@-.(+1#.,.&.":)"+@i.
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/VRx09TS0DZX1dPTU9JSsNJW0HTL1/mtycaUmZ@QrpCkYwhjGMIYpjGEOY1jCGEYGcNVwfRZmcKNMTeBmGJnCbTCCMeCycB0WcK0GCEPg@uBWmCJkDQwQggb/AQ "J – Try It Online")
## Explanation:
`i.` a list 0 .. n-1
`( )"+` for each item in the list
`.,.&.":` convert it to a list of digits,
`1#` find their sum
`+` and add it to the item
`$@-.` exclude the list from the argument and find the shape
[Answer]
# [MATL](https://github.com/lmendo/MATL), 11 bytes
```
t:tFYA!Xs+-
```
The output is a non-empty array, which is truthy if all its entries are non-zero, and falsy if it contains one or more zeros.
[Try it online!](https://tio.run/##y00syfn/v8SqxC3SUTGiWFv3/39DUwA "MATL – Try It Online") Or [verify all test cases](https://tio.run/##bc69CsIwFAXg/TxFHKSDWJK0qdVFhCq4OTjoIFhoawMxLU2KdPDZYzsoGbzL/eGDe565Ve5OvjUnWROG4auWqnR2Yw/X3exiFku39cixQmC73tZDMK2n3tTE1tIQYzupH3h7dq9MSQiCKldm4v/8zfe6QObHkaZV@YCz/19XUktbkuKXlaimaR1DBIEV1uAUEUOagIkYggtwxEiQgtHxBM4gxoHSsdEP), including truthiness/falsihood test.
### Explanation
Consider input `n = 10` as an example.
```
t       % Implicit input, n. Duplicate
        % STACK: 10, 10
:       % Range
        % STACK: 10, [1 2 3 4 5 6 7 8 9 10]
t       % Duplicate
        % STACK: 10, [1 2 3 4 5 6 7 8 9 10], [1 2 3 4 5 6 7 8 9 10]
FYA!    % Convert to base 10 digits and transpose
        % STACK: 10, [1 2 3 4 5 6 7 8 9 10], [0 0 0 0 0 0 0 0 0 1
                                              1 2 3 4 5 6 7 8 9 0]
Xs      % Sum of each column
        % STACK: 10, [1 2 3 4 5 6 7 8 9 10], [1 2 3 4 5 6 7 8 9 1]
+       % Add, element-wise
        % STACK: 10, [2 4 6 8 10 12 14 16 18 11]
-       % Subtract, element-wise
        % STACK: [8 6 4 2 0 -2 -4 -6 -8 -1]
        % Implicit display
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 14 bytes
```
~⊢∊⍳+(+/⍎¨∘⍕)¨∘⍳
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24S6R12LHnV0PerdrK2hrf@ot@/QikcdMx71TtWEMjb//29Q96h3hQaQaWKgeXh6GlACxAQA "APL (Dyalog Unicode) – Try It Online")
**How?**
```
               ⍳   range
     (  ⍎¨∘⍕)      digits
     (+/    )      digit sums
   ⍳+              vectorized addition with the range
 ⊢∊                is the input included?
~                  negate
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
ḟDS+Ɗ€
```
For input **n**, this returns **[n]** if **n** is a self number, **[]** if not.
[Try it online!](https://tio.run/##y0rNyan8///hjvkuwdrHuh41rfl/uB1IRv7/b6ijYKyjYKqjYK6jYKmjYGQA5APFLMx0FAxNTYAyRkA5Ix0FIBMoZAEUNQDJAMWAqkxBbAMDEMMAAA "Jelly – Try It Online")
### How it works
```
ḟDS+Ɗ€  Main link. Argument: n
     €  Call the link to the left for each k in [1, ..., n].
    Ɗ     Drei; combine the three links to the left into a monadic chain.
 D          Decimal; map k to the array of its digits in base 10.
  S         Take the sum.
   +        Add k to the sum of the k's digits.
ḟ       Filterfalse; promote n to [n], then remove all elements that appear in the
        array to the right.
        This returns [n] if the array doesn't contain n, [] if it does.
```
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 32 bytes
```
n->!sum(i=1,n,i+sumdigits(i)==n)
```
[Try it online!](https://tio.run/##FcjLCoMwEIXhV0ldZegJZKLxsogvUroQijLQDkHtok8f09X5zp@XXdyWy2pSUTffju/HSmIo5F79kk3OwwqlpFSWnN8/q8bNJu@iZ2XzP41ZrRLBPBgtIgZMCB4tY@zBsUMMEQEdeoxgXxMCI1Z4X8c/qVw "Pari/GP – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 46 bytes
```
f x=and[x/=n+sum[read[d]|d<-show n]|n<-[1..x]]
```
[Try it online!](https://tio.run/##bY6xboNADIb3PsUf1CERDuVISNMqDB3SqZ2aDaHqyBkRFQ56d6gMeXcKiZQu9eJftj5/LqX94qoahgJ9IrVK@4dE@7arU8NSpSo7q93Sls0PdHbWu2UqgqDPsqGWJ40EqrnDWBU7SGvZuP03JPJxcyogkySHK1nDsOuMni/AlWWwMY3BPbz9FGbY9y0fHatneL5/cUnf9/BydJ2s/ob5RVXL9v0T85vtYDpGgGKBVNCKYnqkJ4pCWgnabkjEa4qjOPsXfZXTN1c2ojVtaEsiHBmKBMVjCMOxhVe47dyHM28a3oGts2inM2rmDb8 "Haskell – Try It Online")
[Answer]
# Scala, ~~44~~ 42 bytes
```
x=>0 to x forall(n=>x!=(n/:s"$n")(_+_-48))
```
[Try it online](https://scastie.scala-lang.org/O9mJjklnT3ODlUIPhYgM7w)
[Answer]
# [Perl 5](https://www.perl.org/) `-a`, 34 bytes
```
#!/usr/bin/perl -a
say!grep{s/./$_+=$&/reg;/@F/}1..$_
```
[Try it online!](https://tio.run/##FcqxCsIwFAXQ/f6FEFykSW7aNA1FcHLzG0qHUASxIeki4q/3qWc@OZWHF6nz67CUlN/VaKOm01kdTUnLaC5X86HWahIhHFp08OgRMCCCFiTowBbsQA/2YAAHMMJZOCIGxN/9Z4t9zdt9fVZpZmluXtNq@wU "Perl 5 – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 38 bytes
```
->x{(1..x).all?{|n|n+n.digits.sum!=x}}
```
[Try it online!](https://tio.run/##DchLDsIgFEbhuavQmcbfGy4ttQ7QhTQd1Ee1SSVGIMEAa8eOzpfz9ddfGXU5nEPcMlHY0TDPl5hMMntD9@k5OUvWvzc65Fyc7hgVFI44QQpUjLYBqxpKKkjUaNCCxbIgGWqBEEtEv3L0GG6vmEL6eGfXYxf6XP4 "Ruby – Try It Online")
[Answer]
# Python 2, ~~70~~ 66 Bytes
```
lambda x:[i for i in range(x)if i+sum([int(j)for j in`i`])==x]==[]
```
EDIT: -4 thanks to @user56656
[Answer]
# [Pyth](https://pyth.readthedocs.io), 8 bytes
```
!/m+sjdT
```
[Test suite.](https://pyth.herokuapp.com/?code=%21%2Fm%2BsjdT&input=154&test_suite=1&test_suite_input=1%0A3%0A5%0A7%0A9%0A20%0A31%0A86%0A154%0A525%0A2%0A4%0A6%0A8%0A10%0A15%0A21%0A50%0A100%0A500&debug=0)
If swapping truthy / falsy values is allowed, then we can drop the `!` and get 7 bytes instead. One of [Sok](https://codegolf.stackexchange.com/users/41020/sok)'s suggestions helped me golf 2 bytes.
## Explanation
```
!/m+sjdT – Full program. Takes an input Q from STDIN, outputs either True or False.
  m      – Map over the range [0 ... Q) with a variable d.
     jdT – Convert d to base 10.
    s    – Sum.
   +     – And add the sum to d itself.
 /       – Count the occurrences of Q in the result.
!        – Negate. Implicitly output the result.
```
[Answer]
# [Perl 6](https://perl6.org/), ~~39~~ 33 bytes
```
{!grep $_,map {$_+[+] .comb},^$_}
```
[Try it out!](https://tio.run/##K0gtyjH7n1upoJamYPu/WjG9KLVAQSVeJzexQKFaJV47WjtWQS85PzepVidOJb72f3FipUKahqGCgqY1F4RtjMQ2RWKbI7EtkdhGBkh6DRFsCzME29DUBGGmkSlCL5I5JkhsMyS2BRLb0ADZTCQ3INlriqzGwABJHMj@DwA)
A bare block with implicit single parameter, called thus:
```
say {!grep $_,map {$_+[+] .comb},^$_}(500);
> False
say {!grep $_,map {$_+[+] .comb},^$_}(525);
> True
```
Since `n + digits(n) >= n`, we can just calculate the Colombian number for all the numbers up to our query value and see if any of them match. So this calculates the Colombian number for a given input:
```
{$_ + [+] .comb}
```
Which we apply to all the values up to our target:
```
(^$_).map({$_+[+] .comb})
```
But we only care whether any of them match, not what those values are, so as pointed out by @nwellenhof, we can grep:
```
grep $_, map {$_+[+] .comb}, ^$_
```
The rest is just coercion to bool and wrapping in a block.
## 39 bytes
```
{!((^$_).map({$_+[+] .comb}).any==$_)}
```
[TIO test link provided by @Emigna](https://tio.run/##Tc5NCoMwEAXgvacYQUqCEBJrUkVyEmklLboyrdRVEM8eBRd5u4/5eTPL@J9N9IFuE9m45Yy9ioEL7xa2FUPZl08Sn59/71y4b7D2bO5xdYEmpoh4l12@gzX4AW7BlYRdldyYZKXrlFnptAs5NdiAG7CSmAk/wF2NM1JC/XQ8AA)
@nwellenhof pointed out that using grep would save 6 bytes!
[Answer]
# [Python 3](https://docs.python.org/3/), 60, 56, 55, 54 bytes
```
lambda x:{x}-{n+sum(map(int,str(n)))for n in range(x)}
```
[Try it online!](https://tio.run/##Lc3RCoIwGAXg@55iN@I/OoGbTU3oSaqLiVkD3WQaGOKzrwmdmwMfB874nd/O5qG73kOvh6bVbKnXZTut9jh9Bhr0SMbOmGZPlnPeOc8sM5Z5bV9PWvgWdjI73QQkcpyhUKBEhQtEBqEgM0iBXKAqouwUN7GVVI/6wP4ZfTyiNGnrZEoTMmic66kjE295@AE "Python 3 – Try It Online")
-4 using all inverse instead of any
-1 by changing != to ^ by @jonathan-allan
-1 by using sets by @ovs
[Answer]
# [J](http://jsoftware.com/), 20 bytes
```
#@-.i.+1#.10#.inv i.
```
[Try it online!](https://tio.run/##RY0xDoAwDAP3viJSR0SUFgplQOIviIoywMb3w0Lc7RT7nEu1rEx@67lyFzwH8VzvlyrrsZ8PFQruh8EgGcwGi0EUtOHlySikERsxOUgGSGFkqNJG4OFFaqlIO4p@ "J – Try It Online")
```
                  i.     Range [0,n-1]
          10#.inv        To base 10
       1#.               Sum the digits
    i.+                  Plus the corresponding number
  -.                     Remove from the input, leaves an empty list if it was a self number.
#@                       An empty list is truthy, so return the length instead.
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-d!`](https://codegolf.meta.stackexchange.com/a/14339/), 6 bytes
```
N¥U+ìx
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LWQh&code=TqVVK%2bx4&input=MjE)
---
## Original, 8 bytes
Returns the input number for truthy or `0` for falsey. If only the empty array were falsey in JavaScript, this could be 7 bytes.
```
ÂNkUÇ+ìx
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=wk5rVccr7Hg=&input=ODg=)
---
### Explanation
```
             :Implicit input of integer U
   UÇ        :Generate the range [0,U) and pass each Z through a function
      ì      :  Digits of Z
       x     :  Reduce by addition
     +       :  Add to Z
  k          :Remove the elements in that array
 N           :From the array of inputs
Â            :Bitwise NOT NOT (~~), casts an empty array to 0 or a single element array to an integer
```
---
### Alternative
```
Ç+ìxÃe¦U
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=xyvseMNlplU=&input=ODg=)
```
             :Implicit input of integer U
Ç            :Generate the range [0,U) and pass each Z through a function
  ì          :  Digits of Z
   x         :  Reduce by addition
 +           :  Add to Z
    Ã        :End function
     e       :Every
      ¦U     :  Does not equal U
```
[Answer]
# [Add++](https://github.com/cairdcoinheringaahing/AddPlusPlus), ~~27~~ 18 bytes
```
L,RFBDB+B]ARz€b+Ae
```
[Try it online!](https://tio.run/##S0xJKSj4/99HJ8jNycVJ2ynWMajqUdOaJG3H1P8lVtGGCsYKpgrmCpYKRgYKxoYKFmYKhqYmCqZGprFcaVbRRgomCmYKFgqGBkBhBSNDBVMgw8AASBnEcnG5luhwcaZkggglXTslIK2Sk5iblJKoYGgHEvXn4vJXUgKqSyOg7r@RAQA "Add++ – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/) `-apl -MList::Util=sum,all`, 28 bytes
```
$_=all{"@F"-sum/./g,$_}1..$_
```
[Try it online!](https://tio.run/##Fc27CsIwAAXQ/X5G6dikuekjTaHg5KSjc@ggEog2mDiJv26s@4ETr88wlFK7ZQ3hXR2OlUiveyvbW1O7D6WsXSmERoceA0YYTLCgAglqsAN7cABH0IATaKEVNGEN7G7/WOG7xey3RyrifPIpz/Ml@7DsVbO/Rawx/AA "Perl 5 – Try It Online")
[Answer]
# [Lua](https://www.lua.org/), 81 bytes
```
for i=1,...do a=i+0(i..''):gsub('.',load'a=a+...')b=b or a==0+...end print(not b)
```
[Try it online!](https://tio.run/##FctBCoAgEEDRq8xuFGWwwE0whxmxQhANs/NPtf28Xx9RPfqAwosnotxBuLhgChGi3c77SQYJfe2SUVjch9AmTvBNwhz@sLcM1yhtmtYnJKuqcY0v "Lua – Try It Online")
```
for i=1,...do
    a=i+0                            -- +0 is needed to avoid an error
    (i..''):gsub('.',load'a=a+...')  -- Sums up all the digits of i
    b=b or a==0+...                  -- Sets b to true if a equals the input
end
print(not b)
```
[Answer]
# [FunStack](https://github.com/dloscutoff/funstack) alpha, 46 bytes
```
All? Minus Plus foldl ToBase 10 hook map From0
```
Try it at [Replit](https://replit.com/@dloscutoff/funstack)!
### Explanation
First, we construct a function that adds a number to its base-10 digit sum:
```
Plus foldl                 Left-fold second argument on addition, with first
                           argument as starting value
                     hook  Take a single argument; pass it to the above function
                           twice: first, unchanged, and second, passed through
                           the following function:
           ToBase 10       Convert to list of base-10 digits
```
This is a bit shorter than the alternatives:
```
Plus Sum ToBase 10 over hook
Sum Pair ToBase 10 compose3
```
Then:
```
                   From0  Range of integers from 0 up to input-1
           ... map        Map the above function to each
     Minus                Subtract each from the input
All?                      Are all results truthy (non-zero)?
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), ~~18~~ 12 bytes
```
aNI:_+$+_M,a
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgUXTsgqWlJWm6FmsS_Tyt4rVVtON9dRIhQlCZJdFGBjBVAA)
*-6 thanks to @DLosc*
#### Explanation
```
aNI:_+$+_M,a  ; Full program. Input (a) on command line
         M,a  ; Map over the range from 0 to a (_)
      $+_     ;  Sum _
    _+        ;  And add this to _
aNI:          ; Is a not in this list?
              ; Implicit output
```
Old:
```
$*Y{\a!=a+$+a}M\,a  ; Full program. Input (n) on command line.
               \,a  ; Range from 1 to n
   {         }M     ; Map over this list (a):
          $+a       ;  Sum the digits of a
        a+          ;  Add to a
    \a!=            ;  And check if it's not equal to n
$*Y                 ; Get the product of this list
                    ; Implicit output
```
[Answer]
# [Arturo](https://arturo-lang.io), ~~36~~ 34 bytes
```
$->x[every? x'n->x<>+∑digits<=n]
```
[Try it](http://arturo-lang.io/playground?F6U5Kl)
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 55 bytes
```
.+
*
Lv`_+
_+
$&$.&
^_+
$&¶$&
\d
*
Cms`^(_+)\b.*¶\1\b
0
```
[Try it online!](https://tio.run/##HYlBDoIwFAX3c47aIE2a/wtFXLtw4xEaQKILF7hQ49E4ABerjckkb/Lmdf88nlfNu@o8Ze@ouXyn0VEw1njL8LdtNZZ0K/m0vKehGt0@zb7e1qRpRnJWGiIHjgShUfoOjS0xRAItHT0q5SIosYhIGfkB "Retina – Try It Online") Link includes test cases. Explanation:
```
.+
*
```
Convert input `x` to unary.
```
Lv`_+
```
Create a range from `x` down to `1`.
```
_+
$&$.&
```
Suffix the decimal value of each `n` to its unary value.
```
^_+
$&¶$&
```
Make a copy of `x`.
```
\d
*
```
Convert each decimal digit of `n` to unary, thus adding the digits to the existing copy of `n`.
```
Cms`^(_+)\b.*¶\1\b
```
Check whether `x` appears in any of the results.
```
0
```
Invert the result.
[Answer]
# JavaScript (ES6), ~~52~~ 51 bytes
*Saved 1 byte thanks to @l4m2*
Returns **0** or **1**.
```
n=>(g=k=>k?eval([...k+'k'].join`+`)-n&&g(k-1):1)(n)
```
[Try it online!](https://tio.run/##bctBDoMgEEDRfU/hSiCOBFCsbYI9iDGRWCWKHUxtvD5126Sr/zdvsYfdh/e8fXIMzzFOJqJpqDPeNP4xHnalLefcZ8STji9hxj7rWY5p6qjPJbtLRpHFIeAe1pGvwdFWQgEarnADJaCQUFcgdQla6Y6/7EYxMU0yUcwIYYxdfqyCEiqoQYrTgJKgzxHijPiH4xc "JavaScript (Node.js) – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), ~~63~~ 58 bytes
```
s 0=0
s x=x`mod`10+s(x`div`10)
f n=all(\x->x+s x/=n)[1..n]
```
[Try it online!](https://tio.run/##dZAxb8IwEIV3/4rXqAMIldopoTC4Q4cuoDK0G63kSHGUCONUOEHm1wcPDEjVu8n6Pt/d0zVlOFjnxjFAaikCoo7m2FVGyVmYRFO15/Scihpel85NfuLTW5ylb8/aT/dqPve/Y4QJTTe46t0aXKDxN/Rf/Wnr8Yi2RoTWCfeN9ch2mwzWBYvss@ux2zxkQhzL1qeuqhNIVUPdz/s@DfbGXwgvCH8lfE14Ltlilmi1JEIVCxY2Z3Hze/5RpiPdxIKJJRMrJpSkpmAmV8wUfJqUvOm/Gq8 "Haskell – Try It Online")
]


[Question]
      [
* Alice (A) and Bob (B) decided to have a battle.
* Each combatant has 10 health.
* They take turns to roll a 6 sided die for damage.
* That damage is removed from their opponent's health.
* In the end either Alice or Bob, will vanquish their foe.
---
Show me how the battle went. Outputting these codes for the actions which have taken place.
Attack
```
B a A
^ Combatant
  ^ Action (attack)
    ^ Target
```
Roll
```
B r 4
^ Combatant
  ^ Action (roll)
    ^ Value
```
Health change
```
A h 6
^ Combatant
  ^ Attribute (health)
    ^ Value
```
Win
```
A w
^ Combatant
  ^ Action (win)
```
---
Example output:
```
A a B
A r 4
B h 6
B a A
B r 6
A h 4
A a B
A r 6
B h 0
A w
```
---
Here are the rules:
* Write in any language.
* A single roll of the die should have an equal chance of resulting in any one of the numbers 1, 2, 3, 4, 5, or 6.
* Alice always starts (Bob is chivalrous, in an old-fashioned way).
* Output an action for each turn.
* You must report the attack, roll, damage and win actions.
* Combatants are upper case, actions are lower case.
* It must not consistently produce the same result.
* There must be at least one whitespace character between an output combatant, action and value.
* The win action takes place when the opponent has zero or less health.
* All parts of an action must be on the same line.
* There should be one action per line.
* Fewest bytes wins.
Have at it!

[Answer]
# [Python 3](https://docs.python.org/3/), 131 bytes
```
x,y="AB"
from random import*
X=Y=10
p=print
while X>0:p(x,"a",y);d=randint(1,6);p(x,"r",d);Y-=d;p(y,"h",Y);x,y,X,Y=y,x,Y,X
p(y,"w")
```
[Try it online!](https://tio.run/##Hc1BCsMgFATQvacIfxXLFBIKXVR@oD2FLgO2KDRGRIie3tqshuExTKzZ7eHWWkFler5IfNK@DWkNtoff4p7yRWg2PE8ickw@ZHE4/30PepkecSyglVClsvwfdR5n3KU6JRGsVObKtvcKcgQjVb@ChuGKAgMtTjpItvYD "Python 3 – Try It Online")
-8 bytes thanks to officialaimm
-2 bytes thanks to ChooJeremy
[Answer]
# [Python 3](https://docs.python.org/3/), 127 bytes
*This is an improvement on [@HyperNeutrino answer](https://codegolf.stackexchange.com/a/159903/20064) that wouldn't fit in a comment. See the explanation below.*
```
x,y="AB"
s=id(0)
X=Y=10
p=print
while X>0:p(x,"a",y);s=s**7%~-2**67;d=s%6+1;p(x,"r",d);Y-=d;p(y,"h",Y);x,y,X,Y=y,x,Y,X
p(y,"w")
```
[Try it online!](https://tio.run/##HY1BCsIwFAX3OYV8KDTxFVKFFgxf0FMkSyFCClJDU2iy8eqxdDnMwMSyhu98rTWjMD2eJBJPvtVSWHbcaxE5LtO8ii1Mn/fJ3vUtthn0IhRpEielxubXXZQaRuM5NcO5N0exELw0rmO/cwEFgpNm38DCcUGGgxWH2kjW@gc "Python 3 – Try It Online")
---
## An epic quest for a shorter python dice roll
**TL;DR: It's possible to shave 4 bytes off the standard python dice roll by using RSA encryption.**
I wanted to see if the standard python dice roll (**32 bytes**) could be shortened a bit:
```
from random import*;randint(1,6)
```
In particular, `id(x)` is quite convenient to bring some non-deterministic value into the program. My idea then was to somehow hash this value to create some actual randomness. I tried a few approaches, and one of them paid off: [RSA encryption](https://en.wikipedia.org/wiki/RSA_(cryptosystem)#Encryption).
RSA encryption, due to its simplicity, only requires a few bytes: `m**e%n`. The next random value can then be created by encrypting the previous one. Assuming the `(e,n)` key is available, the dice roll can be written with **22 bytes**:
```
s=id(0);s=s**e%n;s%6+1
```
That means we have about 10 bytes to define a valid RSA key. Here I got lucky. During my experiments, I started to use the [Mersenne prime](https://en.wikipedia.org/wiki/Mersenne_prime) **M67** only to realize later on that [Mersenne made a mistake](https://en.wikipedia.org/wiki/Mersenne_prime#History) including **M67** in his list. It turns out to be the product of `p=193707721` and `q=761838257287`. I had found my modulus:
```
n=~-2**67
```
Now, the exponent and the [Charmichael totient](https://en.wikipedia.org/wiki/Carmichael_function) `lcm(p-1,q-1)` need to be coprime. Luckily again, the first prime number that do not divide the totient of n is only one digit long: 7. The dice roll can then be written using **28 bytes** (4 bytes less than the standard approach):
```
s=id(0);s=s**7%~-2**67;s%6+1
```
One good thing with **M67** is that the random value generated has 66 bits, which is more than the usual 64 bits RNG. Also, the use of RSA makes it possible to go back in time by decrypting the current value multiple times. Here are the encrypting and decrypting keys:
```
Encryption: (7,                    147573952589676412927)
Decryption: (42163986236469842263, 147573952589676412927)
```
I'm definitely not an expert in statistics or cryptography, so I can't really tell whether or not this RNG checks the criteria for "good randomness". I did write [a small benchmark](https://gist.github.com/vxgmichel/2f7cb31f32c5d92810d44ccca36c99b7) that compares the standard deviation of the occurrences of the 1 to 6 dice rolls using different RNGs. It seems like the proposed solution works just like other ones.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~146~~ 141 bytes
```
f(A,B,r,t,a,b){for(A=B=10;r=1+clock()%6,A*B>0;t=!t)printf("%c a %c\n%c r %u\n%c h %i\n",a=65+t,b=66-t,a,r,b,t?A-=r:(B-=r));printf("%c w",a);}
```
[Try it online!](https://tio.run/##TYyxDsIgFAB3vwKbkPDsI2kHGSRo4CdculASaiNSgxiHpr8uVieXyy13jg/OleKZRoMJM1rsYfZTYloZ1TYyqbZ2YXJXBlSg3pljI7PaZrinMWbPKuqIJdR1cZVE6PMnF0LHLlZoldjXGXslBP@@E/aYT5qrdGBmJYD8@7zWAORSbnaMDOaNZyA3S3k7H@zwKPxsQ/gA "C (gcc) – Try It Online")
De-golf:
```
f(A,B,r,t,a,b){
    for(A=B=10; //Initialize HP
        r=1+clock()%6, // Get the number of processor cycles the program has consumed. This is relatively random, so I call it good enough.
        A*B>0;t=!t) // Flip t for change of turns
        printf("%c a %c\n%c r %u\n%c h %i\n", // Print the turn
            a=65+t,b=65+!t,a,r,b, // 65 is ASCII for 'A', 66 for 'B'
            t?A-=r:(B-=r)); // Deduct the damage.
    printf("%c w",a); // Print the winner
}
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 49 bytes
```
"BaABr0Aha"S3ô»D„ABÂ‡[6LΩ©Tǝ¤H®-©16ǝ=®0‹#s]н…ÿ w?
```
[Try it online!](https://tio.run/##AVAAr/8wNWFiMWX//yJCYUFCcjBBaGEiUzPDtMK7ROKAnkFCw4LigKFbNkzOqcKpVMedwqRIwq4twqkxNsedPcKuMOKAuSNzXdC94oCmw78gdz///w "05AB1E – Try It Online")
**Explanation**
```
"BaABr0Aha"                                        # push the initial state of B
           S                                       # split to list of characters
            3ô                                     # divide into 3 parts
              »                                    # join each part on space and all on nl
               D„ABÂ‡                              # make a copy with A and B inverted
                     [                             # start a loop
                      6LΩ©                         # pick a random number in [1 ... 6]
                          Tǝ                       # insert at position 10 of the string
                            ¤H                     # get the last char of the string and
                                                   # convert from hex
                              ®-©                  # subtract the random number
                                 16ǝ=              # insert at position 16 and print
                                     ®0‹#          # if the hp is less than 0, break
                                         s         # swap the other string to the stack top
                                          ]        # end loop
                                           н…ÿ w?  # print the winner
```
[Answer]
# [Perl 5](https://www.perl.org/), ~~93~~ ~~88~~ 87 bytes
```
$A=$B=10;$_=B;${$_^=v3}-=$%=1+rand 6,say"$_ a $'
$_ r $%
$' h $$_"until//>$$_;say"$_ w"
```
[Try it online!](https://tio.run/##K0gtyjH9/1/F0VbFydbQwFol3tbJWqVaJT7Otsy4VtdWRdXWULsoMS9FwUynOLFSSSVeIVFBRZ0LSBcpqKhyqagrZCioqMQrleaVZObo69sB2dZQheVK////yy8oyczPK/6v62uqZ2igZwAA "Perl 5 – Try It Online")
[Answer]
# JavaScript (ES6), 122 bytes
```
f=(h=[10,10,p=0])=>`${x='AB'[p]} a ${y='BA'[p]}
${x} r ${d=Math.random()*6+1|0}
${y} h ${H=h[p^=1]-=d}
${H<1?x+' w':f(h)}`
```
[Try it online!](https://tio.run/##HcmxDoIwFIXh3afoQNJWhNDFwXg1MLH4BARDQynVIG2AKAT77LWYnOX835O/@VgPDzNFvRaNcxKIgoIlBz8DSUnhUgXrDDjNcGFKizgK1gVwlv7vzptFg28CbnxS8cB7oV@E7o8h@yabLxYp7zmowtyBlRGILedndp1DjD74JImitnK17kfdNXGnWyIJpe4H "JavaScript (Node.js) – Try It Online")
[Answer]
# [Java (JDK 10)](http://jdk.java.net/), 180 bytes
```
v->{var r="";int p=0,H[]={10,10},h=0;for(;H[0]*H[1]>0;)r+=r.format("%3$c a %4$c%n%3$c r %d%n%4$c h %d%n",h+=Math.random()*6-h+1,H[p]-=h,p+65,(p^=1)+65);return r+(char)(66-p)+" w";}
```
[Try it online!](https://tio.run/##LY8xb4MwEIX3/IoTCpIdjAVqy@I6Y5UlU6QuiEouhNjUGMsYqijit1OXdrrv3r270@vELNKu@VprLcYRzkIZeOwA7PSpVQ2jFz6UeVAN9GGGLt4pcysrEO424s0K0IUjdPJK03YytVeDoW//8PoeVsnf1hFavs7p8TELB45HEVPGg@UZOZUVf@QZybOFSJ6xdnCIncqsOpzKvDpmDLuEOxrkXngUxU/7GgTEz/s6NlvjIG4CBgHkhhGRCT8LL6kTphl6hA9FKpM8vLJVyiWxSfFCkP3gOQ6Embv6yRlwCaqlcBgVRWpxEsF3xJaVbTEv99FfezpMntqQx2uDWiqs1XdkJq0x/rUtu2X9AQ "Java (JDK 10) – Try It Online")
## Credits
* -8 bytes thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen)
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~122 120 96 92~~ 91 bytes
```
f=->x=?A,y=?B,m=10,n=m{p [x,?a,y],[x,?r,r=1+rand(6)],[y,?h,t=n-r]
t<1?p([x,?w]):f[y,x,t,m]}
```
Saved 1 byte thanks to [Asone Tuhid](https://codegolf.stackexchange.com/users/77598/asone-tuhid).
[Try it online!](https://tio.run/##KypNqvz/P81W167C1t5Rp9LW3kkn19bQQCfPNre6QCG6Qsc@UacyVgfEKNIpsjXULkrMS9Ew0wQKVerYZ@iU2ObpFsVyldgY2hdogFSVx2papQHlKnRKdHJja/@nRcf@BwA "Ruby – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 142 bytes
```
#define R(c,t)r=rand()%6+1,c&&printf(#c" a "#t"\n"#c" r %d\n"#t" h %d\n",r,t-=t<r?t:r),t||puts(#c" w")
f(A,B,r){for(A=B=10;A*B;R(B,A))R(A,B);}
```
[Try it online!](https://tio.run/##RY7BasMwEETP8VcsMgnaVgLn0kMVE@xP8KWXUnBlKxW1ZbNe00OSX68apYVehplZlnlWn6yNMe9650MPjbSKkUpqQydx@/S4V3a3m8kHdjK3AloQOYvXIFIg2HbJsoCPX6tIsS75QEd@JlR8ucwrL/fPL4GZk5WqFeHZTSSrsi73hakeatPIWlWITTqjucbbHIytDxLhnG2WOw37sZcFwhvYYbKfEtFkGyeT/vElrP@Sel4pQGGya/y2bmhPS9QvYdJ@nAdvPUftbul99QP78AM "C (gcc) – Try It Online")
[Answer]
# Java 8, ~~230~~ ~~229~~ 228 bytes
```
v->{for(int h=104,a=h,x=0,y=1,A=10,B=A,r=0,t=0,T;a<119;System.out.printf("%c %3$c %c%n",x+65,y=(a<98?t=r+=Math.random()*6-r+1:a>h?(T=x<1?A-=t:(B-=t))<0?0:T:A*B<1?-16:(x^1)+17)+48,a=a<98?114:a>h?h:A*B<1?119:97))x^=a>h|A*B<1?1:0;}
```
-2 bytes thanks to *@ceilingcat*.
Note: there is already [a much shorter Java answer, so make sure to upvote his](https://codegolf.stackexchange.com/a/159906/52210)! I use a completely different approach however, so figured it was worth posting as well.
**Explanation:**
[Try it online.](https://tio.run/##LVDfb4IwEH7fX9GYmbRSCM2cPwqV4Lu@SPayzKQrMHBYTKkE4/zb2akkd9f0u/su930H2Uq3PmX6kP72qpJNgzay1NcXhEptM5NLlaHt/YtQW5cpUvjj/rQkAOwGCdFYaUuFtkgjgfrWXV3z2mDgo0Iwf0qlKGgnfHoRjMaA0LWIqQHAQiaBDBlbBrtLY7OjV5@tdzLAzfForND47RWKGusR7ZzZO6zAMlwuIiuMIzbSFp6ROq2PmExmrnEYl6siwonoQhbFrrAcr6ESEvqRzxMeT9bQcNmM427PiMPmxJku4MDHUsamD34xzMFZfDknpNsLgP8GkPvBrQ@eyk/n7wqUDwY8DDqCfXhnQcLP55ckT@u0p7A@V9Xg2q3/Bw)
```
v->{                     // Method with empty unused parameter and no return-type
  for(int h=104,         //  Temp integer with unicode for 'h' to save bytes
          a=h,           //  Second part (Action)
          x=0,           //  First part
          y=1,           //  Third part
          A=10,          //  Score player A, starting at 10
          B=A,           //  Score player B, starting at 10
          r=0,           //  Random dice-roll
          t=0,           //  Previous dice-roll
          T;             //  Temp integer
      a<119              //  Loop until there is a winner:
      ;                  //    After every iteration:
       System.out.printf(//     Print:
        "%c %3$c %c,%n", //      The three parts with spaces, and a new-line
                         //      First part:
        x+65,            //       Add 65 to `x` to convert 0/1 to 65/66
                         //       (unicode values of A/B)
        (y=              //      Third part (after set-up):
           (a<98?        //       If the previous action was 'a'
             t=r+=Math.random()*6-r+1
                         //        Roll the dice, and save it in `t`
            :a>h?        //       Else-if the previous action was 'r':
             (T=x<1?     //        If the first part changed to player A:
              A-=t       //         Subtract the previous dice-roll from A
             :           //        Else:
              (B-=t))    //         Subtract the previous dice-roll from B
             <0?         //        If this score is below 0:
              0          //         Use 0
             :           //        Else:
              T          //         Use this score
           :             //       Else (the previous action was 'h'):
            A*B<1?       //        Is there a winner:
             -16         //         Change the third part to a space
            :            //        Else:
             (x^1)+17)   //         Change the third part to the other player
         +48,            //       Add 48 to convert it to unicode
         a=              //      Second part:
           a<98?         //       If the previous action was 'a':
            114          //        Change it to 'r'
           :a>h?         //       Else-if the previous action was 'r':
            h            //        Change it to 'h'
           :             //       Else (the previous action was 'h'):
            A*B<1?       //        If either score is 0:
             119         //         Use 'w'
            :            //        Else:
             97))        //         Use 'a'
    x^=                  //   First part set-up:
       a>h               //    If the previous action is 'r',
       |A*B<1?           //    or there is a winner:
         1               //     Change A→B or B→A
       :                 //    Else:
         0;}             //     A/B remains unchanged
```
[Answer]
## Batch, 174 bytes
```
@set/aA=B=10
@set c=A
@set d=B
:g
@set/ar=%random%%%6+1,h=%d%-=r
@echo %c% a %d%
@echo %c% r %r%
@echo %d% h %h%
@if %h% gtr 0 set c=%d%&set d=%c%&goto g
@echo %c% w
```
Explanation: `%` variable references are substituted at parse time. This has two useful benefits:
* `%d%-=r` subtracts `r` from the variable named by `d` (i.e. indirect reference)
* `set c=%d%&set d=%c%` is simply a straight swap.
[Answer]
# PHP 7.1: 159 bytes
```
<?php $A=$B=10;$t='AB';while($A>0&&$B>0){$a=$t[0];$b=$t[1];$d=rand(1,6);$$b-=$d;echo"$a a $b\n$a r $d\n$b h {$$b}\n";$t=strrev($t);}echo($A>0?'A':'B')." w\n";
```
[Run it in the browser here!](http://sandbox.onlinephpfunctions.com/code/79a833581d55a878c3e79a8da8cfb5a8a5cc1303)
# PHP 5.6: 156 bytes
```
<?php $A=$B=10;$t='AB';while($A>0&&$B>0){list($a,$b)=$t;$d=rand(1,6);$$b-=$d;echo"$a a $b\n$a r $d\n$b h {$$b}\n";$t=strrev($t);}echo($A>0?'A':'B')." w\n";
```
[Run it in the browser here!](http://sandbox.onlinephpfunctions.com/code/ad3752f87c8167f19b29920b4309d5728f413706)
Here's what the PHP 5.6 solution looks like with formatting and comments:
```
<?php
// Initialize both HP counters
$A = $B = 10;
// Set the turn order as a string (which 5.6 allows to be unpacked into a list)
$t = 'AB';
// Run this loop as long as both players have HP
while ($A > 0 && $B > 0) {
    // Unpack the turn string into $a and $b variables; on the first run, $a = 'A'
    // and $b = 'B'. This is no longer possible in PHP 7.0, so the PHP 7.0
    // solution needed to use an array instead.
    list($a, $b) = $t;
    // Set damage to a random number between 1 and 6
    $d = rand(1, 6);
    // Subtract the damage from the referenced value $b. On the first turn, this
    // is 'B', so this ends up subtracting $d from $B. Next turn, $b will be 'A',
    // so it'll subtract $d from $A
    $$b -= $d;
    // Echo the string (interpolated values)
    echo "$a a $b\n$a r $d\n$b h {$$b}\n";
    // Reverse the turn order string ('AB' becomes 'BA', which will affect the
    // call to list in the first line of the while-loop)
    $t = strrev($t);
}
// Someone's run out of HP; figure out whom by figuring out who still has HP
echo ($A > 0 ? 'A' : 'B') . " w\n";
```
[Answer]
# F#, 238 235 bytes
I thought I was doing well, but you've all far outclassed me!
```
let p=printfn
let mutable A=10
let mutable B=A
let x h a d=
 p"%s a %s"a d
 let i=(new System.Random()).Next(1,7)
 let j=h-i
 p"%s r %i"a i
 p"%s h %i"d j
 if j<=0 then p"%s w"a
 j
while A*B>0 do
 B<-x B"A""B"
 if B>0 then A<-x A"B""A"
```
[Try it online!](https://tio.run/##VY9RS8MwFIXf@ysOkbFVXNs9CbIMWtAnEXG@iQ/Zmi4pbRLSzG2/vt6sKviW833nXm6aYbm3Xo55jmcpvEFPCWJnjwFPNxABKgT3kOfNoIR3mfWHhLpbKRGUxJw678dgvRbdHM7bVu4DGuunPUp2LkuSj/WjCf7yarUJm8@kkwG90AbCH77AMSISx50n35jkGvtjELtOouSr4j@peDmBMxQEap4Ajs0Ges8GRoBy1JovjDxhexmC7LM3YWrbL9I0e5HnsFjd3ac/vZarpf7d4THTtOMvq5hrtJR1g3bNi/hvM8kTE8TJnZSOp95WmwK1JVatl2dUrGSsYtNoVNfJMqqSONkRxfgN)
Thanks to Rogem for the brilliant advice to use A\*B>0 instead of A>0&&B>0 (takes off 3 bytes).
Thank you also to officialaimm, whose hint about predefining printf in the Python answer helped me shave a few bytes off too.
[Answer]
# [Haskell](https://www.haskell.org/), 204 bytes
My attempt with Haskell, I wasn't able to get it more competitive unfortunately
```
import System.Random
main=getStdGen>>= \g->putStr$q(randomRs(1,6)g)10(10::Int)"A ""B "
(!)=(++)
l="\n"
q(x:z)a b p o=p!"a "!o!l!p!"r "!show x!l!o!"h "!show n!l!if n<1then p!"w"else q z n a o p where n=b-x
```
[Try it online!](https://tio.run/##NYw9y8IwFEb3/oqbi0OCH9jFoZiCLuKqq0vEa1NMb9ok0uqfr@GFdzvn4fBYE1/k3Dy3Xe9DgusnJuo2F8MP3xWdaVk3lK7pcSKuaw23Zl337zyExSDDX3WJslztVKPKrSy3VXXmpPAAiEfAQgql5XKpCqfxxlgMcqq@ysAdevC6F2gAhRdOZAwZo/UjTNm9QPvvnL19Au/LZIkhpyOSiwQDfIHBgM9vo6VAwPq@nub5Bw "Haskell – Try It Online")
Explanations:
```
import System.Random  --import random module
main=                        --main function, program entry point
 getStdGen                   -- get the global random number generator
   >>= \g->                  --using the random generator g
       putStr $ q            --print the result of function q, passing in ..
          (randomRs (1,6) g) --an infinite list of random numbers, 1 to 6 generated by g
           10 (10::Int)      --the starting health of both players,
                             --type annotation sadly seems to be required
           "A " "B "         --The names of the players,
                             --with an extra space for formatting
(!)=(++) --define the operator ! for list (String) concatenation,
         -- we do this a lot so we save a bit by having a one byte operator
l="\n"   -- define l as the newline character
q      --define function q
 (x:z) --our list of random numbers, split into the next number (x) and the rest (z)
 a     -- the health of the active player
 b     -- the health of the player getting attacked
 p     -- the name of the active player
 o     -- the name of the player getting attacked
=
  p!"a "!o!l --create the attack action string with a newline
 !p!"r "!show x!l -- append the roll action
 !o!"h "!show n!l -- append the health remaining
 !           -- append the result of the following if
  if n<1     -- if the player being attacked has been defeated
  then p!"w" -- append the win string for the active player
  else q z n a o p  --otherwise append the result of calling q again with
                    --rest of the random numbers, and the active players swapped
  where n=b-x -- define the attacked player's new health n
              -- their current health b - the random roll x
```
[Answer]
# [Julia 0.6](http://julialang.org/), 175 bytes
```
p=println()
f(l="AB",h=[10,10],a=1)=(while min(h...)>0;d=3-a;p(l[a]," a ",l[d]);r=rand(1:6);h[d]-=r;p(l[a]," r ",r);p(l[d]," h ",max(h[d],0));a=d;end;p(l[findmax(h)[2]]," w"))
```
[Try it online!](https://tio.run/##RcpBCsIwEIXhvacoWc1AWhKFLgwj6DVCFgPTkkgMJSj19rHtxuX/3vf85MRjawstNZV3LoCnGTKp@0PpSN4abU3QTBYJ1pjy1L1SgTgMA96ME7r07BbInoNWHXdKZy8BXaXKRcBeR3RxW3qqf1Y3VvFo2Ttu/eIv7FAbRMckbipyiDkVOU7057DrVSG29gM "Julia 0.6 – Try It Online")
Long, ungolfed version:
```
function status(player, health)
    println("$player h $(max(0,health))")
end
function roll(player)
    x = rand(1:6)
    println("$player r $x")
    x
end
function play()
    players = ["A","B"]
    healths = [10, 10]
    attacker = 1
    while min(healths...) > 0
        println("$(players[attacker]) a $(players[3-attacker])")
        healths[3-attacker]-=roll(players[attacker])
        status(players[3-attacker], healths[3-attacker])
        attacker = 3 - attacker
    end
    winner = findmax(healths)[2]
    println("$(players[winner]) w")
end
```
[Answer]
## VBA, ~~222~~ ~~185~~ 179 Bytes
This recursive solution involves 3 subs
1. g is the *game start* that kicks off the first turn
2. t is called for each *turn*. It uses recursion.
3. ~~p is shorter than Debug.Print when used more than 3 times (only 4 in this solution)~~ *Edit:* Now that I learned that `Debug.?` is an acceptable alternative to `Debug.Print`, `Debug.?x` is shorter than calling a Sub to print.
```
Sub g()
t "A",10,"B",10
End Sub
Sub t(i,j,x,h)
d=Int(Rnd()*6)+1
Debug.?i &" a "&x
Debug.?i &" r "&d
h=h-d
If h<1Then
Debug.?i &" w"
Else
Debug.?x &" h "&h
t x,h,i,j
End If
End Sub
```
This was a fun challenge. If you know of an online interpreter like TIO for VB6/VBScript/VBA please leave a comment. Then I can post a link to a working solution.
If you want to test this code and have Microsoft Excel, Word, Access, or Outlook installed (Windows only), press Alt+F11 to open the VBA IDE. Insert a new code module (Alt+I,M) and clear out Option Explicit. Then paste in the code and press F5 to run it. The results should appear in the Immediate Window (press Ctrl+G if you don't see it).
*Edit 1:* Removed whitespace that the VBA editor will automatically add back in. Reduced by 37 bytes
*Edit 2:* Removed Sub p()\* to save 6 bytes after learning `Debug.?` is an acceptable alternative to `Debug.Print`. Calling a [Sub](https://codegolf.stackexchange.com/a/166127/69061) to handle `Debug.?` only saves bytes after more than six calls.
]