[Question]
  [
FizzBuzz is where a range of positive integers is taken, and numbers divisible by 3 are replaced with "Fizz", divisible by 5 with "Buzz" and divisible by 15 with "FizzBuzz".
I've got some FizzBuzz output here. Unfortunately, it's been shuffled:
```
4
Fizz
Fizz
Buzz
2
```
A bit of logic shows us that this is `2, Fizz, 4, Buzz, Fizz` shuffled.
Your challenge is to take a range of FizzBuzz, shuffled, and put it in any order such that it's valid FizzBuzz. For example, given `Fizz, Fizz, Buzz, 11` we can work out that the correct order is `Fizz, Buzz, 11, Fizz` (corresponding to `9, 10, 11, 12`)
Input will always be rearrangeable into valid FizzBuzz.
You may choose any values that cannot appear as integers to represent Fizz, Buzz and FizzBuzz.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), shortest wins!
## Testcases
```
1, 2, Fizz, 4, Buzz -> 1, 2, Fizz, 4, Buzz
Fizz, 4, Buzz, 1, 2 -> 1, 2, Fizz, 4, Buzz
Fizz, Fizz, Buzz, 11 -> Fizz, Buzz, 11, Fizz
Fizz, Buzz, 8, Buzz, 7, Fizz -> Buzz, Fizz, 7, 8, Fizz, Buzz
Buzz, Fizz -> either way
29, 31, FizzBuzz -> 29, FizzBuzz, 31
28, Fizz, FizzBuzz, 29 -> Fizz, 28, 29, FizzBuzz
8, 7 -> 7, 8
```
  
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), ~~21~~ 15 bytes
```
ṖÞ∞ƛ₍₃₅T∨;ÞS$↔h
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLhuZbDnuKInsab4oKN4oKD4oKFVOKIqDvDnlMk4oaUaCIsIiIsIjI4LCBbMF0sIFswLCAxXSwgMjkiXQ==)
Why use clever mathematics when you can just generate infinite FizzBuzz?
*-6 thanks to Steffan and emanresuA*
## Explained
```
ṖÞ∞ƛ₍₃₅T∨;ÞS$↔h
Ṗ                # All permutations of the input
 Þ∞              # An infinite list of positive integers starting at 1
   ƛ     ;       # To each number n:
    ₍₃₅          #   [n % 3 == 0, n % 5 == 0]
       T         #   Truthy indices of that
        ∨        #   Logical or that with the number. This gets either the indices of where Fizz or Buzz would usually be or n
         ÞS      # Sublists of the infinite fizzbuzz
           $↔    # Remove sublists which don't have everything from the input
             h   # Get the first item of that
