[Question]
  [
# Challenge
Given a binary matrix and a binary string, determine if that binary string can be found starting at any point in the matrix and moving in any direction at any subsequent point to form the binary string. That is, can the string be found folded up however inside the matrix?
The string can only be folded at 90 degrees or 180 degrees (edge connections; Manhattan Distance 1) and cannot overlap itself at any point.
# Example
Let's take the following example:
```
Matrix:
010101
111011
011010
011011
Snake: 0111111100101
```
This is a truthy test case. We can see the snake folded up in the following position:
```
0-1 0 1 0 1
  |
1 1 1-0 1 1
  | | |   |
0 1 1 0-1-0
  | |
0 1-1 0 1 1
```
# Rules
* Standard Loopholes Apply
* You may take the length of the string and the width and height of the matrix as input if you'd like
* You may take the binary matrix and the binary string as a multiline string/array of strings/newline-joined string/anything else-joined string and a string
* You may take the dimensions as a flat array instead of several arguments
* Your program must finish for any 5 x 5 matrix with any string of up to length 10 in under a minute
# Limitations
* The matrix is not necessarily square
* The string will be non-empty
* The string can be length-1
* The string will not contain more squares than available (that is, `len(string) <= width(matrix) * height(matrix)`
# Test Cases
Truthy
```
01010
10101
01010
10101
01010
0101010101010101010101010
01110
01100
10010
10110
01101
011111000110100
0
0
10
01
1010
100
010
001
100010001
```
Falsy
```
00000
00000
00000
00000
00000
1
10101
01010
10101
01010
10101
11
100
010
001
111
10001
01010
00100
01010
10001
1000100010001000101010100
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), ~~275~~ ~~271~~ ~~264~~ 249 bytes
* Saved four bytes by replacing `-1` with `H` and removing one slicing operation (`[:]`).
* Saved seven bytes thanks to [Halvard Hummel](https://codegolf.stackexchange.com/users/72350/halvard-hummel); removing yet another slicing operation (`[:]`), using multiple-target assignment to give a visited entry a value `v not in "01"` (`S=S[1:];M[y][x]=H;` -> `S=M[y][x]=S[1:];`) and switching from a ternary if/else to a simple logical or (`any(...)if S else 1` -> `not S or any(...)`).
* If you somewhat extend your definition of *truthy* and *falsey*, you could allow this [257 byte long solution](https://tio.run/##fU/PT4MwFL73r6jdpchTW4@MetJlF@Jhl21dD5iBNEIhQAQu/OvYgk5NjG3Sl/f9eN9rNbRZae6njThNeVy8nGMcwQ46yAK5pbKQgUrLGhdYGxyphYEeBs@hg0Pr2LwmNJuB/hvoPJ3inWRKiEgOSvZKXTN0TlK8pdGPOcHuixc7yQO1/ifW38PgH@akPRwsJ@nIgHlA@fwyGJfCPaXTkYXWEXYPLBTWFmZX4rKPf7CJ/l4ptyRO8iYZ2R2biritdS8IIYhxdxHn9uW2c@1SOLL8ujHxW@KUFpgPc3rnREd4FpIwokASThRapgKeLVjgIq5orpsW8MLYb99wddtUuW4pORnieYCdgM4OD3WAM@vLE0M/HUw5yaX3EFrhY1KXj/pdN7o0T3Vd1mhV1dq0eEN/bQDYzZstSVG1wxyF/pT6x0/x9AE "Python 2 – Try It Online"). It raises an exception (`ZeroDivisionError`) when the snake is found and returns an empty list (`[]`) when there is no snake to be found, which are two distinct behaviours.
* Saved fourteen bytes thanks to [user202729](https://codegolf.stackexchange.com/users/69850/user202729); golfing two array deep copies
* Saved a byte; golfed `not S or` to `S<[1]or` ~ `S==[]or`.
```
lambda M,S,w,h:any(H(eval(`M`),S,w,h,x,y)for y in range(h)for x in range(w)if S[0]==M[y][x])
def H(M,S,w,h,x,y):S=M[y][x]=S[1:];return S<[1]or any(H(eval(`M`),S,w,h,x+X,y+Y)for X,Y in[(~0,0),(1,0),(0,~0),(0,1)]if~0<x+X<w>0<=y+Y<h!=S[0]==M[y+Y][x+X])
```
[Try it online!](https://tio.run/##nY8/b8IwEMX3fIqrJ1u5VnZHiNsNsSCGdIAES7giaaIGg0IoycJXT50/QKUWiWJLtu7u996zt1WRbMxzPZKLOtPr95WGCfp4wGSgTUXHNPrSGV1OlqzrYokVizc5VJAayLX5iGjSNspL48DSGPyQKyknYaXCUjFnFcUwppMfLgP/NJV@KAZqmEfFPjfge6FQ1vBKvjvDyp23kTOc29CQHjlyhlS0J8djdwmm0vjIPavwDi/ck1bmJQ/y/DB3bsPdmWL1Whd5WkpCiMNFsx0h7Cls1ZTdJRw7H@6M/owa0jbaxRu@UToBTmVIOFEYEkGU07kitBKQsNZbmqW7AqGb2E8/CvW022ZpQcnCEMYQGoC2CuYcEBKryyJDewVXDXKumbPNU1PAiJ6yoE8DhEZtaQLyFd7yfUR@wYH7D7h3doMLbNmRznbXnW@Dp/c8Y3oL3DvfBgfuHc5/fbD@Bg "Python 2 – Try It Online")
# Explanation
Lambda function which takes in the matrix as a two-dimensional list of strings (either `"0"` or `"1"`), the snake as a one-dimensional list and the matrix dimensions as two integers.  
The lambda function searches the matrix for entries that match the snake's first element. For every found match, it calls `H` with a deep copy of the matrix, no copy of the snake, the matrix dimensions and the match's position. 
When `H` is called, it removes `S`' first entry and sets the given position's matrix entry to something else than `"0", "1"`. If `S`' length is zero, it returns `True`; as it calls itself recursively, the snake was found somewhere in the matrix.  
If `S`' length is non-zero, it loops through the four cardinal directions, tests if that position is in the matrix, compares the matrix' element at that position with the first element of `S` and -- if it matches -- calls itself recursively.  
`H`'s return values are funneled up the stack frames, always checking if at least one function found a possible snake.
# Formatted Output
I have augmented my program to also output the path the snake slithers (if there is one). It uses the same ASCII output design as the question. [TIO link](https://tio.run/##hVNNb@IwED3jXzFrqZJNDIo5BswR0QNiJVYVxPUhVcOSXRKiJBVEWvWvs@N8lRZQQXIynvfePHsmaVnsDsno/Bpu4SdbiJU4ip14FL5IuUd6aRYlBdBVEvwN4SH34Ff2FlJ4AEqHfw5RwnxOeqQXB0UWnUCBNqS3PWRQQpRAFiS/Q7azOg3CUVobhFSY0wfmyL0aoEvjqEdc9ckICrRj4pbq3rQ3kDcKDWQrM4ySPMwKVvZHjhSgUcn02bE/QggaXosNek2H6SFlLq@FTqKSSq3ZaIvmJrD2oC3ZH6EjK2aQSAe0BU1vgAafQSUqbS5BKGJhFehfB5p@Bg2@gtYCrOmTgLJry3PSdKHtRsztUWJ7kFqKOxZEellYvGUJSEJso5/aRtvWYPXkUMDsYw@uuj4L9nmIQheNX3FCZur5vA/il9cAGrIXJCWbMx1rz3RWFqYZK7xjcZ3CmF/NzNWAoM2Vdo1Si3o6eHWSeTeyVrsaW6UN91ZqpaVnxg1YzcfNDdzzh3Et46xF6WxqKUczlOW1PTs0UaLZuytcLpisVle81w/JTbR9dyfInxyn7kShyGT3Q3WenQ0acdamOgiEeJ9fv7eu2rnunaKUElfaP5ESV4mRDeuHJJgf57ZHFokb1c@1eMskvlgqTV1qhKaSGlKrCqgoOEpxkLJ9lBeiHTtpP6thnu6jgtmx4VyABbCKwclRwA55@xAHrWa4xkK6mJMn1laBpg4IsLzLlO/cTTUsx7/LupVafi@4vMu6lfKdb1mtjfN/).
[Answer]
# JavaScript (ES6), ~~138~~ 134
Not so different from @Neil's, but what else could it be?
Input: matrix as a multi line string, binary string, width (not counting newline)
NB: the logic in the recursive function `r` is somewhat inverted to save a couple of bytes
```
(m,s,w)=>[...m].some((c,p,m,r=(p,o)=>s[m[p]=r,o]&&([~w,-~w,1,-1].every(d=>m[d+=p]!=s[o]||r(d,o+1))&&(m[p]=s[o-1])))=>c==s[0]&&!r(p,1))
```
*Less golfed*
```
(m,s,w)=>(
  m=[...m],
  r= (p, o) => 
    (m[p] = -w, s[o])
    && (
         [~w, -~w, 1, -1].every( d =>
            m[d+=p] != s[o] || r(d, o+1)
         )
         && (m[p]=s[o-1])
    ),
  m.some((c,p) =>c == s[0] && !r(p,1))
)
```
**Test**
```
var F=
(m,s,w)=>[...m].some((c,p,m,r=(p,o)=>s[m[p]=r,o]&&([~w,-~w,1,-1].every(d=>m[d+=p]!=s[o]||r(d,o+1))&&(m[p]=s[o-1])))=>c==s[0]&&!r(p,1))
// this slightly modified version tracks the path
var Mark=
(m,s,w)=>(m=[...m]).some((c,p,m,r=(p,o)=>s[m[p]=-o,o]&&([~w,-~w,1,-1].every(d=>m[d+=p]!=s[o]||r(d,o+1))&&(m[p]=s[o-1])))=>c==s[0]&&!r(p,1))
?m.map((c,p)=>c<-1?'.───│┘└.│┐┌.│'[((m[p-1]-c)**2<2)+((m[p+1]-c)**2<2)*2+((m[p+~w]-c)**2<2)*4+((m[p-~w]-c)**2<2)*8]:c<0?'*':c).join``:''
function go()
{
  O.textContent =F(M.value, S.value, M.value.search('\n'))+'\n\n'
  +Mark(M.value, S.value, M.value.search('\n'))
}
go()
```
```
#M {width:100px; height:100px }
```
```
<textarea id=M>010101
111011
011010
011011</textarea><br>
<input id=S value='0111111100101' oninput='go()'>
<button onclick='go()'>go</button>
<pre id=O></pre>
```
[Answer]
## JavaScript (ES6), 149 bytes
```
(m,s,w)=>[...m].some((c,i)=>c==s[0]&&g(m,s,i),g=(m,s,i)=>!(s=s.slice(1))||[~w,-1,1,-~w].some(o=>m[o+=i]==s[0]&&g(m.slice(0,i)+' '+m.slice(i+1),s,o)))
```
Takes the matrix as a newline-delimited string, the snake as a string and the width (as an integer). Loosely based on @JonathanFrech's answer.
[Answer]
# Mathematica, ~~180~~ ~~156~~ ~~141~~ ~~153~~ ~~138~~ ~~136~~ 104 bytes
```
MemberQ[#|Table[""<>Part[Join@@#,p],{x,1##4},{y,1##4},{p,FindPath[GridGraph@{##4},x,y,#3,All]}],#2,All]&
```
## Example input
```
[{{"1","1","1","1","1"},{"0","0","0","0","0"}},"10011001",8,5,2]
```
## Explanation
1. `GridGraph@{##4}` is a `Graph` object for a grid of vertices with adjacent vertices connected by edges, with dimensions `{##4}` - that is, `{#4,#5}` or `{width,height}`.
2. We iterate over all starting vertices `x` (numbered `1` to `1##4 = width*height`), all ending vertices `y`, and all paths `p` of length at most `#3` from `x` to `y`.
3. For each such path, `""<>Part[Join@@#,p]` extracts the corresponding characters of the matrix and puts them into a string.
4. We also include the matrix itself, whose characters are all the strings of length 1 that can be found in it.
5. We see if one of these strings matches `s`, searching at all levels because this is a very multidimensional list we've built.
Note: Replacing `#3` by `{#3-1}` in `FindPath`, so that we only find paths of exactly the right length, is a huge improvement in terms of speed - but costs 4 more bytes.
---
*-24 bytes: taking dimensions of things as input*
*-15 bytes: using `StringPart` and `StringJoin` properly*
*+12 bytes: fixing the length-1 case*
*-15 bytes: ...*
*-2 bytes: taking size of the matrix as input as an array*
*-32 bytes: using `Table` to iterate over the path lets us avoid using `Function`, and using `MemberQ[...,s,All]` lets us just sort of stick the matrix onto the table when dealing with snakes of length 1.*
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 346 341 336 302 297 bytes
```
(m,h,w,s,l)=>{for(int y=0;y<h;y++)for(int x=0;x<w;x++)if(N(x,y,l-1))return 0<1;return 1<0;bool N(int x,int y,int p){if(p<0)return 0<1;if(y<0|x<0|y==h|x==w||m[y,x]>1||s[p]!=m[y,x])return 1<0;int g=m[y,x];m[y,x]=2;if(N(x,y-1,--p)||N(x-1,y,p)||N(x,y+1,p)||N(x+1,y,p))return 0<1;m[y,x]=g;return 1<0;}}
```
[Try it online!](https://tio.run/##pVLBbqMwED2Xr5jesDJEdtqbcS4r7V66UaUe9hDlkFInQQUTYdJgAd@eNRhSElVtV4sH43m8eTNjO9JBlOXydNCx2sKT0YVMuRcla63hsfJ0sS7iCH4eVBTGqljiCsF@36flADxnWTKHJ7V@lSDg5Ke4wyNqTIiYV5ss9y0LjKDchDtuJhMyYKXFyvDIS4vFG3/hl2gwCRghuSwOuQIaMt4vWUh5mwgWLhQ70W7ek8pG70M6DrOICWld2tcIsatLIY51nS4Nlqs5q2u93K9uhfPJKEcruO1x7j5ixofqAoZBsCd1bT27Ntiv0UzYsJ44fFxMr7MdN9M0J@4Nu/yWxS/wex0rn3iVd@P2G1Jm97PyYPRUQBEYjmZo8IrBsDdH@oBBLxn0S4bVOBMaW/ZQYXt1kvbUqzYGmu7nQOzuCGjbxBm6bOac5MrouL@LvFfSs0@k3fjXBDe98l3XE22xAbrvIOZoPzKls0RO/@RxIR9iJf3u/vspw5RNf8niQaptsfMpufQZQc2sTZ1PCP8/rZm172i5g0Jmh75D9m3uveM2XnP6Cw "C# (.NET Core) – Try It Online")
5 bytes saved by golfing the `p` increment
5 bytes saved by taking in the snake length and starting at its tail, and removing an unnecessary space
34 bytes saved by reading the challenge properly and seeing I can take in the matrix's height and width
5 bytes saved, the single element test case failed, and the fix was beneficial
### Ungolfed
```
(m,h,w,s,l)=>{
    // Go through every potential starting point
    for(int y=0; y<h; y++)
        for(int x=0; x<w; x++)
            if(N(x,y,l-1)) // start the recursive steps
                return 0<1; // return true if N returns true, otherwise check the next element
    return 1<0; // return false as the snake doesn't fit into the matrix
    // C#7 local function in a Func
    bool N(int x, int y, int p)
    {
        // if there is no more snake to fit return true
        if(p<0)
            return 0<1;
        // if m element has part of the snake or 
        // snake part doesn't match matrix element then return false
        if(y<0 | x<0 | y==h | x==w || m[y,x]>1 || s[p] != m[y,x])
            return 1<0;
        // hold the current matrix element
        int g=m[y,x];
        // set the current matrix element to 2 to indicate it has a part of the snake
        m[y,x]=2;
        // check each of the four neighbours and recurse down that neighbour 
        // except if they are outside the matrix
        if(N(x,y-1,--p) ||
           N(x-1,y,p) ||
           N(x,y+1,p) ||
           N(x+1,y,p))
               return 0<1; // return true if remainder of the snake fits into the matrix
        // if snake doesn't fit then set the matrix element as not having part of the snake
        m[y,x]=g;
        // return false to indicate this neighbour direction doesn't fit the snake
        return 1<0; 
    }
}
```
[Answer]
# [Kotlin](https://kotlinlang.org), 413 bytes
```
var x:(Array<Array<Char>>,String)->Boolean={b,s->fun f(s:String,x:Int,y:Int):Boolean{if(b[x][y]!=s[0])
return 0>1
if(s.length<2)
return 1>0
val v=b[x][y]
b[x][y]='Z'
try{return(-1..1).map{x+it}.flatMap{t->(-1..1).map{y+it}.map{t to it}}.filter{(X,Y)->(x-X)*(x-X)+(y-Y)*(y-Y)==1&&X in b.indices&&Y in b[0].indices&&f(s.substring(1),X,Y)}.any()}finally{b[x][y]=v}}
b.indices.any{x->(0..b[0].size-1).any{f(s,x,it)}}}
```
## Beautified
```
var x: (Array<Array<Char>>, String) -> Boolean = { b, s ->
    fun f(s: String, x: Int, y: Int): Boolean {
        if (b[x][y] != s[0])
            return 0 > 1
        if (s.length < 2)
            return 1 > 0
        val v = b[x][y]
        b[x][y] = 'Z'
        try {
            return (-1..1).map{ x + it }
                    .flatMap { t -> (-1..1).map{y+it}.map { t to it } }
                    .filter { (X, Y) ->
                        (x - X)*(x - X) + (y - Y)*(y - Y) == 1 &&
                                X in b.indices && Y in b[0].indices &&
                                f(s.substring(1), X, Y) }
                    .any()
        } finally {
            b[x][y] = v
        }
    }
    b.indices.any { x -> (0..b[0].size - 1).any { f(s, x, it) } }
}
```
## Test
```
var x:(Array<Array<Char>>,String)->Boolean={b,s->fun f(s:String,x:Int,y:Int):Boolean{if(b[x][y]!=s[0])
return 0>1
if(s.length<2)
return 1>0
val v=b[x][y]
b[x][y]='Z'
try{return(-1..1).map{x+it}.flatMap{t->(-1..1).map{y+it}.map{t to it}}.filter{(X,Y)->(x-X)*(x-X)+(y-Y)*(y-Y)==1&&X in b.indices&&Y in b[0].indices&&f(s.substring(1),X,Y)}.any()}finally{b[x][y]=v}}
b.indices.any{x->(0..b[0].size-1).any{f(s,x,it)}}}
data class Test(val board: String, val snake: String, val output: Boolean)
val tests = listOf(
        Test("""01010
            |10101
            |01010
            |10101
            |01010""", "0101010101010101010101010", true),
        Test("""01110
            |01100
            |10010
            |10110
            |01101""", "011111000110100", true),
        Test("""0""", "0", true),
        Test("""10
            |01""", "1010", true),
        Test("""100
            |010
            |001""", "100010001", true),
        Test("""00000
            |00000
            |00000
            |00000
            |00000""", "1", false),
        Test("""10101
            |01010
            |10101
            |01010
            |10101""", "11", false),
        Test("""100
            |010
            |001""", "111", false),
        Test("""10001
            |01010
            |00100
            |01010
            |10001""", "1000100010001000101010100", false)
)
fun main(args: Array<String>) {
    tests.filter {(board, snake, expected) ->
        val boardR = board.trimMargin().lines().map { it.toCharArray().toTypedArray() }.toTypedArray()
        val result = x(boardR, snake)
        result != expected
    }.forEach { throw AssertionError(it) }
    println("Test Passed")
}
```
]