[Question]
  [
I have a number like this:
```
n = 548915381
```
The output should be the sum of every second digit of that number. In this case 26:
```
4+9+5+8 = 26
```
Rules:
* This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins.
* The input consists only of numbers bigger than 10 (at least 2 digits) but smaller than a 32-bit integer.
* The input will be a number, not a string
Test cases:
| Input | Output |
| --- | --- |
| 10 | 0 |
| 101011 | 1 |
| 548915381 | 26 |
| 999999 | 27 |
| 2147483647 | 29 |
| 999999999 | 36 |
 
  
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 2 bytes
```
y∑
```
well.
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJ54oiRIiwiIiwiNTQ4OTE1MzgxIl0=) | [1 byte with `s`](https://vyxal.pythonanywhere.com/#WyJzIiwiIiwieSIsIiIsIjU0ODkxNTM4MSJd)
**Explanation**
```
y∑
y   Uninterleave, push two lists with every second and every second+1 digit
 ∑  Sum the first list
```
[Answer]
## Python 3, 28 37 32 30 35 bytes
```
lambda n:sum(map(int,str(n)[1::2]))
```
Assuming input is a string number
[Answer]
# [Raku](https://github.com/nxadm/rakudo-pkg), 15 bytes
```
{sum m:g/.<(./}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/urg0VyHXKl1fz0ZDT7/2f3FipUKahrZetEGspoKtnYJetGGsQlp@kUJOZl5qsZ2dXnl@UUrxf0MDTk4DLkMDIDTk5DTksgQDTk4jcy4jQxNzEwtjMxNzTiNLqARIztgMAA "Raku – Try It Online")
Simple regex based sum of every other digit
[Answer]
# JavaScript (ES6), 30 bytes
*-1 by [@l4m2](https://codegolf.stackexchange.com/users/76323/l4m2)*
```
f=n=>n&&f(i=n/10|0)+i++%2*n%10
```
[Try it online!](https://tio.run/##hYzRCsIgGEbve4rdbGhS@qtTd2HvMtYMY@ho0VXvbjYagQR93@U5nGv/6Jfh5uf7IcTzmJKzwZ5C0zjkbaDAngwTT0jN96EGloYYljiNxylekEMAGFfbKK3YruDsH8/fGplDwVtpOmiFWZXMuSqEbt03wHUhcJBaGqGkztJb6H4WPpEsCJVe "JavaScript (Node.js) – Try It Online")
---
# JavaScript (ES6), 31 bytes
```
f=n=>n?f(n/10|0)+i++%2*n%10:i=0
```
[Try it online!](https://tio.run/##bczfCsIgFMfx@55iNwNNSo86/wTWs4w1wxgaLbrq3c3GIpDOufx@@F37Zz8P93B77GI6jzl7F90xnjyKFNiLYRIIafk2tsAOwbE8pDinadxP6YI8AoZx8z1KG7ape3lYTelQ9U4aC50wCymdqwrY5X4DXFeAg9TSCCV1QR9g/y6sIwUIld8 "JavaScript (Node.js) – Try It Online")
### Commented
```
f = n =>            // f is a recursive function taking the input n
  n ?               // if n is not equal to 0:
    f(n / 10 | 0) + //   do a recursive call with floor(n / 10)
                    //   it's important to understand that:
                    //     1) n is defined in the local scope of f
                    //     2) i is defined in the global scope
                    //     3) we're not going to execute the code that
                    //        follows until the recursion stops and i
                    //        has been initialized
    i++ % 2 *       //   take the parity of i (increment it afterwards)
    n % 10          //   and multiply by the least significant decimal
                    //   digit of n
  :                 // else:
    i = 0           //   stop the recursion and initialize i to 0
```
[Answer]
# [R](https://www.r-project.org), ~~40~~ ~~38~~ 36 bytes
*Edit: -2 bytes thanks to [@Giuseppe](https://codegolf.stackexchange.com/users/67312/giuseppe).*
```
\(x)sum(x%/%10^(nchar(x):0)%%10*1:0)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMGiNNulpSVpuhY3VWI0KjSLS3M1KlT1VQ0N4jTykjMSi4BiVgaaqkABLUMgA6o2PE3D0EBTmdOAC8QAQkMgxxDIMTWxsDQ0NbYA8Y3MgAKWYADimQN5RoYm5iYWxmYm5iARS7g8RImxGcT4BQsgNAA)
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-hx`](https://codegolf.meta.stackexchange.com/a/14339/), 3 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
ì ó
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LWh4&code=7CDz&input=NTQ4OTE1Mzgx)
```
ì ó     :Implicit input of integer
ì       :Convert to digit array
  ó     :Uninterleave
        :Implicit output of sum of last element
