# Find self-locating strings in a number

## APL (Dyalog Extended), 16 bytes

```
+/⍬∘⍋(⍸⊣⊃¨⍕⍛⍷¨)⊂
```

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
```

## 05AB1E, 9 bytes

```
āʒ.$yÅ?}O
```

Try it online!

## Python 2, ^{112 \$\cdots\$ 52} 51 bytes

Saved 9 bytes thanks to ElPedro!!!

Saved a byte thanks to Jonathan Allan!!!

Saved ~~3~~ 4 bytes thanks to Poon Levi!!!

```
f=lambda s,i=0:s>s[:i]and(s[:i]+`i`in s)*i+f(s,i+1)
```

Try it online!

Takes a number in the form `.abc...`

as string input and returns its SRI.