[Question]
  [
# Introduction
A while ago a lost SO user posted a question here and its now been deleted but I think it would make a good challenge so here it goes...
# Challenge
Write a full program or function that takes two strings and checks whether any permutation of the first string is a sub-string of the second string.
# Input
Two strings, a string and a sub-string to test for (you may choose the order).
# Output:
A truthy value if the string contains any permutation of the sub-string.  
A falsey value if the string does not contain any permutations of the the sub-string.  
The test is case sensitive.
# Examples/Test cases
```
         sub-string    string          
input    d!rl          Hello World!
output   truthy
input    Pog           Programming Puzzles & Code Golf
output   falsey
input    ghjuyt        asdfhytgju1234
output   truthy
```
  
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 2 bytes
```
sp
```
[Try it online!](https://tio.run/nexus/brachylog2#@19c8P@/UmJxSlpGZUl6VqmhkbGJ0n@l9Iys0soSJQA "Brachylog – TIO Nexus")
### Explanation
```
Input variable = "Hello World!", Output variable = "d!rl"
(?)s        Take a substring of the Input variable
    p(.)    It is a permutation of the Output variable
```
[Answer]
# JavaScript (ES6), 77 bytes
```
(s,t)=>t&&[...t.slice(0,s.length)].sort()+''==[...s].sort()|f(s,t.slice(1))
```
Returns 1 or 0.
**Snippet**
```
f=
(s,t)=>t&&[...t.slice(0,s.length)].sort()+''==[...s].sort()|f(s,t.slice(1))
console.log(f('d!rl','Hello World!'))                   //1
console.log(f('Pog','Programming Puzzles & Code Golf')) //0
console.log(f('ghjuyt','asdfhytgju1234'))               //1
```
[Answer]
## Python 2, ~~67~~ 66 bytes
Takes input as two strings, substring first.
```
a=sorted
lambda s,S:a(s)in[a(S[n:n+len(s)])for n in range(len(S))]
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 3 bytes
```
œåZ
```
[Try it online!](https://tio.run/##MzBNTDJM/f//6OTDS6P@/09RLMrh8kjNycnXUQjPL8pJUQQA "05AB1E – Try It Online")
-1 byte thanks to [Emigna](https://codegolf.stackexchange.com/users/47066/emigna).
Explanation:
```
œåZ 2 inputs
œ                  permutations of the first input
 å  Is each of the                                 in the second input?
  Z Take the maximum of the resulting boolean list
```
[Answer]
# Japt, ~~10~~ ~~7~~ 6 bytes
```
á d!øV
```
[Try it online](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=4SBkIfhW&input=ImQhcmwiCiJIZWxsbyBXb3JsZCEi)
```
á d!øV   :Implicit input of sub-string U & string V
á        :Permutations of U
  d      :Any
   !øV   :  Contained in V
```
[Answer]
# Java 8, ~~266~~ 244 bytes
```
import java.util.*;Set l=new HashSet();s->p->{p("",p);for(Object x:l)if(s.contains(x+""))return 1>0;return 0>1;}void p(String p,String q){int n=q.length(),i=0;if(n<1)l.add(p);else for(;i<n;)p(p+q.charAt(i),q.substring(0,i)+q.substring(++i,n));}
```
**Explanation:**
[Try it here.](https://tio.run/nexus/java-openjdk#jZBBj9owEIXv/IrZHCqbBANtTw1Eaiu1e0FFolIPVQ8mcRIjxzb2eNks4rdTh7LaarnswfbM0/jz8ztPp/CzFWC5Qw8HiS1Mp@Ntj2JSmqBxDNwJwNb4Yed4aYdhMHUUBHDtD8KNRrKzJqo7/sBZQKnYOH9Fuh2pgy5RGs2@XYt8VCruPayOI4CNQFBLLQ5wz30bO0JvkADPVxcbdFI32ev@izFKcF0U5TJOA/hJYSfF0ZIkySzNa@PIj@1OlAiPnxSVNfGsNBq51J48pklCqRMYnIZ5Mcuv5ayY56dbK3lcD0ZWYMm/x8Fm12JPj1Ij6OWeKaEbbAnN5HKWx/f0Yk4V41VFoh2hYs6Dp1wudE4tsemelS13n5FImu2ZD1t/QZJZJmn6v5CmMtOU3jqLtmzYKlmCR47xuJjs4hevPn//AU6Pl3hW0MEShtBXMe6LtOk9io6ZgMzGaVSadKxk3FrVk@ReKGXgl3Gqukvos1rdORWjewtg7UzjeNcNMa3D05MSHt7BV1MJ@G5U/cJcm@aNSO6ruu2x2YX5@w8fXwhNuws9XiGn0el8/gs)
```
java.util.*;                   // Required import for Set and HashSet
Set l=new HashSet();           // Class-level Set
s->p->{                        // Method (1) with two String parameters and boolean return-type
  p("",p);                     //  Put all permutations in the class-level Set
  for(Object x:l)              //  Loop over the permutations:
    if(s.contains(x+""))       //   If the input String contains one of the permutations:
      return 1>0;//true        //    Return true
                               //  End of loop (implicit / single-line body)
  return 0>1;//false           //  Return false
}                              // End of method (1)
void p(String p,String q){     // Method (2) with two String parameters and no return-type
  int n=q.length(),i=0;        //  Two temp integers
  if(n<1)                      //  If `n` is zero:
    l.add(p);                  //   Add this permutation of the String to the Set
  else                         //  Else:
    for(;i<n;                  //   Loop over `n`
      p(p+q.charAt(i),q.substring(0,i)+q.substring(++i,n))
                               //    Recursive-call with permutation parts
    );                         //   End of loop (no body)
}                              // End of method (2)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
Œ!ẇ€Ṁ
```
[Try it online!](https://tio.run/##y0rNyan8///oJMWHu9ofNa15uLPh////SimKRTlK/5U8gLL5Ogrh@UU5KYpKAA "Jelly – Try It Online")
-1 thanks to [Emigna](https://codegolf.stackexchange.com/users/47066/emigna) for encouraging me to retry golfing.
Explanation:
```
Œ!ẇ€Ṁ Main link, dyadic
Œ!               the permutations of the left argument
  ẇ€  Is each of                                      in the right argument?
    Ṁ Maximum of boolean values 
```
[Answer]
# [Python](https://docs.python.org/), 60 bytes
An altered form of [TFeld's answer](https://codegolf.stackexchange.com/a/122945/53748) - go give some credit!
```
s=sorted
f=lambda u,t:s(u)==s(t[:len(u)])or t and f(u,t[1:])
```
Recursive function returning the boolean `True` (truthy) or an empty string (falsy).
**[Try it online!](https://tio.run/nexus/python3#HY67DoIwGEZneYqfDtKaOqBOTerioCObA2Go6QVIaU0vA7w8guP5cpLzrZFHH5KSheZWTB8pINPEIs6E84hTy6xyG3TEB0ggnASNN6OtWUdWvY8qJhgcYIxkGSyigF7KWg9vH6wsEaEYNd4giprgTRDTNDgDTV4WqyIc4eGlgqe3@m@afsxz2mQRpe7nZMZcX643RAgrDt8wuIT3IIXqfK/o9uW0IyHrDw "Python 3 – TIO Nexus")**
sorts the substring, `u`, and the same length of the front of the string, `t`, (using a slice `t[:len(u)]`) if they are the same then `True` is returned, otherwise if `t` is still truthy (not empty) recurses with a dequeued `t` (using a slice, `t[1:]`). If `t` does become empty the `and` is not executed and this empty `t` is returned.
[Answer]
# Pyth, ~~9~~ 8 bytes
```
sm}dQ.pE
```
*-1 byte thanks to @Erik\_the\_Outgolfer*
Takes two quoted strings, the second of which is the substring.
[Try it!](https://pyth.herokuapp.com/?code=sm%7DdQ.pE&input=%22Hello+World!%22%0A%22d!rl%22)
[Answer]
## Mathematica, ~~55~~ 50 bytes
-5 bytes from user202729
```
StringFreeQ[#2,""<>#&/@Permutations@Characters@#]&
```
Returns `False` if a permutation of the first input is in the second string. Returns `True` if a permutation of the first input is not in the second string.
Explanation:
```
                                    Characters@#   - split first string into array of characters
                       Permutations@               - make all permutations
               ""<>#&/@                            - join each array of characters together to form a single string
StringFreeQ[#2,                                 ]& - Check if any of these string is in the second input string
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), ~~13~~ 12 bytes
```
le!lf{\#)}:+
```
[Try it online!](https://tio.run/##S85KzP3/PydVMSetOkZZs9ZK@///9Iys0soSrsTilLSMypL0rFJDI2MTAA "CJam – Try It Online")
I feel like CJam is really limited compared to other golfing languages, but maybe it's just me being bad... 
I'm thinking about moving to another. 05AB1E seems fun.
*Fixed small bug thanks to Erik the Outgolfer*  
*Cut one bite because non-zero numbers are truthy*
Explanation:
```
l                 Read substring
 e!               Generate all permutations
   l              Read string
    f{            For each permutation
      \#            Check if it is in the string (returns -1 if not found)
        )           Add one
         }        End for
          :+      Sum the whole found/not found array
```
[Answer]
# [Java 9 JShell](http://jdk.java.net/9/), 160 bytes
```
p->q->IntStream.range(0,q.length()-p.length()+1).anyMatch(
    i->Arrays.equals(
        q.substring(i,i+p.length()).chars().sorted().toArray(),
        p.chars().sorted().toArray()))
```
(newlines inserted for readability)
[Try it online!](https://tio.run/nexus/java-openjdk9#hVBNb9swDL3rV7CXQVoTYd12S2NgGLAPYB0C5LDDsANr07YyWXIkqp079LdncuxmRVFsPEgE@d4jH03X@8CwwxvUiY3VL1fCPK3VyZVsvHu2GTkQdmNL9OnamhJKizHCFRoHvwXkmOuRkfN3400FXe7KLQfjmu8/AEMT1Qwe48M88HJCLGATqDIlMs2VooAa1od@WeyXxWfH22mJgK4h@Wqx15Zcw61Uy/6Unl8ojW64Qi5baZbFuxBwiJr2CW2Uex3TdTyKS7Mw5395SpcthiiVjtk5VTlhfyRLtej/0VTq8GBotS3ROQoQ8w9rcHQLc0luh8jUaePU6nSA29ZYAjmidYvxK/3iL8ZR1nx0pTGmc2Q9qjJhfdTX7gRfPQdus23G8ud/4dNiPrHuM5Gtk7XGvreDnOZlrxRZPuipR/x7Mb33h@osWPGJrPXwzQdbnYmNb8Qm@CZg1437bNLdnaUIL@C9rwg@eluLpt2lgQXGqm4Hbnbp4vWbt38A "Java (OpenJDK 9) – TIO Nexus")
Note: JShell includes a number of imports by default. As a Java 8 or Java 9 solution, it would be necessary to import:
```
import java.util.*;import java.util.stream.*;
```
For an extra 45 bytes, or 205 bytes total. The TIO link above is to a Java 9 program since TIO doesn't currently have JShell (and it's not clear to me how JShell would work on TIO).
[Answer]
# C#, 320 bytes
```
using System.Linq;s=>u=>p(u.ToArray(),0,u.Length-1).Any(p=>s.Contains(p));w=(c,a,b)=>{if (a!=b)(var t=c[a];c[a]=c[b];c[b]=t;)};System.Collections.Generic.IEnumerable<string>p(char[]l,int k,int m){if(k==m)yield return new string(l);else for(int i=k;i<=m;){w(l,k,i);foreach(var c in p(l,k+1,m))yield return c;w(l,k,i++);}}
```
I'm sure calculating the permutations can be a lot shorter but I can't see how at the moment.
Formatted/Full version:
```
void test()
{
    Func<string, Func<string, bool>> f = s => u =>
        p(u.ToArray(), 0, u.Length - 1).Any(p => s.Contains(p));
    Console.WriteLine(f("Hello World!")("d!rl"));
    Console.WriteLine(f("Programming Puzzles & Code Golf")("Pog"));
    Console.WriteLine(f("asdfhytgju1234")("ghjuyt"));
}
System.Collections.Generic.IEnumerable<string>p(char[] l, int k, int m)
{
    Action<char[], int, int> w = (c, a, b) =>
    {
        if (a != b)
        {
            var t = c[a];
            c[a] = c[b];
            c[b] = t;
        }
    };
    if (k == m)
        yield return new string(l);
    else
        for (int i = k; i <= m;)
        {
            w(l, k, i);
            foreach (var c in p(l, k + 1, m))
                yield return c;
            w(l, k, i++);
        }
}
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 69 bytes
```
->a,b{r=nil;a.chars.each_cons(b.size){|q|r||=q.sort==b.chars.sort};r}
```
[Try it online!](https://tio.run/nexus/ruby#RYu7DoIwFEB3v6J2EE2wiY@N1MVBRzYHQ0yhpUAKV25pwvPbURON48k5p@Xz9iT8eEBe5SYQLMkEWqZEkj0SqOw6Zjbv1WYY6xHHkdfMAjacx9/wQ1OA0/x0jSXt3bsqY4DcAI1cer4nl2i8aPGzIYJGUZZ5pUno@t4oS1bkDFKRC5j0PYSg/z0VVqZZ1@jC7faHI/WpzgrXNTSaXw "Ruby – TIO Nexus")
[Answer]
# [Perl 6](http://perl6.org/), 48 bytes
```
{$^a.contains(any $^b.comb.permutations».join)}
```
Returns an or-junction of each permutation's presence as a substring. For example, with arguments `"Hello World!"` and `"d!l"`, returns:
```
any(False, False, False, False, True, False)
```
...which "collapses" to `True` in a boolean context. That is, junctions are truthy values.
[Answer]
# PHP>=7.1, 91 Bytes
```
for([,$x,$y]=$argv;~$p=substr($y,$i++,strlen($x));)$t|=($c=count_chars)($x)==$c($p);echo$t;
```
[Testcases](http://sandbox.onlinephpfunctions.com/code/5593a150bb9b96c6d8bc13ee03c2ffcd0d7ca2a8)
[Answer]
# Haskell, 54 bytes
```
import Data.List
s#t=any(`isInfixOf`s)$permutations t
```
Using the power of Data.List for both `isInfixOf` as well as `permutations`.
[Answer]
# [R](https://www.r-project.org/), 103 bytes
```
function(w,x,y=u(w),z=u(x)){for(i in 1:n(w)){F=F|!sum(setdiff(y[1:n(x)+i-1],z))};F}
u=utf8ToInt
n=nchar
```
[Try it online!](https://tio.run/##JcqxbsIwFIXhPU9x4wHZwgwpHSogE1KALUOlDoghwrmOkeMrObZI0vLsaSKmI53v9xPCYQMTRncPhhx/yl4OeeRPIcd5eiF@kTw3YBxku9nno8iLv7SLLe/qoAwiH64L9WJtNtlNjkK89sUriXkM@PVNFxcSl7t7U/kJOTvX1hL8kLcqZRKYSr1lIpml9KR91bbGaSjjONq6gxUcSdVwIotLXJJ@t1WnsBmCfsTsY/u5kG4ecQhMTP8 "R – Try It Online")
Returns `TRUE` for truthy and `NA` for falsey.
[Answer]
# MATL, 10 bytes
```
Y@Z{w&Xfma
```
[Try it on MATL Online](https://matl.io/?code=Y%40Z%7Bw%26Xfma&inputs=%27d%21rl%27%0A%27Hello+World%21%27&version=20.9.1)
[Answer]
# [Ruby](https://www.ruby-lang.org/), 43 bytes
```
->a,b{b.chars.permutation.any?{|c|a[c*""]}}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsEiN9ulpSVpuhY3tXXtEnWSqpP0kjMSi4r1ClKLcktLEksy8_P0EvMq7atrkmsSo5O1lJRia2uhWjoKFNyilTxSc3LyFcLzi3JSFJV0FJRSFItylGIVlBVs7RRKikpTucCqAory04sSc3Mz89IVAkqrqnJSixXUFJzzU1IV3PNz0kAaA_LTYfrSEnOKoRoTi1PSMipL0rNKDY2MTUDq0jOySitLkK2AuGfBAggNAA)
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 18 bytes
```
{∨/(∧/⍺∊⊢)¨⍵,/⍨⍴⍺}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///3/FR24TqRx0r9DUedSzXf9S761FH16OuRZqHVjzq3aoDFADSW4DCtf//q6coFuWoO6p7pObk5CuE5xflpCiqc6kH5KcDBQOK8tOLEnNzM/PSFQJKq6pyUosV1BSc81NSFdzzc9KA6tIzskorS4BKE4tT0jIqS9KzSg2NjE3UAQ "APL (Dyalog Unicode) – Try It Online")
[Answer]
# [Factor](https://factorcode.org/) + `math.combinatorics`, 35 bytes
```
[ '[ _ subseq? ] find-permutation ]
```
[Try it online!](https://tio.run/##TY@7TgMxEEX7/YqbLUJFpBAqkKCgCGnQShGiiCLk@LUOtmdjj4tNlG9fjBASU845dzTXCMmUpvft5m39AJEzyQyTRgTB/UJSOLgoquHqekiaeRySi4ysT0VHqTMem@bSoM4FrZol36J91d4TPih5NWtx/aMd2Qq7RDaJEFy06Mr57OuNOV5IaazJm3@@7Y9l5BoRWZl@ZHssy7vV/Y9xnXa42eETuRzqK8/Yw7iobgedQmHBjiL2k/kt9BTEgMxCfi2mbw "Factor – Try It Online")
Outputs the matching subsequence (which behaves as boolean true in Factor) for truthy and `f` for falsey.
]