[Question]
  [
# Task
As input you have:
* a positive integer `N`
And you should output:
* The number of integers in \$[1,N]\$ (an inclusive range) which end with the digit \$2\$ in base ten.
# Test cases
```
1 -> 0
2 -> 1
5 -> 1
10 -> 1
12 -> 2
20 -> 2
30 -> 3
54 -> 6
97 -> 10
100 -> 10
```
# Rules
It is a code-golf so the lowest score in bytes wins!
  
[Answer]
# [Python 2](https://docs.python.org/2/), 17 bytes
```
lambda n:(n+8)/10
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPSiNP20JT39Dgf1p@kUKmQmaeQlFiXnqqhrGpphWXgkJBUWZeiUKmjkKaRqbmfwA "Python 2 – Try It Online") Uses Python 2's integer division. In Python 3 would be a byte longer with `lambda n:(n+8)//10`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
Ḋm⁵L
```
A monadic Link accepting a positive integer, `N`, which yields a non-negative integer.
**[Try it online!](https://tio.run/##y0rNyan8///hjq7cR41bff7//29oZAQA "Jelly – Try It Online")**
### How?
Every tenth number starting with \$2\$ ends with the digit \$2\$...
```
Ḋm⁵L - Link: integer, N                           e.g. 15
Ḋ    - dequeue (implicit range [1..N]) -> [2..N]       [2,3,4,5,6,7,8,9,10,11,12,13,14,15]
  ⁵  - literal ten                                     10
 m   - modulo slice                                    [2,12]
   L - length                                          2
```
---
[Alternative 4 byter](https://tio.run/##y0rNyan8/1/bwupR49b///8bGhkBAA "Jelly – Try It Online"):
```
+8:⁵
```
Add eight, integer divide by ten (as first used in [RGS's Python answer](https://codegolf.stackexchange.com/a/200364/53748) I believe).
[Answer]
# [Perl 5](https://www.perl.org/) `-pl`, ~~13~~ 10 bytes
*@Grimmy got it back down to 10 bytes, with correct output.*
```
$_+=1<chop
```
[Try it online!](https://tio.run/##K0gtyjH9/18lXtvW0CY5I7/g/38To3/5BSWZ@XnF/3ULAA "Perl 5 – Try It Online")
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 8 7 bytes
-1 byte thanks to [Bubbler](https://codegolf.stackexchange.com/users/78410/bubbler)
Full program
```
⌊.1×8+⎕
```
[Try it online!](https://tio.run/##Hc5BCsIwFEXRebYiFt9L1bqcQsFJwUy7AkXEmbggd5KNxH8zeJNwzydzWffLNq@3a6uPe2n19Rz0@067@v7w0ko6pJIUcyzHxtgxdoqdY1PsQtNDSpGKVsSiFrnoBRDCCPfbCCOMMMIII4wwIiMyIvfvIPL4Bw "APL (Dyalog Unicode) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~7~~ ~~6~~ 5 bytes
```
R%⁵ċ2
```
[Try it online!](https://tio.run/##y0rNyan8/z9I9VHj1iPdRv///zcyAgA "Jelly – Try It Online") Thanks to Nick Kennedy for saving me one byte.
How it works:
```
R      Range from 1 to n,
 %⁵    modulo 10.
   ċ2  Then count how many of those are 2.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 4 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
8+T÷
```
Same approach as everyone else.
[Try it online](https://tio.run/##yy9OTMpM/f/fQjvk8Pb//41MAQ) or [verify all test cases](https://tio.run/##yy9OTMpM/X@xydXPXknhUdskBSV7v/8W2iGHt//X@Q8A).
Some (slightly) more interesting 5-[bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) alternatives:
```
LT%2¢
L€θ2¢
L2Å¿O
FNθΘO
```
[Try each online.](https://tio.run/##yy9OTMpM/X@xydXPXknhUdskBSX7/35KPiGqRocWWQE5EJa9kjWQzQWUeNS05twOmByMg5A2Otx6aL8/WBLChEu5@Z3bcW4GWArK/F@r8x8A)
**Explanation:**
```
8+     # Add 8 to the (implicit) input-integer
  T÷   # Integer-divide it by 10
       # (after which the result is output implicitly)
L      # Push a list in the range [1, (implicit) input-integer]
 T%    # Take modulo-10 on each
       # or
 €θ    # Leave the last digit of each
   2¢  # Count the amount of 2s
       # (after which the result is output implicitly)
L      # Push a list in the range [1, (implicit) input-integer]
 2Å¿   # Check for each whether it ends with a 2 (I'm actually surprised it vectorizes..)
    O  # Sum to get the amount of truthy values
F      # Loop `N` in the range [0, (implicit) input-integer):
 N     #  Push `N`
  θ    #  Pop and leave only its last digit
   Θ   #  05AB1E trutify: check if it's exactly 1
    O  #  Sum all values on the stack together
       # (after the loop, the result is output implicitly)
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), ~~15~~ 13 bytes
```
.+
$*
.{2,10}
```
[Try it online!](https://tio.run/##K0otycxL/P9fT5tLRYtLr9pIx9Cg9v9/EyMA "Retina 0.8.2 – Try It Online") Edit: Saved 2 bytes thanks to @Grimmy. Explanation:
```
.+
$*
```
Convert to unary.
```
.{2,10}
```
Count the number of multiples of 10, each of which contains an integer that ends in 2 in base 10, plus count an additional match for a final 2-9, as that's enough for one last integer that ends in 2 in base 10.
[Answer]
# [Desmos](https://www.desmos.com/calculator)
I know I'm 7 months late but this is my first code golf answer. I'm looking for some easier coding challenges to take down. I have two answers(one where I tried it without looking at any answers, then one after I looked through some answers.).
## First Answer, 62 bytes:
`f(N)=\sum_{n=1}^N\left\{\operatorname{mod}(n,10)=2:1,0\right\}`
[![](https://i.stack.imgur.com/hTMrX.png)](https://i.stack.imgur.com/hTMrX.png)
[Try it on Desmos!](https://www.desmos.com/calculator/zikegfft1e)
Explanation:
```
f(N)=                                               a function taking in an argument of N
     \sum_{n=1}^N                                   summation from 1 to N
                 \left\{                            starting piecewise
                        \operatorname{mod}(n,10)=2: if the remainder of n/10 is 2...
1                                                   sum 1
 ,                                                  otherwise...
  0                                                 sum 0
   \right\}                                         end piecewise
```
Not too sure why I can't take out the `\left` and `\right` for the brackets(`{` and `}`). Theoretically it should work(I've taken out the `\left`'s and `\right`'s of all the other "left-right pairs"), but I guess Desmos doesn't allow it.
## Second Answer, 20 18 bytes:
Saved two bytes thanks to [@golf69](https://codegolf.stackexchange.com/users/94333/golf69)
`f(N)=floor(.1N+.8)`
[![](https://i.stack.imgur.com/dhb3d.png)](https://i.stack.imgur.com/dhb3d.png)
[Try it on Desmos!](https://www.desmos.com/calculator/vozzazyef6)
Explanation:
My answer is equivalent to `f(N)=floor((N+8)/10)`, which is explained in [RGS's comment](https://codegolf.stackexchange.com/questions/200363/find-the-number-of-integers-in-the-range-from-1-to-n-that-ends-with-2?page=1&tab=oldest#comment476894_200364) under his answer.
[Answer]
## Python 3, 55 40 bytes
Any help with golfing it would be appreciated
```
lambda N:sum(x%10==2for x in range(N+1))
```
Lots of thanks to the commentors for helping me out( I have problems with memory, see names below)
[Answer]
# Haskell, 14 Bytes
```
f x=div(x+8)10
```
[Answer]
# [W](https://github.com/A-ee/w), 4 [bytes](https://github.com/A-ee/w/wiki/Code-Page)
```
8+T/
```
Just another boring formula: Add eight, divide by 10. (W performs integer division if both operands are integers.)
# [W](https://github.com/A-ee/w) `d`, 5 [bytes](https://github.com/A-ee/w/wiki/Code-Page)
```
[ⁿNy|
```
Uncompressed:
```
Tm2=Wk
```
## Explanation
```
    W % For every number in the range [1 .. N]:
      % Keep all that satisfies:
Tm    % After modulo by 10,
  2=  % The result is equal to 2
     k% Find the length of that
```
[Answer]
# Powershell, ~~50~~ 20 bytes
```
1.."$args"-match"2$"
```
$args are arguments to pass as number.
[Answer]
# [Julia 1.0](http://julialang.org/), 12 bytes
```
x->(x+8)÷10
```
[Try it online!](https://tio.run/##yyrNyUw0rPifZvu/QtdOo0LbQvPwdkOD/wVFmXklOXkaaRqGmppcCJ4RCs8UhWdogMoFqv0PAA "Julia 1.0 – Try It Online")
[Answer]
# [Kotlin](https://kotlinlang.org), 25 bytes
```
{(1..it).count{it%10==2}}
```
[Try it online!](https://tio.run/##DYyxCsMwDAX3fMVbCtJQ42QMuJ0L/QmTxCCayiUoWYy/3fUtd9N9su2i7Yo70gx6qTHuD3QjtEKjc2LslnyqFbHb6EOYam3pVHyjKDHKgM7vEDVKdGxxfYtuxE9nuW96zJ55qGiT/wM "Kotlin – Try It Online")
[Answer]
# [Pyt](https://github.com/mudkip201/pyt) [sic!], 3 bytes
Finally found the right language. I had a now-deleted answer in Vim, but it returned the empty string for an input of 1 :(
```
8+₀
```
Explanation:
```
8    In fact, I have no idea whether is this language stack-based, I guess it pushes 8
 +   add that 8 to the seemingly-implicit input
  ₀  divide by 10. There are also instructions to divide by numbers from 2 to 11 :)
```
[Try it online!](https://tio.run/##K6gs@f/fQvtRU8P//0YA "Pyt – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 7 bytes
```
#ȯ=2→dḣ
```
[Try it online!](https://tio.run/##yygtzv7/X/nEelujR22TUh7uWPz//39DAwMA "Husk – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-x`](https://codegolf.meta.stackexchange.com/a/14339/), 6 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
The straightforward solution of adding 8 and floor dividing by 10 would be a byte shorter: `+8 zA`. But where's the fun in that?!
```
õ_ìÌ¶2
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LXg&code=9V/szLYy&input=MTAw)
```
õ_ìÌ¶2     :Implicit input of integer U
õ          :Range [1,U]
 _         :Map
  ì        :  To digit array
   Ì       :  Last element
    ¶2     :  Is equal to 2?
           :Implicit output of sum of resulting array
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~10~~ 7 bytes
```
ṾṪ=”2)S
```
[Try it online!](https://tio.run/##y0rNyan8///hzn0Pd66yfdQw10gz@P///8YGAA "Jelly – Try It Online")
But there's already 2 shorter answers I hear you say... Well, this doesn't use mathematics but rather uses strings
[Answer]
# [Scala](http://www.scala-lang.org/), 11 bytes
```
n=>(n+8)/10
```
[Try it online!](https://tio.run/##K05OzEn8n5@UlZpcouCbmJmnkFpRkpqXUqzgWFBQzVWWmKOQZqXgmVeiYGsHof7n2dpp5GlbaOobGvw31CvJ1zA0MNDUS8svSk1MztDIBCksKMrMK8nJA3K0FZRAAkpARppGpqamJlftfwA "Scala – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~5~~ 4 bytes
*Edit: -1 byte thanks to Jo King*
```
hs+8
```
[Try it online!](https://tio.run/##yygtzv7/P6NY2@L///@GBgYA "Husk – Try It Online") or [check all test cases](https://tio.run/##yygtzv6f@6ip8X9GsbbF////ow11jHRMdQwNdAyNdIwMdIwNdExNdCzNgSIGsQA)
**How?**
```
            # implicit input
    +8      # plus 8            
   s        # convert to string
  h         # remove last character
            # (so hs effectively divides by 10)
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 17 bytes
```
f(n){n=(n+8)/10;}
```
[Try it online!](https://tio.run/##DchBCoAgEADAu69YAmEXlYwIAquXdAnF2ENbRDfp7dYcJ7o9xlozChWZUcxIbefDW4@NBamofN7I8gDPPvDUD8EYJgVw3f9mbHQCt4BOqzSWLWRkoqDe@gE "C (gcc) – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 17 bytes
```
f(n){n+=8;n/=10;}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI0@zOk/b1sI6T9/W0MC69n9mXolCbmJmnkZZfmaKJlc1lwIQFBQBhdM0lFRTYvKUdBTSNAw1Na2xyxjhlDHFKWNogFsKt3lGuHUZ45YyNcEpZWmOx4VgE2v/AwA "C (gcc) – Try It Online")
Alternative 17-byter:
# [C (gcc)](https://gcc.gnu.org/), 17 bytes
```
f(n){n=n/10.+.8;}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI0@zOs82T9/QQE9bz8K69n9mXolCbmJmnkZZfmaKJlc1lwIQFBQBhdM0lFRTYvKUdBTSNAw1Na2xyxjhlDHFKWNogFsKt3lGuHUZ45YyNcEpZWmOx4VgE2v/AwA "C (gcc) – Try It Online")
Alternative 17-byter
# [C (gcc)](https://gcc.gnu.org/), 17 bytes
```
f(n){n=(n+8)/10;}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NI0@zOs9WI0/bQlPf0MC69n9mXolCbmJmnkZZfmaKJlc1lwIQFBQBhdM0lFRTYvKUdBTSNAw1Na2xyxjhlDHFKWNogFsKt3lGuHUZ45YyNcEpZWmOx4VgE2v/AwA "C (gcc) – Try It Online")
[Answer]
# [Clojure](https://clojure.org/), 28 bytes
```
(defn e[n](int(/(+ n 8)10)))
```
Ungolfed:
```
(defn ends-in-two [n]
  (int (/ (+ n 8) 10)))
```
Test harness:
```
(println (e 1))
(println (e 2))
(println (e 5))
(println (e 10))
(println (e 12))
(println (e 20))
(println (e 30))
(println (e 54))
(println (e 97))
(println (e 100))
```
[Try it online!](https://tio.run/##S87JzyotSv3/XyMlNS1PITU6L1YjM69EQ19DWyFPwULT0EBTU5OLy1ohJLW4RCEjsSgvtbjYikujoAioKidPQSNVwRCoAJlvhMY3ReODjEQVQNdhhK7CGF3A1ARNwNIcwxagnv//AQ "Clojure – Try It Online")
[Answer]
# [GolfScript](http://www.golfscript.com/golfscript/), 6 bytes
GolfScript has no decimal support, that's why the `/` works.
```
~8+10/
```
[Try it online!](https://tio.run/##S8/PSStOLsosKPn/v85C29BA//9/SwMA "GolfScript – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 5 bytes
```
/+8QT
```
[Try it online!](https://tio.run/##K6gsyfj/X1/bIjDk/39DIwA "Pyth – Try It Online")
### Explanation
```
/+8QT
   Q   : Variable containing evaluated input
 +8    : Add 8 to it
/   T  : Divide result of add by 10
```
[Answer]
## [Javascript (node)](https://nodejs.org/en/) - 25 Bytes
```
f=n=>n?(n%10==2)+f(n-1):0
```
[Try it online!](https://tio.run/##dc7LCoMwEIXhvU@RjZAgyky8FIVpn0WsKYpMpIqvH8FAFzVZf3DOP/dHvw3fad1ztu/ROUNMT35JThGItMqM5BxVB26wvNllLBb7kcJIVIJIgFDJH@gL8A51DBCi4sd04AViUnopAwHVJc1d2ocvgFAc/Myd)
[Answer]
# [JavaScript (V8)](https://v8.dev/), 15 bytes
```
f=n=>(n+8)/10|0
```
[Try it online!](https://tio.run/##FctLCsMgEADQq8xS6SQdbUIswex6itKFFc2HoEGDq97dttsHbzPFZJvW42yKqsUkCO@UQcNToMQeBaGQKAlvhH2H9@En9Bqr10FPLFwUvwr6UP2v1sf0MHZhDvQENoYcd9fucWaeOc75WL8 "JavaScript (V8) – Try It Online")
[Answer]
# [PHP](https://php.net/), ~~18~~ 17 bytes
```
<?=$argn/10+.8|0;
```
[Try it online!](https://tio.run/##K8go@P/fxt5WJbEoPU/f0EBbz6LGwPr/f0OTf/kFJZn5ecX/dd0A "PHP – Try It Online")
-1 bytes thanks to @oxgeba
[Answer]
# Python 3, ~~22~~ 18 bytes
```
lambda n:(n+8)//10
```
Thanks to @JoKing for suggesting to use integer division.
[Answer]
# [R](https://www.r-project.org/), ~~18~~ 15 bytes
Thanks @Giuseppe! Guess I didn't really know what the %/% operator did.
```
(scan()+8)%/%10
```
[Try it online!](https://tio.run/##K/r/X6M4OTFPQ1PbQlNVX9XQ4L8hlxGXKZehAZehEZeRAZexAZepCZelOVDE4D8A "R – Try It Online")
]