[Question]
  [
In Russia we have something like a tradition: we like to look for lucky tickets. 
Here's what a regular ticket looks like:
[![bus ticket](https://i.stack.imgur.com/0bqM1m.jpg)](https://i.stack.imgur.com/0bqM1m.jpg)
As you can see, the ticket has a six-digit number.
A six-digit number is considered **lucky** if the sum of the first three digits is equal to the sum of the last three.
The number on the photo is not lucky:
```
038937
038 937
0 + 3 + 8 = 11
9 + 3 + 7 = 19
11 != 19
```
## Challenge
Given the limits of a range (inclusive), return the number of lucky ticket numbers contained within it.
## Parameters
* Input: 2 integers: the first and last integers in the range
* The inputs will be between 0 and 999999 inclusive
* Output: 1 integer: how many lucky numbers are in the range
* You may take the inputs and return the output in [any acceptable format](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods)
* Assume leading zeros for numbers less than 100000.
## Examples
```
0, 1 => 1
100000, 200000 => 5280
123456, 654321 => 31607
0, 999999 => 55252
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest answer in bytes in every language wins.
Update: here's the lucky one [![lucky one](https://i.stack.imgur.com/a5RK9.jpg)](https://i.stack.imgur.com/a5RK9.jpg)
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~8 (or 10?)~~ 11 (or 13?) [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Ÿʒ₄n+¦S3ôOË
```
[Try it online](https://tio.run/##MzBNTDJM/f//6I5Tkx41teRpH1oWbHx4i//h7v//DYwtLE0NuECUgQEA) or [verify some more test cases](https://tio.run/##MzBNTDJM/W/q5un5/@iOU5MeNbXkaR9aFmx8eIv/4e7/tTr/DYwtLE0NuECUAZAyMDSAUIZgygjCMwLxjIzAPCAFkTMwgGkwBAA).
NOTE: In 05AB1E strings and integers are interchangeable, so the output numbers doesn't contain leading zeroes. This could however be fixed with 1 additional byte (**12 bytes**):
```
Ÿ₄n+€¦ʒS3ôOË
```
[Try it online](https://tio.run/##MzBNTDJM/f//6I5HTS152o@a1hxadmpSsPHhLf6Hu///NzC2sDQ14AJRBgYA) or [verify some more test cases](https://tio.run/##MzBNTDJM/W/q5un5/@iOR00tedqPmtYcWnZqUrDx4S3@h7v/1@r8NzC2sDQ14AJRBkDKwNAAQhmCKSMIzwjEMzIC84AURM7AAKbBEAA).
+3 bytes to bug-fix numbers with a length of 3 or less (range `[000000, 000999]`).
**Explanation:**
```
Ÿ          # Create an inclusive (on both sides) range from the two inputs
           #  i.e. 038920 and 038910 → 
           #   [38910,38911,38912,38913,38914,38915,38916,38917,38918,38919,38920]
 ʒ         # Filter this list by:
  ₄n+      #  Add 1,000,000 to the number
     |     #  And remove the leading 1
           #   i.e. 38910 → 1038910 → '038910'
  S        #  Transform it to a list of digits
           #   i.e. '038910' → ['0','3','8','9','1','0']
   3ô      #  Split it into chunks of length 3
           #   i.e. ['0','3','8','9','1','0'] → [['0','3','8'],['9','1','0']]
     O     #  Sum the digits in both parts
           #   i.e. [['0','3','8'],['9','1','0']] → [11,10]
      Ë    #  Check if they are equal (if they are, they remain in the filtered list)
           #   i.e. [11,10] → 0
```
---
EDIT: Seems I (and most other answers) slightly misread the challenge and the amount of numbers is being asked instead of the numbers themselves within the range. In that case a trailing `}g` can be added (close the filter; and get the amount of numbers left in the filtered list), so it's **~~10~~ 13 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)** instead:
```
Ÿʒ₄n+¦S3ôOË}g
```
[Try it online](https://tio.run/##MzBNTDJM/f//6I5Tkx41teRpH1oWbHx4i//h7tr0//8NjC0sTQ24QJSBAQA) or [verify some more test cases](https://tio.run/##MzBNTDJM/W/q5un5/@iOU5MeNbXkaR9aFmx8eIv/4e7a9P86/w2MLSxNDbhAlAGQMjA0gFCGYMoIwjMC8YyMwDwgBZEzMIBpMAQA).
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 93 + 18 = 111 bytes
```
a=>b=>Enumerable.Range(a,b-a+1).Select(e=>$"{e:D6}").Count(e=>e[0]+e[1]+e[2]==e[3]+e[4]+e[5])
```
[Try it online!](https://tio.run/##rZA/a8MwEMV3fQoROkgkMbb7B9pUXtJ2aqE0Qwbj4aycjcCRWkkOhODP7squM3Voh7zhnTjufryTdEtpLPatU7qmm6PzuI9elf5aESIbcI6@kxOhQZ9WHcAjdR68ktQi7Ixujuedl1bLR6X94ncjWJbRiooeRFaK7Fm3e7RQNhh9gK6RwaJcwjzh0QYblJ6hyK5mJ3x4uutmPFqbVo89zONijnkyWFoIgfn18LwZ7LbgPZ0Uog9lCnowakffQGnmvA1H5gUFWzs@zvycNmhKvTbamRBsa5XH8A/IKpbEccxZEgrnq78X/jNTsXSEpheGphM2vTA4MO9HnZkd6Uj/DQ "C# (.NET Core) – Try It Online")
18 bytes for `using System.Linq;`. I supposed that the input and output formats could be flexible. So I take two integers as input (the range, inclusive).
Some test results:
```
a=1000
b=1100
Lucky numbers = 3 [001001, 001010, 001100]
a=2000
b=2100
Lucky numbers = 3 [002002, 002011, 002020]
a=222000
b=222100
Lucky numbers = 7 [222006, 222015, 222024, 222033, 222042, 222051, 222060]
a=0
b=999999
Lucky numbers = 55252 (that's 5.5% of the total numbers)
```
[Answer]
# JavaScript (ES6), 66 bytes
Takes input in currying syntax `(m)(n)`, where **m** is the ~~exclusive~~ inclusive upper bound and **n** is the inclusive lower bound.
```
m=>g=n=>n<=m&&![...n+=''].reduce((t,d,i)=>t-=n[i+3]?d:-d,0)+g(-~n)
```
[Try it online!](https://tio.run/##Zcg7DsIwDADQnVuwtLbyUVQ2hMNBqg5VnEZBrYPawMjVg8TKG99jfs9H2POzGikc20JtI59IyMuNtq47j9ZaUdT3k90jv0IEqJp1RvLVkIxZXaY7Xw1rhyqB@Qi2UOQoa7RrSbDA4JxDcIinvx9@374 "JavaScript (Node.js) – Try It Online")
### How?
We test each number \$n\$ by walking through its digits \$d\_i\$ and updating a total \$t\$:
* \$t \gets t - d\_i\$ if there are at least 3 remaining digits after this one
* \$t \gets t + d\_i\$ otherwise
If we have \$t=0\$ at the end of the process, then \$n\$ is a lucky number.
---
# JavaScript (ES6), 67 bytes
Same input format.
```
m=>g=n=>n<=m&&!eval([...n/1e3+''].join`+`.split`+.`.join`^`)+g(n+1)
```
[Try it online!](https://tio.run/##ZcjBDoIwDADQu3/hBdo01oFXx48YTRccy8joCCP8/kz06Du@2R2ujFtc94vmt6@TrYsdglU76N0uTXP2h0vwYGa9dv5GbfvkOUcVEi5rirsQy29eghRAqcM6Zi05eU45wAS9MQbBIJ7@vv9@/QA "JavaScript (Node.js) – Try It Online")
### How?
For each number \$n\$:
* divide it by \$1000\$: e.g. `38937 --> 38.937`
* coerce to a string and split: `['3','8','.','9','3','7']`
* join with `+`: `"3+8+.+9+3+7"`
* replace `+.` with `^`: `"3+8^+9+3+7"`
* evaluate as JS code and test whether the result is \$0\$: `24` (\$11\$ XOR \$19\$)
If \$n \equiv 0 \pmod{1000}\$, no decimal point is generated and the evaluated expression is just a positive sum (falsy), unless \$n=0\$ (truthy). This is the expected result in both cases.
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~56~~ 54 bytes
```
->a,b{(a..b).count{|i|j=i.digits;j[0,3].sum*2==j.sum}}
```
[Try it online!](https://tio.run/##NYtBDoIwEEX3nGKWYGpTphQ0pnqQpgvQYNqgGIGFoZy9to3@ZDJ/8ua9l@7je@n355Z0a95S2hX0Oi7PeXXGWWnozdzNPJ2sYoRrOi2PHUppY9k2/wKVAajAoNRp0lmyGAKYdgACD@zPkFeiJlCLimOUeFmz5geDc0yJjkCBOtO0HYbL6nJDwBYERhc@e2WI1SAljNnmvw "Ruby – Try It Online")
### Method:
1. For every number, creates an array of digits (which comes out reversed)
2. Compares the sum of the first 3 digits in the array (last 3 in the number) multiplied by 2 to the sum of the entire array
3. Counts the numbers for which the two sums are equal
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~38~~ 15 bytes
```
õV Ëì ò3n)mx r¥
```
*-23 thanks to Shaggy!*
My first Japt submission; thanks to Shaggy for all the help!
[Try it online!](https://tio.run/##y0osKPn///DWMIXD3YfXKBzeZJynmVuhUHRo6f//uhVcRkZGBgYGIMrQwAAA "Japt – Try It Online")
[Answer]
# Python 3, 117 113 106 135 bytes
This is my first answer ever so I'm sure there's room for improvement.
```
def x(a,b):
    n=0
    for i in range(a,b+1):
        if sum(map(int,str(i//1000)))==sum(map(int,str(i%1000))):n+=1
    print(n)
```
* *-4 bytes thanks to W W*
* *-7 bytes thanks to Asone Tuhid*
* *+29 bytes to create a function*
Gets the first three digits through integer division, and the last three through modulo. The first and last integers in the range are inputted as arguments of the `x` function, as `a` and `b`, respectively. Output is `n`, printed.
Ungolfed:
```
def x(a, b):
    n = 0
    for i in range(a, b + 1):
        if sum(map(int, str(i // 1000))) == sum(map(int, str(i % 1000))):
            n += 1
    print(n)
```
[Answer]
# [R](https://www.r-project.org/), ~~93~~ 86 bytes
Shorter logic at the end compliments of @Giuseppe/
```
function(a,b){for(i in sprintf("%06d",a:b)){x=utf8ToInt(i);F=F+!sum(x[1:3]-x[4:6])}
F}
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/TyNRJ0mzOi2/SCNTITNPobigKDOvJE1DSdXALEVJJ9EqSVOzusK2tCTNIiTfM69EI1PT2s3WTVuxuDRXoyLa0Mo4Vrci2sTKLFazlsut9n@ahoGOJRho/gcA "R – Try It Online")
Integer inputs. Pad them with `0`. Convert to the six ASCII code points. Abuse the `F` builtin.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 12 bytes
```
#ȯ§¤=Σ↓↑3↔d…
```
[Try it online!](https://tio.run/##yygtzv7/X/nE@kPLDy2xPbf4UdvkR20TjR@1TUl51LDs////hgYg8N8ITAEA "Husk – Try It Online")
## Explanation
```
#(§¤=Σ↓↑3↔d)…  -- example input: 100000 101000
            …  -- inclusive range: [100000,100001..100999,101000]
#(         )   -- count elements where (example with 100010)
          d    -- | digits: [1,0,0,0,1,0]
         ↔     -- | reversed: [0,1,0,0,0,1]
  §     3      -- | fork elements (3 and [0,1,0,0,0,1])
       ↑       -- | | take: [0,1,0]
      ↓        -- | | drop: [0,0,1]
   ¤=          -- | > compare the results by equality of their
     Σ         -- | | sums 1 == 1
               -- | : 1
               -- : 3
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 15 bytes
```
ＩＬΦ…·ＮＮ⁼Σι⊗Σ÷ιφ
```
[Try it online!](https://tio.run/##VclBCsJADIXhvafoMoUKY7curUJBRPQE02loA@lUZ5Jefwzixrf44eOF2aewei7lnigKnHwWuGKcZIYLsWCCPgbWTBs@fJzQ@FK56TLYVTfVH83nt3rO8NQFyNitOjCOX/dROtpoRKCmOjjn6t@OpbTGXWst@40/ "Charcoal – Try It Online") Link is to verbose version of code. Edit: I originally thought that it was the list of lucky numbers that was required. This can be done in 14 bytes (by removing the `Ｌ`, which takes the length of the list), or in 20 bytes if you want some nice formatting:
```
ＥΦ…·ＮＮ⁼Σι⊗Σ÷ιφ﹪%06dι
```
[Try it online!](https://tio.run/##VcpBCsIwEAXQvacIBWEKEWIXbtzWQhcV0ROkTdCBaVLTTK8fR3fO4sP7f6aXTVO0VMotYcgw2AU6pOwT9GEiXnHzdxueXrhwvvI8ylRr9Ufx5c2WVnjwDChsI4/k3c99yC1u6DygVkdjTP09rYbomCJUe3NylVYo5bmURh52jWQ5bPQB "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
    ＮＮ                  Input the range endpoints
  …·                    Inclusive range
 Φ                      Filter
        ι               Current value
       Σ                Sum of digits
            ι           Current value
             φ          Predefined variable 1000
           ÷            Integer divide
          Σ             Sum of digits
         ⊗              Doubled
      ⁼                 Equals
Ｅ                       Map over results
                   ι    Current value
               %06d     Literal string
              ﹪         Format value
                        Implicitly print each result on its own line
```
[Answer]
## [Perl 5](https://www.perl.org/) + `-pl -MList::Util+(sum)`, 49 bytes
```
@F=/./g,$\+=sum@F[5,4,3]==sum@F[2,1,0]for$_..<>}{
```
[Try it online!](https://tio.run/##K0gtyjH9/9/BzVZfTz9dRyVG27a4NNfBLdpUx0THONYWyjPSMdQxiE3LL1KJ19Ozsaut/v/fgMvQEgj@5ReUZObnFf/XLcj5r@vrk1lcYmUVWpKZo60B1KoJAA "Perl 5 – Try It Online")
---
## [Perl 5](https://www.perl.org/) + `-nl -MList::Util+(sum) -M5.010`, 50 bytes
To output each ticket instead is +1 byte:
```
@F=/./g,sum@F[5,4,3]-sum(@F[2,1,0])||say for$_..<>
```
[Try it online!](https://tio.run/##K0gtyjH9/9/BzVZfTz9dp7g018Et2lTHRMc4VhfI0QDyjHQMdQxiNWtqihMrFdLyi1Ti9fRs7P7/N@AytASCf/kFJZn5ecX/dfNy/uv6@mQWl1hZhZZk5mhrAA3QBAqZ6hkYGgAA "Perl 5 – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), ~~89~~ 86 bytes
-2 thanks to Mr. Xcoder.
-3 inspiring from Asone Tuhid answer's.
```
lambda a,b:sum(sum(map(int,str(i)))==2*sum(map(int,str(i)[-3:]))for i in range(a,b+1))
```
Tests results : 
```
Example 1 : 
a = 0
b = 1
Lucky numbers : 1 
Example 2 : 
a = 100000
b = 200000
Lucky numbers : 5280 
Example 3 : 
a = 123456
b = 654321
Lucky numbers : 31607 
Example 3 : 
a = 0
b = 999999
Lucky numbers : 55252 
```
[Try it online!](https://tio.run/##fczBDoIwDAbg@56i2WnVmUC5LeHozTcQD0NBF9lYBiTy9Mhi0BiihyZ/2r@fH/tb67Kpzoup0ba8aNCyVN1gRRyrvTCul10fhEHEPKfNen/cZeqEWLcBDBgHQbtrJWZnmyJOPsxNwTnfP7T1TQUpKGAackiTJGFlDHNih@F8H8ENtqxCB2p@kLWIFRnPKHnhODK24mjhaOHoJxcrkv5y2ZujD0h/SHqh9MVOTw "Python 3 – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), 24 bytes
```
&:1e3&\,!'%03d'&V2&sw]=s
```
[Try it online!](https://tio.run/##y00syfmf8F/NyjDVWC1GR1Fd1cA4RV0tzEituDzWtvi/S8h/S0tLAwMuSxDgMuAy5DIwMDQACgApIM0FYgMpIzAFAA "MATL – Try It Online")
*(-2 bytes thanks to Luis Mendo.)*
`&:` - Make an inclusive range between the two given numbers
`1e3&\` - 'divrem' - divide by 1000 and get the reminders and floored quotients in two arrays. 
`,` - do twice
`!'03d'&V` - transpose and convert each value to a zero-padded three-width string
`&s` - sum each row's values
`w` - switch to bring the reminder array out and do this again on that
`]` - end loop
`=` - check for equality (returns 1s in places where the arrays are equal)
`s` - sum those to get the count (implicit output)
[Answer]
# [Kotlin](https://kotlinlang.org), 152 119 bytes
```
{a:Int,b:Int->(a..b).map{String.format("%06d",it)}.filter{it[0].toInt()+it[1].toInt()+it[2].toInt()==it[3].toInt()+it[4].toInt()+it[5].toInt()}.count()}
```
[Try it online!](https://tio.run/##ZY1dC4IwFIav9VcMIdjIxlwfkKTQZdddRhezmox0yjoGIf72tSwk8Vycs@d5z2H3CgqlrWw0KoXSWJj8EaO9MeK1O4JROk8Jan3vKQokUWJbER80hNmnL1IsKM0ILUXdfpeprEwpAAcztrkGoQLSUakKuJlWwYmdKVTuEJO5o2hEfKAkcbgchasRrQfq6KVq@of1avc/FBpLHDHGQhS5QYj/53nv@dTzX8KnmdPbvpzufPsG "Kotlin – Try It Online")
Taking two integers than convert it into six symbol strings and count.
Optimized it thanks to mazzy and his [solution](https://codegolf.stackexchange.com/a/169047/81779) to 119 bytes.
```
{a:Int,b:Int->(a..b).count{val d="%06d".format(it);(d[0]-'0')+(d[1]-'0')+(d[2]-'0')==(d[3]-'0')+(d[4]-'0')+(d[5]-'0')}}
```
[Try it online!](https://tio.run/##ZY5dC4IwFIav9VcMIdxIx1wfkDWhy667jC5mMhnpjDWDEH/7mhoYdC7OeXjec/HeG1NJZUWrQM2lglyXzxQctebvw9loqcoMgc73XrwCAjDb8fSkTJQPO84gxzhH@Na0ynTDS8GCBdkWARaNrrmB0qA9LC7kGockREuHyYx0QsYcr2a9nnEzYd9b7@G6mEpBARNCSAQSdxDyfzwdPf339JvQ/8zp3ThO9779AA "Kotlin – Try It Online")
[Answer]
# [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 44 bytes
```
sb[d]sD[dA00~[rA~rA~++rx]dx=D1+dlb!<L]dsLxkz
```
Takes two arguments from an otherwise empty stack, outputs to top of stack.
[Try it online!](https://tio.run/##S0n@b2hkbGJqpmBmamJsZPi/OCk6JbbYJTrF0cCgLrrIsQ6ItLWLKmJTKmxdDLVTcpIUbXxiU4p9KrKr/hf8BwA "dc – Try It Online")
The clever bit here is the use of an unnamed (i.e., unstored) macro that's duplicated before execution in order to run a copy of itself on the other three-digit part.
# Explanation
The inner macro `[rA~rA~++rx]` has the effect "calculate the digit sum of the three digit number that is second-to-top on the stack, then execute the original top of the stack as a macro".
Main program: 
```
sb             Saves the upper bound as b so we'll know when to quit
[d]sD          Defines the macro D, which contextually is "increment stack depth"
[              Start the main loop - the next number to test is on top 
  d              Make a copy to increment later for loop purposes
  A00            The literal "1000"
  ~              Quotient and remainder, so "123456" is now "123 456"
  [rA~rA~++rx]d  Stack is now "123 456 M M", where M is the anonymous macro
  x              Run M on the stack "123 456 M", which (see definition 
                 above) ends up running M on the stack "123 15", which
                 leaves "15 6" (and executes the 6, which is a no-op)
  =D             If the two sums were equal, increment the stack depth
  1+             Increment the current test number
  dlb!<L         Loop unless the test number is now larger than b
]dsLx          Name and start the loop
kz             Current depth is 1+answer, so throw away top and return
```
[Answer]
# [Pascal (FPC)](https://www.freepascal.org/), ~~163~~ 153 bytes
```
var a,b:Int32;begin read(a,b);for a:=a to b do if a div$186A0+a div$2710mod$A+a div$3E8mod$A=a div$64mod$A+a div$Amod$A+a mod$Athen b:=b+1;write(b-a)end.
```
[Try it online!](https://tio.run/##TYlBDoIwFESv8hcsIIhpwSC2YdGFC4/xS1ttgi2pDR6/kqKJs5l58xZ8TTg3ZplSWjEAHiS7udi1XOq7dRA0qnI7K278ZtmIED1IUB6sAQRl14IOvSD1vtszJU@vCvHl7jpkHHfsT/9S/CB3fGgHko2ypvwdbNSlbLDSTh1TInDJ@QA "Pascal (FPC) – Try It Online")
## Explanation
Here is some normal-looking code first:
```
var a,b,i,s,c,d:Int32;
begin
  read(a,b);
  s:=0;
  for i:=a to b do begin
    c:=i div 1000;
    d:=i mod 1000;
    if c div 100+(c div 10) mod 10+c mod 10=d div 100+(d div 10) mod 10+d mod 10 then begin s:=s+1; {writeln(i)} end;
  end;
  write('There are ',s,' numbers');
end.
```
[Try it online!](https://tio.run/##XY9NDoIwEIX3nOLtgFANf7qAcAD3XqB0ijSRYlrUhfHsWLRE42Jm3sx8ycy7cCv4edNdxDzfuAFnLVPMMsGoOuipyOuglSelA8BITpHbx7VrbNWkS@1GA1U1HNOIFuSSpwFRNQqkbsjS9M0CtIyGkX5GqoNYqSRaZeypRHjR0Beif4i8wNRL/flgedAmWY3H3ahJnnWk4iekpuWqL@9NFB57aSS4i9AZD6GvQyuNDZ1PB27nOcuLcrfHflcWefYC "Pascal (FPC) – Try It Online")
Then I abused the behaviour of the for loop:
* the loop values are set beforehand (from `a` to `b`), so `a` can be reused as the loop variable, dropping `i`;
* at the end of the for loop, loop variable is left at the final value (value of `b` before the loop). I used `b` as a container, incrementing it when a lucky number is found and at the end of the loop `b` is away from its old value by amount of lucky numbers, so `b-a` gives the correct result. This dropped `s`.
Replacing `d` with operations directly on `a` shortens the loop. Replacing `c` with operations directly on `a` dose not shorten the loop, but, after dropping `d`, loop's `begin` and `end` are unnecessary and I ended with using only 2 variables :)
`$` starts hexadecimal constants in the golfed code. While they do not save bytes, they eliminate spaces needed before decimal constants.
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), 162 bytes
... borrows from the Kotlin example above.
```
import java.util.stream.IntStream;
(a,b)->IntStream.range(a,b+1).mapToObj(i->String.format("%06d",i).getBytes()).filter(c->c[0]+c[1]+c[2]==c[3]+c[4]+c[5]).count();
```
[Try it online!](https://tio.run/##lVHBasMwDL33K0RhYNPEJGkbGKU97DZYt0N3Czk4rps5dewQOx1h9NszO@1Gd1uFLcl6EnqSK3qioW64qvbHQdSNbi1ULkY6KyQxtuW0Js/K7kZvNZkwSY2BLRXqawIglOXtgTIOLx079q9dXfDWeARAalXCh/7cUtUjlwg08PlQ4JXDz@66Yyy1gv2pBnn7WMOAaFDgcPPLgrRUldxHZzEmNW3e9VtRIRFuHC5USQ66ralF04co3U8DgUnJ7VNvuUEYk4OQjjNi4YZlUT5jWexVkq/XLJt7d@HVMseE6U5ZhFeDGxug6QrpmF4Jn7TYQ@22gC49sxwovsy9643lNdGdJY2DrFTodiLysxKfC1EwmhiPS/l/cRx5CZLR3F2czBfLNEiXi3lyd@cr7cdR8PUvz8M3 "Java (OpenJDK 8) – Try It Online")
Comparing the sum of the String's bytes is just as good as summing up the actual digits.
[Answer]
# [PHP](http://www.php.net/), 131 bytes
```
<?$f='array_sum(str_split(str_split(sprintf("%06d",$i),3)[';for($i=$argv[1]-1;$i++<$argv[2];)eval("\$a+=$f 0]))==$f 1]));");echo$a;
```
To run it:
```
php -n <filename> <from> <to>
```
Example:
```
php -n lucky_tickets.php 100 100000
```
Or [Try it online!](https://tio.run/##TcfRCsIgGIbhWwn5Y4obaEEnTrqQNYbUbMKm8muDbj7b6KQPXni@OMVS2itYXRlE8x7Sa6Ep45Di7PK/IjqfLSVHcXmQGhyrz6yrlA1IwWkw@Fw72TdSgeO8/f1Tr9i4mpmSGxiuwR5Ez5jeITcowtR4nwIYVUqRQuxt@4SYXfCpNP4L "PHP – Try It Online")
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~51~~ 49 bytes
```
{+grep {[==] .flip.comb[^3,3..*]>>.sum},$^a..$^b}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYKvwv1o7vSi1QKE62tY2VkEvLSezQC85PzcpOs5Yx1hPTyvWzk6vuDS3VkclLlFPTyUuqfZ/cWKlQpqGgY6hpjUXhG1oAAQ6CkYgStP6PwA "Perl 6 – Try It Online")
Anonymous code block that takes a two numbers and returns the number of lucky ones. Times out for larger inputs
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~9~~ 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
-1 thanks to Dennis (`rµ...E)S` -> `r...E€S` since everything vectorises.)
```
rdȷD§E€S
```
A dyadic Link accepting the two endpoints of the range (either way around) which yields the count of lucky tickets.
**[Try it online!](https://tio.run/##y0rNyan8/78o5cR2l0PLXR81rQn@//@/oQEI/DcCUwA "Jelly – Try It Online")** Or see a [test-suite](https://tio.run/##y0rNyan8/78o5cR2l0PLXR81rQn@f3i5PpD@/z/aQMcwVifa0AAEdIzAFIhvZGxiaqZjZmpibASSN9CxBINYAA "Jelly – Try It Online")
### How?
Note that for any non-negative integer less than \$1000000\$, \$N\$, we can get two numbers with digits that sum to the required values to check using integer division by \$1000\$  
(yielding, say, \$X=\lfloor\frac{N}{1000}\rfloor\$)  
and its remainder  
(say \$Y=N\mod{1000}\$)  
...that is, \$N=1000\times X+Y\$
Now we want to compare the sums of the digits of \$X\$ and \$Y\$ for each \$N\$ in a range and count those that are equal.
```
rdȷD§E€S - Link: integer a; integer b
r        - inclusive range [a,b] (either [a,a+1,a+2,...,b] or [a,a-1,a-2,...,b])
         -                              e.g.: 0       or 78        or 7241
  ȷ      - literal 1000
 d       - divmod (vectorises)                [0,0]      [0,78]       [7,241]
   D     - to decimal lists (vectorises)      [[0],[0]]  [[0],[7,8]]  [[7],[2,4,1]]
    §    - sum each (vectorises)              [0,0]      [0,15]       [7,7]
     E€  - for €ach: all equal?               1          0            1
       S - sum (counts the 1s in the resulting list)
```
[Answer]
# Powershell, 85 bytes
```
($args[0]..$args[1]|%{'{0:D6}'-f$_}|?{+$_[0]+$_[1]+$_[2]-eq+$_[3]+$_[4]+$_[5]}).count
```
Test script:
```
$f = {
($args[0]..$args[1]|%{'{0:D6}'-f$_}|?{+$_[0]+$_[1]+$_[2]-eq+$_[3]+$_[4]+$_[5]}).count
}
@(
    ,((0,1), 1)
    ,((1000,2000), 3)
    ,((2000,3000), 6)
    ,((10000, 20000), 282)
    ,((101000, 102000), 6)
    ,((201000, 202000), 10)
    ,((901000, 902000), 63)
    ,((100000, 200000), 5280)
    ,((123456, 654321), 31607)
    #,((0, 999999), 55252)
) | % {
    $c, $e = $_
    "      $c"
    $r = &$f $c[0] $c[1]
    "$($e-eq$r): actual=$r expected=$e"
}
```
Output:
```
      0 1
True: actual=1 expected=1
      1000 2000
True: actual=3 expected=3
      2000 3000
True: actual=6 expected=6
      10000 20000
True: actual=282 expected=282
      101000 102000
True: actual=6 expected=6
      201000 202000
True: actual=10 expected=10
      901000 902000
True: actual=63 expected=63
      100000 200000
True: actual=5280 expected=5280
      123456 654321
True: actual=31607 expected=31607
```
[Answer]
# Kotlin, 95 bytes
```
{a:Int,b:Int->(a..b).count{val d="%06d".format(it);d.chars().sum()==2*d.take(3).chars().sum()}}
```
`.kt` for test:
```
var  f = {a:Int,b:Int->(a..b).count{val d="%06d".format(it);d.chars().sum()==2*d.take(3).chars().sum()}}
fun main(args: Array<String>) {
    println(f(0,1))             // 1
    println(f(1000,2000))       // 3
    println(f(2000,3000))       // 6
    println(f(101000, 102000))  // 6
    println(f(201000, 202000))  // 10
    println(f(901000, 902000))  // 63
    println(f(10000, 20000))    // 282
    println(f(100000, 200000))  // 5280
    println(f(123456, 654321))  // 31607
    println(f(0, 999999))       // 55252
}
```
# Explanation
Count numbers from range where sum of all number digits is equal to double sum of first 3 digits.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 14 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
ît║l`Yµß╖vYü╢^
```
[Run and debug it](https://staxlang.xyz/#p=8c74ba6c6059e6e1b7765981b65e&i=0,+1%0A100000,+200000%0A123456,+654321%0A0,+999999&a=1&m=2), but be patient!
[Answer]
# [Python 2](https://docs.python.org/2/), ~~83~~ 80 bytes
-3 by using Asone Tuhid's observation - [go give credit!](https://codegolf.stackexchange.com/a/168983/53748)
```
lambda a,b:sum(sum(map(int,`v/1000`))*2==sum(map(int,`v`))for v in range(a,b+1))
```
**[Try it online!](https://tio.run/##VU1dC8IwDHz3V@TNRIN23Qc46D/xYR1aHdhuzDmQsd8@0755kBy5C3fDd3r2QW/OXLeX9e3NguW2fn88xvF2wC5M3MznTCnVEB20Mf@OiK4fYYYuwGjD446ScMyItihbhjY6iIohIwaMQUoOnTgpOi/KiqEqi1ynH7EvCUT1DgTDKGWwd7isDMtKYGTvT9Lg7YSxhMEllt4f "Python 2 – Try It Online")**
Much like my Jelly answer (but the inputs must be sorted here i.e. `a<=b`)
---
**75 bytes** for input `a, b+1` (i.e. range excludes the right bound):
```
lambda*r:sum(sum(map(int,`v/1000`))*2==sum(map(int,`v`))for v in range(*r))
```
[Try this one](https://tio.run/##VY3dCsIwDIXvfYrcmYygXfdzMeibeLEOrQ5sN@ocyNizz2ZeGUgOOTnkGz/TYwh6c@ayPa3vrjaLzevtUdrbEfswcTufc6VUS5RpY/4vyXRDhBn6ANGG@w2zSLSJZxk6sREVgyYGlC9KFpF8d3RRVjVDXZWF3jPp/IspouYAqcaYUHB0uKwMy0pg0jyeEsLbCYXC4HZN4C8 "Python 2 – Try It Online")
[Answer]
## Clojure, 102 bytes
```
#(count(for[i(range %(inc %2)):when(=(let[d(map int(format"%06d"i))](apply +(map -(drop 3 d)d)))0)]i))
```
Mixing strings and math isn't too fun.
[Answer]
# [J](http://jsoftware.com/), 35 bytes
```
[:+/(6#10)([:=/_3+/\])@#:[+i.@>:@-~
```
[Try it online!](https://tio.run/##y/qvpKeeZmulrlNrZaBgZfA/2kpbX8NM2dBAUyPaylY/3lhbPyZW00HZKlo7U8/BzspBt@6/Jldqcka@gqEBCCikKRiBGVypFZkl6ur/AQ "J – Try It Online")
[Answer]
# C (gcc), ~~90~~ 88 bytes
```
l=10;u(c,k,y){for(y=0;c<=k;)c++%l+c/l%l+c/100%l-c/1000%l-c/10000%l-c/100000%l?:++y;c=y;}
```
Port of my Java [answer](https://codegolf.stackexchange.com/a/169632/79343). Try it online [here](https://tio.run/##fVB/S4RAEP37/BTTgbDiHq3raT@2LYIKoqAv0D@yriG3qXhayeFnt3HRziBalp03M@89Zkdt3pQaBiMDJlqi6I523iEra9JJJtSV3AlP@b5rfHVq7Bsw5pqNjUewQAhvLn2/E0p2oh8@yjyFRu8bkhcNmPJT1xRG2FbVDPVXpVWjUw8OzmosJKppEwMSWjIpLNsT2M7ITAcpJ6YVrqoatRlZEzel4KKbvMYA5OXJey3WFJZWdFaiZQ/a7PV/FifSGj3cPj7f3/1lNo/0y9bpHWf8zXuSF8SOaPfAKAR4R4rNxwTXRoEdS3aRFPgUI36@aPJwG8UU4mgbchSHQczOfrrIvrAHVRGPODZ6Z/gG). Thanks to [ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat) for golfing two bytes.
Ungolfed:
```
l=10; // constant, we will be using the number 10 rather a lot
u(c, k, // function returning an integer and taking two integer arguments: lower and upper bound
  y) { // abusing the argument list to declare a variable of type integer: the number of lucky tickets found in the range
    for(y = 0; c <= k; ) // set count to 0 and loop through the range
        c++ %l + c/l %l + c/100 %l // if the digit sum of the second half of the ticket number ...
        - c/1000 %l - c/10000 %l - c/100000 %l // ... is the same as the digit sum of the first half ...
        ?: ++y; // ... it's a lucky ticket: increment the count
    c = y; // return the count
}
```
[Answer]
# Java 8, ~~101~~ 99 bytes
```
u->l->{int n=0,d=10;for(;l<=u;)if(l++%d+l/d%d+l/100%d==l/1000%d+l/10000%d+l/100000%d)++n;return n;}
```
A different approach than [the other Java answer](https://codegolf.stackexchange.com/a/169005/79343). Instead of using streams and Strings, this uses a loop and evaluates the numbers directly. Try it online [here](https://tio.run/##tVJRS8MwEH6uv@IsDFra1a5bp9KlIOhgqPiwR/EhttnIlqWlTaZj9LfPJOtE3R4EsZTed1/uvrvrZYHXuFuUhC/y5a6Ur4xmkDFc1/CIKYftmdWStcBCmXVBc1ipI2cqKsrnzy@Aq3nt6khrocQCKSgLZpJnghY8GLdgNOGCzEnlw6@CWpCmwGS23ACCneymrJtuKRfAUejnqBcms6JyEjZCMnHpzGGe18k9dpGbby8MOzlCBoQH5itS0PU8nlREyIoDT5qdZSVqDEFq4Zi6PoQ@9NTr/uQ1qSRUwPGREfcham0cXZ0IivqDeOjDMB70IyXW7w3DS/dE9WvzKJU4iiMd0KiVVHSNBfm2E5P2bwvwQf93VrzpMw1lWR4geS9JJki@vwOawZmQmKmlmdwAlyXbOCbDbR2jZMZVezsIAEJt6l7Kmm5qQVZBIUWgRuaCccd2bPD2jShr@6BdI61dF1BqmLYDRYHzdO/aplQDhNXkr9Kf3Wrxc3RUbnwzebi7PZTU@2p2Hw).
Thanks to [ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat) for golfing two bytes.
Ungolfed:
```
u -> l -> { // lambda taking two integer arguments in currying syntax and returning an integer
    int n = 0, // the counter
        d = 10; // auxiliary constant, we will be using the number 10 rather a lot
    for(; l <=u ; ) // loop over all ticket numbers in the range
        if(l++ %d + l/d %d + l/100 %d // if the digit sum of the second half of the number ...
           == l/1000 %d + l/10000 %d + l/100000 %d) // ... is the same as the digit sum of the first half ...
            ++n; // ... it's a lucky ticket, add 1 to the counter
    return n; // return the count
}
```
[Answer]
# VBA (Excel), 159 bytes
Using Immediate Window and Cells `[A1]` `[A2]` as input.
```
c=[A1]-[A2]:d=IIf(c<0,[A1],[A2]):For x=d To d+Abs(c):e=String(6-Len(x),"0")&x:For y=1To 3:i=i+Mid(e,y,1):j=j+Mid(e,7-y,1):Next:z=IIf(i=j,z+1,z):i=0:j=0:Next:?z
```
[Answer]
## F#, 110 bytes
```
let t=string>>Seq.sumBy(int>>(-)48)
let r s e=Seq.where(fun n->t(n/1000)=t(n-(n/1000)*1000)){s..e}|>Seq.length
```
[Try it online!](https://tio.run/##XVDBTsMwDL3vK6xJSAlaS9Z1EwiaAxJXhOA47VBtbhexeSNxQRPj20tiQAOsKI7fe3620oRsufPY9xtk4Cqwd9Ra@4Qveei2twfliK1VmS4v9SBpPATAKvFva/Somo6AMsuKLsbGGF3FV/ZTnMut30Oe48dRXDdILa/7@c0dsT887JL/Qpy3tSOoffsK1QBizJUZwVhfSwEqWZmIFJJPcDEpp7MRzKblpDipo/BKQi8EOVpI0x2jB9l5XzsPmf2Sx0gbBK49QwVNYOH/kEir@8gFWv3juuXz4bGmFr/7RRjn7eNXckMwPHMgZ/hLoKXf9J8)
`t` converts the string into numbers and sums them up. `r` takes the range of numbers from `s` to `e`, and filters out the numbers that are unlucky. The first three digits are collected by `n/1000`. The second three digits are computed by `n-(n/1000)*1000`.
]