A twin of this.

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". For example, FizzBuzz from 1 to 10 is 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz.

Your challenge is to, given a list of Fizzes, Buzzes, FizzBuzzes and a value representing an integer (I'm going to use Int), determine if it can be arranged into valid FizzBuzz.

For example, Int, Fizz, Fizz, Buzz can be arranged into Fizz, Buzz, Int, Fizz (for example 9,10,11,12) which is valid. But Buzz, Fizz, Buzz cannot, as the two Buzz need to be five values apart.

You may choose any four values to represent Fizz, Buzz, FizzBuzz and Int.

This is , shortest wins!


Int, Int, Fizz
Fizz, Int, Fizz, Buzz
Fizz, Fizz, Fizz, Int, Int, Int, Buzz
Buzz, Int, Int, Int, Fizz, FizzBuzz
FizzBuzz, Int, Int, Int, Int


Buzz, FizzBuzz, Fizz
Buzz, Fizz, Buzz
Int, Int, Int
Fizz, Int, Fizz
FizzBuzz, Int, Int, Buzz, Fizz
Int, Int, Fizz, Fizz, Fizz, Buzz, Buzz
  • \$\begingroup\$ Suggested test case: Int, Int, Fizz, Fizz, Fizz, Buzz, Buzz. \$\endgroup\$
    – Nitrodon
    Commented Jun 29, 2022 at 14:05
  • \$\begingroup\$ @Nitrodon Spent a while figuring out whether that worked. Thanks! \$\endgroup\$
    – emanresu A
    Commented Jun 29, 2022 at 19:48

5 Answers 5


Vyxal, 13 bytes


Try it Online! Super slow. Uses [0,0] for Int, [1,0] for Fizz, [0,1] for Buzz, and [1,1] for FizzBuzz.

Test cases, using 14 instead of 26 to make it faster.

L₄+           # Length of input + 26 (14 would be enough, but 26 is one byte)
   v₍₃₅       # For each in range [1, that], calculate [n % 3 == 0, n % 5 == 0]
       ÞS     # All sublists
           ↔  # Keep only lists that are in...
         ?Ṗ   # The permutations of the input
            ḃ # Is this truthy? (does it have at least one element?)
  • \$\begingroup\$ Technically I could make this one byte shorter with ten power instead of plus 26, but that would make it so slow. \$\endgroup\$
    – naffetS
    Commented Jun 29, 2022 at 20:30

JavaScript (ES6), 72 bytes

Expects 0 for Int, 1 for Fizz, 2 for Buzz, 3 for FizzBuzz. Returns 0 or 1.

This is the same algorithm as in my answer to the other challenge.


Try it online!


f = (             // f is a recursive function taking:
  a,              //   a[] = input array
  i =             //   i = index in the FizzBuzz sequence
  k = 15          //   k = counter
) =>              //
  k-- &&          // decrement k; abort if it was 0
  a.sort()        // normalize a[] by sorting it in lexicographical order
  .map(_ =>       // for each value in a[]:
    ++i % 3 < 1 | //   generate the FizzBuzz sequence,
    2 * !(i % 5)  //   starting at i + 1
  )               // end of map()
  .sort()         // normalize this new array
  + '' == a |     // coerce it to a string and compare it with a[]
  f(a, k)         // recursive call with i set to the new value of k
  • \$\begingroup\$ 70 \$\endgroup\$
    – l4m2
    Commented Jan 7, 2023 at 13:25

05AB1E, 15 bytes


Inputs as Int=[0,0]; Fizz=[1,0]; Buzz=[0,1]; FizzBuzz=[1,1].
Too slow to output anything on TIO..

(Don't) try it online.
Try a modified version online, with: hard-coded 26 instead of ; find_first instead of ε...}; outputs the first found list, or -1 if falsey (which still times out for falsey or too long test cases.. -_-).


g             # Push the input-length
 °            # 10 to the power this length
  L           # Pop and push a list in the range [1,10**length]
   35S        # Push pair [3,5]
      δ       # Map over the [1,10**length]-list, with [3,5] as argument for each:
       Ö      #  Check if the current integer is divible by [3,5]
        Π    # Get all sublists of this
         ε    # Map over each sublist:
          œ   #  Get all permutations of it
           €  #  Map over each permutation:
            Q #   Check if it's equal to the (implicit) input-list
         }    # Close the sublists-map
          à   # Flattened maximum to check if any inner permutation was truthy
              # (which is output implicitly as result)

Python3, 213 bytes:

def v(r,l,k=[]):
 if not r:yield k
 for i,a in enumerate(l):
  if r[0]%(a|1)<1:yield from v(r[1:],l[:i]+l[i+1:],k+[a])
def f(l,c=0):
 while(c:=c+1)<sum(i**2for i in l):
  if next(v(range(c,c+len(l)),l),0):return 1

Try it online!

  • \$\begingroup\$ @Steffan Updated \$\endgroup\$
    – Ajax1234
    Commented Jun 29, 2022 at 2:16
  • \$\begingroup\$ 216 with looser I/O plus other golfs \$\endgroup\$
    – naffetS
    Commented Jun 29, 2022 at 2:34
  • \$\begingroup\$ Down to 206 by outputting by error/no error: (requires Python 3.9) ato.pxeger.com/… \$\endgroup\$
    – pxeger
    Commented Jun 29, 2022 at 6:44
  • \$\begingroup\$ Off of pxegers, you can also remoev the V:= \$\endgroup\$
    – naffetS
    Commented Jun 29, 2022 at 20:32
  • \$\begingroup\$ @Steffan Thanks, updated \$\endgroup\$
    – Ajax1234
    Commented Jun 29, 2022 at 20:37

Python 3.8 (pre-release), 109 bytes

lambda n:sorted(n)in[sorted([max(a for a in[1,3,5,15]if j%a<1)for j in range(i,i+len(n))])for i in range(15)]

Try it online!

Takes Int as 1, Fizz as 3, Buzz as 5, FizzBuzz as 15.


One key observation is that, if we replace all the integers with a single value Int, then the FizzBuzz sequence has a period of 15:


It is rather easy to prove that this is in fact the case. Hint: start by placing the multiples of 3 and 5.

What we can therefore do is focus on the first 15 numbers. From each of these numbers, we can make a little subsequence of numbers whose length is the same as the length of the input, and determine whether the sorted values (where the integers become Int) are the same as the input.

How do we do this? We use a cool trick whereby we get the maximum number out of [1, 3, 5, 15] such that the current number is divisible by that number. Since Int is 1, all numbers that are not multiples of 3 or 5 correspond to Int. Multiples of 3 but not of 5 correspond to Fizz, etc. We can eventually generate this sequence of 1s, 3s, 5s and 15s.

Sorting the input and comparing it against the sorted values of the subsequence will reveal whether the input is shuffled FizzBuzz or not.

Yay! First answer in... what, two months?

  • \$\begingroup\$ Why 3.8 and why prerelease? \$\endgroup\$ Commented Jun 29, 2022 at 15:26
  • \$\begingroup\$ @TheShwarma It's a TIO thing \$\endgroup\$
    – ophact
    Commented Jun 29, 2022 at 16:23
  • \$\begingroup\$ but what's TIO? \$\endgroup\$ Commented Jun 30, 2022 at 10:38
  • \$\begingroup\$ @TheShwarma Try It Online, the website that a lot of us use to run code. It's convenient because we can use just about any major programming language on it without any local installation, and we can share a link to our code as well. Unfortunately, TIO hasn't updated Python to the latest version. It's still stuck on the prerelease version of 3.8. \$\endgroup\$
    – ophact
    Commented Jun 30, 2022 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.