```
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 14 bytes
```
0i~i:c%@0(?n+!
```
[Try it online!](https://tio.run/##S8sszvj/3yCzLtMqWdXBQMM@T1vx/38jQxNzEwtjMxNzAA "><> – Try It Online")
**Explanation**
```
0               # init sum as 0
 i~             # discard an input
   i:           # duplicate an input
     c%@        # mod the copy by 12 and move down on stack
        0(?n    # if the other copy was negative, print the sum
            +!  # else add copy to sum and skip the next instruction
```
[Answer]
# [Zsh](https://www.zsh.org/), 33 bytes
```
for _ c (`fold -1`)let t+=c;<<<$t
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724qjhjwYKlpSVpuhY3FdPyixTiFZIVNBLS8nNSFHQNEzRzUksUSrRtk61tbGxUSiAKoeoXrDIyNDE3sTA2MzGHiAAA)
-3 bytes thanks to roblogic
Inputs as a string, because there is no way to input as a number in Zsh.
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 10 7 bytes
```
$+@SUWa
```
First pip answer, so don't sue me plz.
[Try It Online!](https://dso.surge.sh/#@WyJwaXAiLCIiLCIkK0BTVVdhIiwiIiwiNTQ4OTE1MzgxIiwiIl0=)
**Explanation**
```
$+@SUWa
  @SUWa  Uninterweave a, take the second item of the two "every second element" lists 
$+       Sum the string
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~39~~ 32 bytes
-7 (pxeger suggested lambda)
```
lambda n:sum(map(int,`n`[1::2]))
```
[TIO](https://tio.run/##K6gsycjPM/qfaBvzPycxNyklUSHPqrg0VyM3sUAjM69EJyEvIdrQysooVlPzf0ERUEQhUcPQQJMLwQZCQwTf1MTC0tDU2AJJyBIMEHwjQxNzEwtjMxNzdDUgZf8B)
EDIT: new test cases
[Answer]
# [Excel](https://www.microsoft.com/en-us/microsoft-365/excel), ~~39~~ 32 bytes
* -7 bytes thanks to [Engineer Toast](https://codegolf.stackexchange.com/users/38183/engineer-toast)!
```
=SUM(--(0&MID(A1,2*ROW(A:A),1)))
```
[![enter image description here](https://i.stack.imgur.com/CNTII.png)](https://i.stack.imgur.com/CNTII.png)
[Answer]
# [Perl](https://www.perl.org/) `-p`, 18 bytes
```
s/.(.)/$\+=$1/ge}{
```
[Try it online!](https://tio.run/##K0gtyjH9/79YX09DT1NfJUbbVsVQPz21tvr/fyNDE3MTC2MzE/N/@QUlmfl5xf91CwA "Perl 5 – Try It Online")
Input via STDIN.
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~40~~ ~~32~~ 31 bytes
-8 bytes thanks to [G B](https://codegolf.stackexchange.com/users/18535/g-b)  
-1 byte thanks to [Armand Fardeau](https://codegolf.stackexchange.com/users/94303/armand-fardeau)
```
->n{eval"#{n}".scan(/.(.)/)*?+}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsEiN9ulpSVpuhb7de3yqlPLEnOUlKvzapX0ipMT8zT09TT0NPU1tey1ayGq1hUouEWbmlhYGpoaWxjGQgQXLIDQAA)
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 9 bytes
```
tssM%2+1z
```
[Try it online!](https://tio.run/##K6gsyfj/v6S42FfVSNuw6v9/I0MTcxMLYzMTcwA "Pyth – Try It Online")
```
      +1z    # Append '1' before the input
    %2       # Every 2nd element of
 ssM         # Map to integer and take sum
t            # Decrease by 1
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
D0ÐoS
```
[Try it online!](https://tio.run/##y0rNyan8/9/F4PCE/OD/h9s1I///NzTQUTA0AEJDHQVTEwtLQ1NjCyDTEgx0FIwMTcxNLIzNTMxhYkAAAA "Jelly – Try It Online")
Also 5 bytes
```
DŻm2S
```
[Try it online!](https://tio.run/##y0rNyan8/9/l6O5co@D/h9s1I///NzTQUTA0AEJDHQVTEwtLQ1NjCyDTEgx0FIwMTcxNLIzNTMxhYkAAAA "Jelly – Try It Online")
Also also 5 bytes
```
Ds2SṪ
```
[Try it online!](https://tio.run/##y0rNyan8/9@l2Cj44c5V/w@3a0b@/29ooKNgaACEhjoKpiYWloamxhZApiUY6CgYGZqYm1gYm5mYw8SAAAA "Jelly – Try It Online")
### How they work
```
D0ÐoS - Main link. Takes an integer on the left
D     - Digits
  Ðo  - To digits in odd positions:
 0    -   Set them to 0
    S - Sum
```
```
DŻm2S - Main link. Takes an integer on the left
D     - Digits
 Ż    - Prepend a zero
  m2  - Take every second element
    S - Sum
```
```
Ds2SṪ - Main link. Takes an integer on the left
D     - Digits
 s2   - Slice into pairs
   S  - Sums
    Ṫ - Tail
```
[Answer]
# [Julia 1.0](http://julialang.org/), 30 bytes
```
!n=sum(i->i-'0',"$n"[2:2:end])
```
[Try it online!](https://tio.run/##PY1NCoMwFITX5hTPUDCCFuO/Qtx10TOULmJN4RWbilFw4d1t0NKZzcx8i3nNPUq@bJurhZnfDMMGQy/yAnrS9BbXca10d/e352cEBNQwKtn1qJVhPgErGbQgYJCjUWd21VNghh4nhv6BhxH11GsmRePKY3IlCAEtrOuf0ssyqMekOqBB6xN7ufEInIjwyJqDw0mWlhXPktKWOCfVLhsLEvO0SMskTwtbqx/ZYZJ/AQ "Julia 1.0 – Try It Online")
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, 25 bytes
```
[ >dec <odds> 48 v-n Σ ]
```
[Try it online!](https://tio.run/##TY9LTsMwEIb3PsVkT5xn8wJF6gYUCXVTsUIoCo6TVGrsYE8KCHEa7sOVQuq0pf9sRt/882oqhlJNT9ti85CB5m8jF4zr/4zyD1SVhr7Cjg6V0lwt@YEfO0@FUeyYrDkMiiN@DmonEG6h2GTQyn1D1o/FeptBXnMGYuxfuco1zqYWwIJ7cwK4NE3BtufNHDrEQWeOU0umaWPqx/FUqtZhUiAX6LxLVdtl2WJZzmNvru6jHfZ7Qr4IzPJcuMgC98Tm8M7MM2wVJqm3ChLPMD8yMDU6G/3YQN8L4zAJojA2ML1yLmYLgoh8k@l5efhO1rXOIUzgYAv4/YGXqa8GoNMf "Factor – Try It Online")
```
       ! 548915381
>dec   ! "548915381"
<odds> ! "4958"
48     ! "4958" 48
v-n    ! { 4 9 5 8 }
Σ      ! 26
```
[Answer]
# [flax](https://github.com/pygamer0/flax), 2 bytes
```
ΣẎ
```
[Try It Online!](https://dso.surge.sh/#@WyJmbGF4IiwiIiwizqPhuo4iLCLPgiciLCIiLCJbWzEwLDEwMTAxMSw1NDg5MTUzODEsOTk5OTk5LDIxNDc0ODM2NDcsOTk5OTk5OTk5XV0iXQ==)
[Answer]
# [J](https://www.jsoftware.com), 15 bytes
All credit goes to [Raul](https://codegolf.stackexchange.com/users/72244/rdm).
```
[:+/_2}.\,.&.":
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70wa8FOJT31NAVbKwV1BR0FAwUrINbVU3AO8nFbWlqSpmuxPtpKWz_eqFYvRkdPTU_JCiJ6016TKzU5I19BI826LlZTzU7B0ACIgNBQwdTEwtLQ1NjCUMESDBSMDE3MTSyMzUzMoSJAADFmwQIIDQA)
```
[:+/_2}.\,.&.":
         ,.&.":  NB. equivalent to ". ,. ": y, convert to digit list
    _2}.\        NB. behead each non-overlapping window of size 2
[:+/             NB. sum the resulting column
```
# My original 19 bytes from 11 bytes
```
1(#.]*0 1$~#),.&.":
```
Updated to reflect challenge requirements. Thanks to Jonah for the modifications.
[Attempt This Online!](https://ato.pxeger.com/run?1=m70wa8FOJT31NAVbKwV1BR0FAwUrINbVU3AO8nFbWlqSpmux2VBDWS9Wy0DBUKVOWVNHT01PyQoic9Nekys1OSNfQSPNui5WU81OwRCoygAIDRVMTSwsDU2NLQwVLMFAwcjQxNzEwtjMxBwqAgQQYxYsgNAA)
```
1(#.]*0 1$~#),.&.":
             ,.&.":  NB. same as above
1(          )        NB. dyadic hook
           #         NB. use length of right arg to
      0 1$~          NB. reshape 0 1, reuses elements to create alternating 1's
    ]*               NB. multiply by the right arg
  #.                 NB. 1 #. y sums the result 
```
[Answer]
# [Dart (2.18.4)](https://dart.dev/), ~~92~~ 77 bytes
```
f(n,[i=1])=>[for(;i<(n='$n').length;i+=2)int.parse(n[i])].reduce((v,e)=>v+e);
```
* [Try it online](https://tio.run/##bYtBDoIwFET3noKFCf8HQiwUgdR6kaaLRoo00S@pyMZ49kqMmxpnVvPypjd@DmEAypWTTKM8quHmQbgDkEy3lGJxsXSeR@EyWaKjuZiMv1sg5TTqwtv@cbIAS27X75JZFOFqHAEmz02STH59wABshyiivZbFrOZtx@qq/cHdJzErGW94W@1588/96q/wBg).
* [Full source](https://github.com/alexrintt/algorithms/tree/master/codegolf/sum-every-second-digit-in-a-number/dart-2.18).
[Answer]
# [Python 3](https://docs.python.org/3/), 35 bytes
```
lambda n:sum(map(int,f'{n}'[1::2]))
```
[Try it online!](https://tio.run/##K6gsycjPM/6faBvzPycxNyklUSHPqrg0VyM3sUAjM69EJ029Oq9WPdrQysooVlPzf0ERUFAjUcPUxMLS0NTYwhAoBgA "Python 3 – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 12 bytes
```
.(.?)
$1$*
.
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wX09Dz16TS8VQRYtL7/9/QwMuQwMgNOQyNbGwNDQ1tjDksgQDLiNDE3MTC2MzE3OoCBAAAA "Retina 0.8.2 – Try It Online") Link includes test cases. Takes input as a string because Retina has no integer types. Explanation:
```
.(.?)
$1$*
```
Convert alternate digits to unary, dropping the other digits.
```
.
```
Take the sum and convert back to decimal.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 7 bytes
```
ＩΣΦＳ﹪κ²
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEI7g0V8MtM6cktUjDM6@gtCS4BCiXrqGpo@Cbn1Kak6@RraNgpAkC1v//m5pYWBqaGlsY/tctywEA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
   Ｓ    Cast the input to string
  Φ     Filter characters where
     κ  Current index
    ﹪ ² Is odd
 Σ      Take the sum
Ｉ       Cast to string
        Implicitly print
```
[Answer]
# [pl](https://perl1liner.sourceforge.io) – Perl One-Liner Magic Wand, 12 bytes
Use **-o** to loop over command line arguments. Global matching regexp returns every other character, in this case digit. By default List::Util::sum is imported, `e(cho)` its result. On the [blog](https://perl1liner.sourceforge.io/Challenge-and-Golf/#o-e-sum..g-10-101011-548915381-999999), hover the ▶ button, or the blue code box, to see the result:
```
pl -o 'e sum/.(.)/g' 10 101011 548915381 999999 2147483647 999999999
```
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 18 bytes
```
1⊑·+˝⌊‿2⥊'0'-˜•Fmt
```
Anonymous tacit function that takes a number and returns a number. [Try it at BQN online!](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAgMeKKkcK3K8ud4oyK4oC/MuKliicwJy3LnOKAokZtdAoKRiA1NDg5MTUzODE=)
### Explanation
```
1⊑·+˝⌊‿2⥊'0'-˜•Fmt
               •Fmt  Format as string
          '0'-˜      Subtract '0' character from each, giving a list of digits as numbers
     ⌊‿2⥊           Reshape into an array with two columns, dropping the last digit if
                     there is an odd number of digits
  ·+˝                Sum down each column
1⊑                   Take the element at index 1 (0-indexed) in the resulting list
```
[Answer]
# [sclin](https://github.com/molarmanful/sclin), 13 bytes
```
2/`1.: map +/
```
[Try it here!](https://replit.com/@molarmanful/try-sclin)
For testing purposes:
```
"548915381" ; n>o
2/`1.: map +/
```
## Explanation
Prettified code:
```
2/` 1.: map +/
```
* `2/`` chunk into pairs
* `1.: map` get second element of each pair
* `+/` sum
[Answer]
# [Fig](https://github.com/Seggan/Fig), \$3\log\_{256}(96)\approx\$ 2.469 bytes
```
S]y
```
[Try it online!](https://fig.fly.dev/#WyJTXXkiLCJbNSw0LDgsOSwxLDUsMyw4LDFdIl0=)
Port of Vyxal.
```
S]y
    # Uninterleave
 ]  # Get last
S   # Sum
```
# [Fig](https://github.com/Seggan/Fig), \$6\log\_{256}(96)\approx\$ 4.939 bytes
```
S-n2'0
```
[Try it online!](https://fig.fly.dev/#WyJTLW4yJzAiLCJbNSw0LDgsOSwxLDUsMyw4LDFdIl0=)
My original answer before seeing Vyxal.
```
S-n2'0 # Input as a digit list
  n    # For every
   2   # Second item
    '  # Replace
     0 # With a 0
 -     # Subtract this from the original list
S      # Sum
```
[Answer]
# [Kotlin](https://kotlinlang.org), 51 bytes
```
{it.map{it.code-48}.foldIndexed(0){i,a,c->i%2*c+a}}
```
No TIO link as it doesn't have an updated version, ATO borks with it for some reason.
```
{it.map{it.code-48}.foldIndexed(0){i,a,c->i%2*c+a}} // String input
{                                                 } // Lambda expression
 it.map{it.code-48}                                 // Subtract 48 from each char, turning the string into a list of digits
                   .foldIndexed(0){i,a,c->       }  // Fold over the list, starting with 0. i is the index, a is accumulator, and c is the digit
                                          i%2*c     // Multiply the current digit by the index mod 2. If it is even, it resolves to 1*c, otherwise 0*c
                                               +a   // Add to accumulator
```
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 13 bytes
```
+/(2!!#:)#10\
```
[Try it online!](https://ngn.codeberg.page/k#eJxFj01ugzAQhdedUxCli0SV4x/AgH2CrnqANFKIMQQl2Ck2Fahqz14TpGRmMfPpvcV7tXjDG7ZarcV2TckngBc/r/vprxd1FEWjPNqL3Bzrsr3KUU6y3x5+g2dPiSSH+w1LJZ3/NMkLmsY5lYzPXNxHsmwGRpMsyWOeZJIVT3U2xMENgOHs/c0JjJWtdGOv9c75Ul30qM6lafRO2Q5/Ddr51hqHWZrylGA3dEh/635CTitrKlS1TetRa1CJzNCddA/wbm6Dj15Cnehj8OEHShYksORfiMKjQSDGYcm3iCyDZ4WABTwKBDXm/3A5VUY=)
* `10\` convert (implicit) input integer to a list of its digits
* `(2!!#:)#` only keep elements at odd indices (0-indexed)
* `+/` calculate (and implicitly return) the sum
[Answer]
# Julia, 28 bytes
```
f(n)=sum(digits(n)[2:2:end])
```
]