[Question]
  [
*Based on [this](https://www.youtube.com/watch?v=W20aT14t8Pw) Numberphile video*
A self-locating string is a number (or set of numbers) in a decimal expansion which corresponds to its location, from the start of the decimal.
For example, take the number:
```
.2734126393112
```
Here, we can identify certain items quickly, e.g:
```
.27 _3_ _4_ 1263 _9_ 3112
```
There are a few more complex cases in here though, too. For instance, the numbers `11` and `12` both appear *starting* in their respective positions:
```
.2734126393112
 123456789ABCD
           ^
           11
            ^
            12
```
So the list of self-locating strings in this case would be `[3, 4, 9, 11, 12]`, as even though some of them overlap, they both start in the correct places. If we sum these up, we get 39, or the *self-reference index* (SRI) of this terminating decimal.
## Input
A terminating decimal, either an array of digits (after the point) or a decimal type with `0.` at the start/`.`.
## Output
The SRI of the input number.
## Rules
* In the case that there are no self-referential numbers, the SRI is 0. This must be returned/printed, as opposed to exiting or returning undefined.
* The decimal expansion can be assumed to terminate, and will be no more than 128 digits in length.
* The counting of the indexes should be 1-based, e.g the first decimal is at position `1`, etc.
* Standard I/O rules + standard loopholes apply.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins
## Test cases
```
0.1207641728 -> 3
.12345678910 -> 55
0.1234567890112 -> 68
.0 -> 0
0.654321 -> 0
.54321 -> 3
```
  
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 16 bytes
```
+/‚ç¨‚àò‚çã(‚ç∏‚ä£‚äÉ¬®‚çï‚çõ‚ç∑¬®)‚äÇ
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qG@qc6R6cWJOifqj7pbUvMSknNRgR58QIAcoFeyqF@rs66KelF@RmZeukJ@n/l9b/1HvmkcdMx71dms86t3xqGvxo67mQyse9U591Dv7Ue/2Qys0H3U1/U971DbhUW8f0AxPf5CC9caP2iaCTAxyBpIhHp7B/9MU1A2NjE1MzcwtLA0MDY3UucAiBuZmJobmRhZgrpmpibGRoToA "APL (Dyalog Extended) ‚Äì Try It Online")
Takes a string of digits.
### How it works
```
+/‚ç¨‚àò‚çã(‚ç∏‚ä£‚äÉ¬®‚çï‚çõ‚ç∑¬®)‚äÇ  ‚çù Input: character vector of digits
  ‚ç¨‚àò‚çã             ‚çù X‚ÜêArray of 1-based indices
     (    ‚çï‚çõ ¬®)   ‚çù Stringify each of X
     (      ‚ç∑¬®)‚äÇ  ‚çù And for each of above, build a boolean array where
                  ‚çù   substring matches are marked as 1
                  ‚çù e.g. '10'‚ç∑'10428104' is [1 0 0 0 0 1 0 0]
       ‚ä£‚äÉ¬®        ‚çù Extract X-th indices from each of above
      ‚ç∏           ‚çù Convert ones to its 1-based locations
+/                ‚çù Sum
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 9 bytes
```
ƒÅ í.$y√Ö?}O
```
[Try it online!](https://tio.run/##yy9OTMpM/f//SOOpSXoqlYdb7Wv9///XMzI3NjE0MjO2NDY0NPoPAA "05AB1E ‚Äì Try It Online")
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~60~~ 56 bytes
```
param($n)1..128|%{$o+=$_*($_-eq$n.indexOf("$_",$_))};+$o
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/vyCxKDFXQyVP01BPz9DIoka1WiVf21YlXktDJV43tVAlTy8zLyW1wj9NQ0klXklHJV5Ts9ZaWyX/////6kANxiamZuYWlgaGhkbqAA "PowerShell ‚Äì Try It Online")
Takes input `$n` as a string (else you'll get floating point inaccuracies), then constructs a range from `1` to `128`. We then loop through those numbers (the `|%{...}`) and each iteration we're accumulating into `$o` the current number times if the current number `$_` is `-eq`ual to the `.indexOf` the current number `"$_"` starting at position `$_` in the input string `$n`. In other words, if the current number matches the first index starting at that position, the current number is added to our output. After the loop, we tack on a `+` at the front to account for the zero case (i.e., no numbers in the collection). That result is left on the pipeline and output is implicit.
*-4 bytes thanks to inspiration from ElPedro.*
[Answer]
# [R](https://www.r-project.org/), 1Ã∂0Ã∂2Ã∂, 99 bytes
Thanks to @Giuseppe for 99 bytes
```
U=`[`
`[`=Map
sum(which(paste0[U[list(x<-scan()),`+`[(L=seq(x))-1,seq[nchar(L)]]],collapse=""]==L))
```
[Try it online!](https://tio.run/##nVBBasMwELzrFYt62aVysRTHTqDqC9xbc3INFkLFAsdxJYUaSt/uKj310ksXhp0Z2GGZsG0nPXQDy9DPZmHxesaP0dsRFxOTK7tTN/mYcH0sojUzEonhfuiw1dG940pUSJFZN9vRBGyp73thL9Nklug0573WLdGmoIEdVCBBQZ3ZMUPeFGN38OJiAmuii@ztEgA9@BksSlU2dSUbdRAg1a7a183hKMtfopRSCchOva92Sgr4WUTwyQBW0GDiw3w9u@AtopswphCXySfM/u1dY5ML6ElwTnnykTUJvQBePHEBf1bxnwpy6OvMiX1t2zc "R ‚Äì Try It Online")
Few bytes can be saved if there is a second 2-byte 3-argument operator like `[`. First time messing with `[`, it is fun.
[Answer]
# JavaScript (ES6), ~~¬†50¬†~~ 48 bytes
Takes input as a string. A recursive approach.
```
f=(s,n=1)=>s?+s.match('^'+n)+f(s.slice(1),n+1):0
```
[Try it online!](https://tio.run/##XclBDsIgEADAu8/opbuhEhdqjSbYnzQhCNoGF@M2fh977lxn8T8v4Tt/1iOXR6w1OZCOHaG7y6hEv/0aXtBOrWJUCURLnkMEwo4V4e1UQ2EpOepcnpCgMRfbkxns1RKZBvGw@@HcW0Nb1D8 "JavaScript (Node.js) ‚Äì Try It Online")
`s.match('^'+n)` is either *null* or a singleton array holding \$n\$ as a string. By applying the unary `+`, these values are coerced to \$0\$ or \$n\$ respectively.
---
# JavaScript (ES6), 52 bytes
Takes input as a string.
```
s=>[...s].reduce(t=>t+!(i-s.indexOf(i+1,i))*++i,i=0)
```
[Try it online!](https://tio.run/##XclLDoIwEADQvbeQVcfCxLYIYVGu4AGMC9KPGUJaw1Tj7atr3/aty3tht9OzdCn7UKOtbOcbIvId9@BfLohi5yKPgjpGSj58rlGQVC0BnKSkluwZqsuJ8xZwyw8RRaNH0ys9mMkopRuAw98Pl95o9Yv6BQ "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), ~~112~~ \$\cdots\$ ~~52~~ 51 bytes
Saved 9 bytes thanks to [ElPedro](https://codegolf.stackexchange.com/users/56555/elpedro)!!!  
Saved a byte thanks to [Jonathan Allan](https://codegolf.stackexchange.com/users/53748/jonathan-allan)!!!  
Saved ~~3~~ 4 bytes thanks to [Poon Levi](https://codegolf.stackexchange.com/users/79630/poon-levi)!!! 
```
f=lambda s,i=0:s>s[:i]and(s[:i]+`i`in s)*i+f(s,i+1)
```
[Try it online!](https://tio.run/##XY7NasMwEITvfoplT1KtBkn@jUA59gl6C4GotUwEqWwkFVpKn91VYhdKb9/OzA4zf6bL5OWyjPpq3l4GA5E5zVU8xKNyJ@MHcofy7M7OQ6QPrhxJzpSCLkF/PYd3q9BEZPBkrtEqQD8lyMJ3MU4Bko2J2Y/ZvibI/6QAgjshedfWopM9soqyTavqpu36veC5q2n@y1wImY2234xbim/cNnUlxR/h976XU1XAHJxP6xh8PCAbyY0pC8eNtF5HnhiuYAdcfgA "Python 2 ‚Äì Try It Online")
Takes a number in the form `.abc...` as string input and returns its SRI.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~9~~ 8 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
·π´Jw"J·∫π1S
```
A monadic Link accepting a list of the digits after the decimal point which yields an integer.
**[Try it online!](https://tio.run/##y0rNyan8///hztVe5UpeD3ftNAz@//9/tJGOuY6xjomOoY6RjhmQZQnEhiBeLAA "Jelly ‚Äì Try It Online")**
### How?
```
·π´Jw"J·∫π1S - Link: list of digits, A        e.g. [3,2,1,0,5]
 J       - range of length (of A)              [1,2,3,4,5]
·π´        - tail from index (vectorises)        [[3,2,1,0,5],[2,1,0,5],[1,0,5],[0,5],[5]]
    J    - range of length (of A)              [1,2,3,4,5]
   "     - zip with:
  w      -   first index of substring or 0     [3,1,0,0,1]
               Note: w has implicit decimalisation of its right argument,
                    so [7,6,5,4]w65 is equivalent to [7,6,5,4]w[6,5] = 2
      1  - literal one                         1
     ·∫π   - indexes of                          [2,5]
       S - sum                                 7
```
[Answer]
# [J](http://jsoftware.com/), ~~30~~ 29 bytes
```
1#.#\(=#])(<:,:#@":)@#\".;.0,
```
[Try it online!](https://tio.run/##Xc29CsIwFAXgPU9xSYY0EMO9@TcaKAhOTs51Eou49P2nVEgd6nCGc77hfBo3coZaQIIGhPLNwcDlfrs2EkZMQxUPNZyLLmLkRY1i4uZkUDfFGHs93ws4qDCDJIspeko2y76H8APnQ0z5SLhJzH@CRHYz7IT7GoN3luTusE9tBQ "J ‚Äì Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~46~~ 44 bytes
```
->n{r=0;n.chars.sum{n[r+=1,r]=~/^#{r}/?r:0}}
```
[Try it online!](https://tio.run/##VcjRCsIgFIDhV4l1mblznNOtsB5EDFYwupmMMwaGs1c3rKvu/u@n9f7Ko8nHi49k4Oz54znQwpd1it7SwSAjZ971bR8p1Vc6QUrZVhwFaCVRi65iRY1sle56hD8Coijje1UrG4GlfuH4NMxxC9u8s4GNNjiX8gc "Ruby ‚Äì Try It Online")
Thanks Value Ink, as usual, for -2 bytes.
[Answer]
# [Perl 5](https://www.perl.org/) `-pl`, 27 bytes
Requires input to be in the format `.####...`:
```
$\+=++$a*/\G$a/ while/./g}{
```
[Try it online!](https://tio.run/##K0gtyjH9/18lRttWW1slUUs/xl0lUV@hPCMzJ1VfTz@9tvr/fz1DI2MTUzNzC0tDg3/5BSWZ@XnF/3V9TfUMDA3@6xbkAAA "Perl 5 ‚Äì Try It Online")
## Original version below handles input with or without a leading `0`.
### [Perl 5](https://www.perl.org/) `-pal`, 34 bytes
```
s/^0//;$\+=++$a*/\G$a/ while/./g}{
```
[Try it online!](https://tio.run/##K0gtyjH9/79YP85AX99aJUbbVltbJVFLP8ZdJVFfoTwjMydVX08/vbb6/389QyNjE1MzcwtLQ4N/@QUlmfl5xf91fU31DAwN/usWJOYAAA "Perl 5 ‚Äì Try It Online")
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~31~~ 30 bytes
```
{sum m:ex/\d+<!{$/-$/.from}>/}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYKvwv7q4NFch1yq1Qj8mRdtGsVpFX1dFXy@tKD@31k6/9n9xYqWCHlBlWn6RQk5mXmrxfz1DIwNzMxNDcyMLLiDb2MTUzNzC0tAAiWNgaGjEpQcUMTM1MTYy5NIDUwA "Perl 6 ‚Äì Try It Online")
### Explanation:
```
{                            }   # Anonymous code block returning
 sum                             # The sum of
     m:ex/                  /    # All possible matches
          \d+                    # Of numbers
             <!{$/-       }>     # That are equal
                   $/.from       # To their position in the string
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 29 bytes
```
¬∂$.`$.`$*;$'¬∂
Gm`^(.+);+\1
;
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wn@vQNhW9BBDSslZRP7SNyz03IU5DT1vTWjvGkMv6/389I3NjE0MjM2NLY0NDIy49QyMDczMTQ3MjCxDb2MTUzNzC0tAAiWMAVgcUMTM1MTYy5NIDUwA "Retina 0.8.2 ‚Äì Try It Online") Link includes test cases. Assumes input begins with the decimal point. Explanation:
```
¬∂$.`$.`$*;$'¬∂
```
For each offset in the string, list the offset in decimal, then again in unary, then the suffix starting at that offset, wrapping the whole thing in newlines so that the characters in the input string don't contaminate the data.
```
Gm`^(.+);+\1
```
Keep only the lines where the suffix starts with the offset.
```
;
```
Take the total of the matching unary offsets.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 18 bytes
```
Ôº©Œ£Ôº•Ôº¨Œ∏√óŒπ‚ÅºÔº©Œπ‚úÇŒ∏Œπ‚Å∫ŒπÔº¨Ôº©Œπ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEI7g0V8M3sUDDJzUvvSRDo1BTRyEkMze1WCNTR8G1sDQxpxiiLhMoEZyTmZyqUaijAJQLyCkFq4Hqg6qBAev///WMzI1NDI3MjC2NDQ2N/uuW5QAA "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Assumes input begins with the decimal point. Explanation:
```
    Œ∏               Input string
   Ôº¨                Length
  Ôº•                 Map over implicit range
                 Œπ  Current index
                Ôº©   Cast to string
               Ôº¨    Length
              Œπ     Current index
             ‚Å∫      Added
            Œπ       Current index
           Œ∏        Input string
          ‚úÇ         Sliced
         Œπ          Current index
        Ôº©           Cast to string
       ‚Åº            Equals
      Œπ             Current index
     √ó              Multiplied
 Œ£                  Take the sum
Ôº©                   Cast to string for implicit print
```
[Answer]
# [Haskell](https://www.haskell.org/), 71 bytes
```
import Data.List
f l=sum[i|(i,x)<-zip[0..]$tails l,show i`isPrefixOf`x]
```
[Try it online!](https://tio.run/##XYm7CsIwFED3fsWlOLRQQ5I@Bbs5KrqXYjM09GLShiZiEf89DnFyO49J2MeolPeozbI6OAknyBmtiySo1j51h58Esy097t9oOkpIv3MClQWV2Wl5AQ5ob@socbvKYeu9FjhDC1qYyx0Ss@LsgIBMoYsgJozTuipYzZs4C54XZVU3B0b/AmWMh/Q7VVnknAUO2Psv "Haskell ‚Äì Try It Online")
[Answer]
# Java 8, 86 bytes
```
s->{int r=0,i=0;for(;i<s.length();)r+=s.substring(i++).startsWith(i+"")?i:0;return r;}
```
To the point approach. Will see if I can find something shorter later on. Also, this is probably the first time I've used `startsWith` in Java (either in or outside codegolfing). ;)
Input as a String.
[Try it online.](https://tio.run/##jY8xb8IwEIX3/IpTJlsplu2EBOqm/QVlYehQdTAhUNPgIJ@DVKH89tRJGbpUsJx07z699@6gz3p22H4NVaMR4VUbe4kAjPW12@mqhtW4TgJUZO2dsXtAqoLYR2Gg195UsAIL5YCz58sIupI/mJKrXeuIMk/Imtru/SehirqkRIbdBicnYpKEsuDhPL6ZQJgkjumLeeTK1b5zFpzqBzUGnbpNE4KueefWbOEYyl4rvX@Apr9N19/o6yNrO89O4eQbSyyrSCyLNBMyT5epEDKm0wv/00LyIs9EIRd3oGk2z4vFUvD7WX5Pidt@@TxLpbiJ/aX6qB9@AA)
**Explanation:**
```
s->{                       // Method with String parameter and integer return-type
  int r=0,                 //  Result-sum, starting at 0
  i=0;for(;i<s.length();)  //  Loop `i` in the range [0,input-length):
    r+=                    //   Increase the result-sum by:
       s.substring(i++)    //    Take the substring of the input, starting at index `i`
                           //    And increase `i` by 1 afterwards with `i++`
        .startsWith(i+"")? //    If this substring starts with `i` (converted to String):
          i                //     Increase the result-sum by `i`
         :                 //    Else:
          0;               //     Leave the result-sum the same by increasing with 0
  return r;}               //  And return the sum as result
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~64~~ 60 bytes
```
lambda i:sum(x for x in range(len(i))if`x`==i[x:x+len(`x`)])
```
[Try it online!](https://tio.run/##VYnRCoIwFEDf@4r7tl2C6G6mTtiXWOAiVxd0ylJYX78KhOi8nXPm1/KYgsrenvPgxuvNATfPdZQJ/BQhAQeILtx7OfRBMiL7LnXWcpuatP@2j@IF8xw5LOClOKhKF6RKbTSRErj7HbNRb/xNUro4lVVt6CgwvwE "Python 2 ‚Äì Try It Online")
The `0` result works because an empty list in Python is equivalent to `False` which is equivalent to `0` and when you `sum(0)` you very conveniently get `0`.
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 74 bytes
```
a=>Enumerable.Range(1,a.Length).Sum(x=>a.Remove(0,x).StartsWith(x+"")?x:0)
```
[Try it online!](https://tio.run/##jcw7D4IwGIXh3V9hmNqITVuuXsDB6MSEA3MlBZrIR9IW039fmdwkruc8eVuzb43y9xnas7FaQR8qsOW2K7woyhvMo9Ti@ZKkFtBLxEJBKgm9HTB5zCNyRSlILcfpLREN3TJaoa1plB2Q2wUBvrgjxf60uU5gpiXTaGVlpUCiDgWEcZqlMct4HmD8G0Vxkmb5gdF/FGWMr7i1RprEEWcr4Pv7Dw "C# (Visual C# Interactive Compiler) ‚Äì Try It Online")
[Answer]
# T-SQL, 103 bytes
```
SELECT number+1FROM spt_values
WHERE type='P'and-~number=substring(concat(@,''),number+3,len(number+1))
```
**[Try it online](https://rextester.com/VRZL76178)**
[Answer]
# [Zsh](https://www.zsh.org/), 43 bytes
```
repeat $#1 ((r+=0${(M)1[++i,-1]#$i}))
<<<$r
```
[Try it online!](https://tio.run/##RY7NCsIwEITv@xQL2UNiVLLpr6V9BJ@gFOqhpb1UiZ4MefYYquBl@GCGmXk/lzhLJaObHtPthSQYpXS6M@TlVXGv9Xo88SBoDUpB27bkogKY7w43lMDWVGXOla0TZnlRVvWFzZ8NswUDZZFnluGrCn0qQNoAAuyV/T5GnsXhHAR523EIOl3gRo9kkPzPazhgSlvNwxiG@AE "Zsh ‚Äì Try It Online")
Takes input as a string. Repeatedly `(M)`atches the part of the string string at position `++i` to `-1` that `#`starts with `$i`, and adds it to `$r`. The `0` ensures that a valid number is added in the case of no match, so `$r` is set to a value before being printed.
[Answer]
# [Python 2](https://docs.python.org/2/), 53 bytes
```
f=lambda s,i=0:s>''and(s.find(`i`)==0)*i+f(s[1:],i+1)
```
A recursive version of a previous version of [Noodle9's Python 2 answer](https://codegolf.stackexchange.com/a/199838/53748).
**[Try it online!](https://tio.run/##VYzBDoMgEETv/QpuQLWGRUVLgj/SNJHGkm7SohEu/XqKeupcdt7sZJZvfM1epuTM234ekyWhRCN0GCi1fmKhcpjPiCM3RvAzFo6FG@h7iQXw5OaVxGeIBD1htAIpOtVAJ3takg3rplVdfwXxzwJA7smRq7apJez2cFyfSNayoo/7fn5dhlxwbCOefg "Python 2 ‚Äì Try It Online")**
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 49 bytes
`[Double]` has [15 to 17 significant decimal digits precision](https://en.wikipedia.org/wiki/Double-precision_floating-point_format), so we can consider a finite number of digits
```
param($n)1..99|%{$s+=$_*($n-match"^.{$_}$_")}
+$s
```
[Try it online!](https://tio.run/##XY9bC4JAFITf91cc5JhuXnC9Gwj9ksRswwc180KB@tttRS3o7cw3Mwemfrx40@a8KGa8QwzDXKdNWqpYUWaaUTTKA7ZajMlRIKNMuyyXLuaAyYSJRCeiYTtPhJxVoquKyWwr8F0W2KGig0M35rieH4QRswT0vD9qMWYL7ocrXzLWevqe69jsp3cp/lIYQYaBAGDVl1fe6ID8XfOs4zcxApPFaXjbF52QB7FsywkuobpZBn9@W/S0FyQyzR8 "PowerShell ‚Äì Try It Online")
---
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 54 bytes
any string representation of decimal number
```
param($n)$n|% t*y|%{$s+=++$i*($n-match"^.{$i}$i")}
+$s
```
[Try it online!](https://tio.run/##XY/hCoJAEIT/31MsspaXGt6ppwVBT1KYXSSomWdUqM9uJ1lB/3a@mVmY6nKXtTrLPB/wBBtohyqpk8LCkmLZmdAsnp3ZorI3to3ZQnO3SJr0bOyWLWY9ZgbtiY1q6AnZWsSx5kvGvUgELOLx3AGfTswPQhHFK@ZpGIZ/1GOMay7iNx8z3vsUYeBz9tMfqf9S6MCElgBgeSsOsnYA5aOSaSOPegnuR6eW6pY3Ws70vCmnuYHWZLny@m3R9adgkH54AQ "PowerShell ‚Äì Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt) `-x`, 12 bytes
```
√ä√á¬•UtZZsl¬π*Z
```
[Try it online!](https://tio.run/##y0osKPn//3DX4fZDS0NLoqKKcw7t1Ir6/19Jz9DI2MTUzNzC0sDQ0EiJS7cCAA "Japt ‚Äì Try It Online")
]