```
[Answer]
# [J](http://jsoftware.com/), 54 bytes
```
(-:&(/:~)"1#])#]\1((,~{~0=])2-@#.0=5 3|])@+#i.@+9>.>./
```
[Try it online!](https://tio.run/##jZBda4MwFIbv/RUvFaZSTU3saCtYZINdjQ3GLitiS4qOMctiKcPhX3fHRmtvBr0IyXnOcz7IRzth1h5RCAsufIR0PIbHt@en1vbCO3sWNs6Em4ljJhtu225TN36UOMKLTeZH9wh@EyeemgWLp6s1W7NZ6xgvDwx2wZr6lioqMeQuL7EHdyFcpHTN6RIDXmKhn9a7VBV2mZLK0oRDkI852fBC1KzrMrL/pSGmnJYIdCHvHlfSgHvp3GhBG2l@LYqOCkqmvSxWSAMEYzsCFKXBZaBY9tLF0I0DwlrqRg3J8Rtej9XhWClsyyrHKftROOXyS4fZt8ShVKrYfkpr@MHz3kb7Bw "J – Try It Online")
\_1, \_2, \_3 represent Fizz, Buzz, FizzBuzz.
* Generate all integers from 1 to `<list length>` + max(9, `<max value>`)
* Fizz Buzz them
* Sliding window across them of size `<list len>`
* Find ones which set equal the input
[Answer]
# JavaScript (ES6), 82 bytes
*Saved 2 bytes thanks to a suggestion by [@emanresuA](https://codegolf.stackexchange.com/users/100664/emanresu-a)*
Expects and returns `-1` for *Fizz*, `-2` for *Buzz*, `-3` for *FizzBuzz*.
```
f=(a,i=k=0)=>[...b=a.sort().map(_=>-!(++i%3)-2*!(i%5)||i)].sort()+''==a?b:f(a,++k)
```
[Try it online!](https://tio.run/##VY9tT8IwFIW/71dcSEhb2zWwaXgxxcRE/gAfJzFldFiZHa7DRBi/fXRvUb@095ycPuf2Q35LG@f6WPgm26mqSgSWTIuDGBOxjDjnWyG5zfICE/4pj/hNLP0BplSPQuIHdwOsRw@kLDXZdCmKkBDyabtIHIjSA6ly9XXSucIosYjwXMndSqdq/WNiPCa8yNZFrs3e8e0x1QUevpoh4UmWv8j4HVsQS7h4AKkqQIIA28UQA9Su1ETwZaXP5wX4EwbPp2YKGNRep8IriewGyhKoJY8OGGfGZqniabbHbteWZWpWhPp3dUl/1x7aRAYohA3HEMe5kso1dlUM7tt2759iUEc6rz07e@L9lbN@mLYxr1XNGMwZhJPfH3nBrGf1luuYe86d3gA "JavaScript (Node.js) – Try It Online")
The underlying algorithm is the same as in [my answer to the twin challenge](https://codegolf.stackexchange.com/a/249239/58563).
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 55 bytes
```
ＷＳ⊞υι⮌⊟ΦＥ⁷ＥＥυ⁻⁺⌈ＥυΣ⁺ψνκμ∨⁺⎇﹪λ³ωFizz⎇﹪λ⁵ωBuzzＩλ⬤ι⁼№ιλ№υλ
```
[Try it online!](https://tio.run/##ZU/NasMwDL7nKURPCrinUTroaS0N7BAW1r2A6cxiqtipbbVrX96Tk/Y0gazvDwkfex2OXlPO196SAXx3I6dDCtb9YF1Dx7FHVmDrTdWJmPDTXEyIBjs/YmMpmYCtHnGtoIzSEm@t44gdydPqXzvw8HQOAif9psDVUgpO0kMBH2G2vkxwOtyw9d9MHknBi7hXBYvG3u8Lwf8Tq0diyyUhZKdjQpovvBGhVbA/s6aIO8/yD@FUYhPhQuba5FyuVGVR9TqPdTVJeXmhPw "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
ＷＳ⊞υι
```
Input the shuffled range.
```
⌈ＥυΣ⁺ψν
```
Calculate the largest integer in the range.
```
Ｅυ⁻⁺...κμ
```
Calculate a descending range of integers starting with that integer, but also offset by the outer loop index (see below).
```
Ｅ...∨⁺⎇﹪λ³ωFizz⎇﹪λ⁵ωBuzzＩλ
```
Calculate the FizzBuzz output for that range.
```
⮌⊟ΦＥ⁷...⬤ι⁼№ιλ№υλ
```
Calculate 7 ranges sliding up by 1 each time, and output one which matches the input, reversing it to put it back into order. (7 is needed for the edge case of `Buzz Fizz`.)
37 bytes for a boring numeric version:
```
Ｉ⮌⊟ΦＥ⁷ＥＥθ⁻⁺⌈θκμ∨±⁺¬﹪λ³⊗¬﹪λ⁵λ⬤ι⁼№ιλ№θλ
```
[Try it online!](https://tio.run/##XU49C8IwFPwrGV8hGVREwUmqbq3FtXSIbdDga9N8Ff99TJrNg7t7j7vh@jc3veIYQmPk5KDk1sFDLMJYAY2a4SbRCQMVn@FASbJEHU85eQsNRqn4V45@BF1Q8okciyh3A7V4cSdyp1YOKjV4VICU7FLjovwTxfAX7YsESnDVMyJISq7ac7RQKh83yhRSkh@dmytOIbQt21DCtpQcs8XRbNN1gS34Aw "Charcoal – Try It Online") Link is to verbose version of code. Uses `-1` for Fizz, `-2` for Buzz and `-3` for Fizzbuzz.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 28 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
∞εD35SÖƶ(O‚0Kθ}Ig„üÿ.V.Δ{I{Q
```
Not too happy about this.. I have the feeling this can be a lot shorter.. :/
[Try it online](https://tio.run/##yy9OTMpM/f//Uce8c1tdjE2DD087tk3D/1HDLAPvcztqPdMfNcw7vOfwfr0wvXNTqj2rA///jzbR0TUEIyMdo1gA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeWhlf8fdcw7t9XF2DT48LRj2zT8HzXMMvA@t6P20Lr0Rw3zDu85vF8vTO/clOpD66oD/9fq/I@ONtHRNQQjIx2jWJ1oQx0jEA8oCuJBWTqGOlAeRKGhIZRnpGMBIsyB4iARIwhtZKljDJQ0BjEtwFqMdYwsgTwLHXMwCRQyB1kQCwA).
**Explanation:**
```
∞               # Push the infinite positive list: [1,2,3,...]
 ε              # Map each value to:
  D             #  Duplicate the current value
   35S          #  Push pair [3,5]
      Ö         #  Check if the value is divisible by 3 and/or 5
       ƶ        #  Multiply the check by their 1-based index
        (       #  Negate them
         O      #  Sum them (-1 if only divisible by 3; -2 if only 5; -3 if both;
                #  0 if neither)
          ‚     #  Pair it with the current value
           0K   #  Remove all 0s
             θ  #  Pop and keep the last value
 }              # Close the map
  Ig            # Push the length of the input-list
    „üÿ         # Push string "ü<length>"
       .V       # Evaluate and execute it as 05AB1E code,
                # `ün` created overlapping lists of size `n`
         .Δ     # Then find the first which is truthy for:
           {    #  If it's sorted
              Q #  is equal to
            I{  #  the sorted input-list
```
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 149 bytes
```
lambda a,e=enumerate:{p for p in permutations(a)if all(j in(l:=k+i-n,-(l%3<1)-2*(l%5<1))for k,j in e(p)for n,i in e(p)if i>0)}
from itertools import*
```
[Try it online!](https://tio.run/##fVHBTuMwEL37K@aCYoNT0XRRabXhsBJc97I34GCWCTV1YstxBAXx7d2ZpKHtCpGD8@a9N@M3SdiklW9mlyFuq/Ju60z98GjAaCyx6WqMJuHyPUDlIwSwDQSMdZdMsr5ppVG2AuOcfCZJumW5PrN5o3PpTmY/pyovTgldEFLcv9ZsA5ShLxttx5Km2Ktz9SGq6GuwCWPy3rVg6@BjOt1GrMr37Ma@vWXLfKoh@9X1sCDI7K6cfYiXlXUIf2KHSwGQ4oZfQPcEDb5LUDLsklSTNjibZAb5FWRqNEH/lHBrmyQpR62AsxGY2PbRPlGHAnQtAkW6Zf6@/zSMeBkaMQ6maOq@nxsiT6skiYpvwte/GBJc/765jtHHIeFDRLPe0m60E6@k4YcG3osDfkGLo0r3lu@tw7lzT9l7zAwOcUhejmA@iNw0EINr3lv2HWIvshVtWmGEF7MRxULDbHfFuBVzY82qKD6H7elisU/K@mGToHrOMufoi8Mwo3DE0b/6f4F/ "Python 3.8 (pre-release) – Try It Online")
Uses `-1` for `Fizz`, `-2` for `Buzz` and `-3` for `FizzBuzz`.
Returns all possible options.
The idea is to try all permutations and then, for each permutation, find the first integer in the list and check if the rest of the list agrees with that one.
[Answer]
# Python3, 276 bytes:
```
def v(r,l,k=[]):
 if any([r,l])==0:yield k;return
 for i,a in enumerate(l):
  if a==r[0]or(type(a)==str and r[0]%{'Fizz':3,'Buzz':5,'FizzBuzz':15}[a]==0):yield from v(r[1:],l[:i]+l[i+1:],k+[a])
def f(l):
 c=0
 while(c:=c+1):
  if(V:=next(v([*range(c,c+len(l))],l),0)):return V
```
[Try it online!](https://tio.run/##bY@xbsIwEIb3PMUtFXZzQwJFgCsvHfoILJaHKDhgxTiRa2hD1WdPbRJoEUw@3//9d/@1nd81drZsXd9vVAVH4tBgzYWkLAFdQWE7IkJPUs4z1mllNlC/OuUPziZQNQ40FqAtKHvYK1d4RUy0nr2cO5HJxhHftYoUYcSHd2HkBmL/6Xvyrk@nCZvh5O0QizmeO8Mnn/@IQoatdFxbuWYfA4qcSTSCaZkaodP4q9OA0iReUA37S54l8LnTRpGS8TLNx1BkzbhVX54ciXh2hd0GHcvUKBt8NMylmFHKhgNh3bdOW08qInKEKcKQGOEllOeYktLkytypCNH2kLm@FzB/jI3y8q9cXMy3hlF9IE1XCLN8lO5TT5f/0lyRkHt1gwVqERr9Lw)
]