Skip to main content
2 of 10
fixed typo
Jo King
  • 47.5k
  • 5
  • 125
  • 186

Brain-Flak, 474 bytes

(((()()()()()){}){}){({}<(()()())>[((((()))))])}{}{({}<>)<>({}<>)<>({}()<>)<>}<>{}{}{([({}[()])]{(({}[()]))<{(<{}>)(((((((((()()()()){}){}){}()){})[(()()()()){}]){}())(()()){}())){({}<>)<>}}{}({}[()]){{}<>(((((((((()()()){}()){}()){}){}()){}))[((()()()()){}){}()])[(((()()()()){}){}()){}()])(<>)}>}{}()){({}[](<>))(<>)((()()()()()){}){(({}<({}())>)){({}[()])<>}{}}{}<>([{}()]{}((((()()()){}){}){}){}<>)<>({}[()]){({}((((()()()){}){}){}){}<>)(<>)}}{}<>((()()()()()){})<>}<>{}

Try it online!

Gosh, it's nice to finally check this off my to-do list.

###Explanation:

Brain-Flak is obviously not very good at getting the modulo of numbers, so I bypassed this by pushing all the elements first.

(((()()()()()){}){}) Push 20
{ Loop 20 times
    ({}
    <(()()())>    Push a 3 to represent a Buzz
    [((((()))))] Push 4 1s
    ) And decrement loop counter
}{} Pop the excess 0
{ Loop over the list of numbers
    ({}<>)<>({}<>)<> Transfer two of the elements to the other stack
    ({}()<>)<>       And add one to the last one
}<>{}{} Pop the excess two elements

Now 1 represents normal numbers, 2 representa Buzz, 3s represents FizzBuzz. Initially I just pushed the values that repeat every 15 numbers 7 times and popped the excess 5, but this way turned to be slightly shorter.

{ Loop over each element
    ([({}[()])] Subtract one from the current element
    { Fizz and/or Buzz
        (({}[()])) Subtract 1 again
        <
        { Push Buzz
            (<{}>)(((((((((()()()()){}){}){}()){})[(()()()()){}]){}())(()()){}())){({}<>)<>}
        }{}
        ({}[()]) Subtract 1 again
        { Push Fizz
            {}<>(((((((((()()()){}()){}()){}){}()){}))[((()()()()){}){}()])[(((()()()()){}){}()){}()])(<>)
        }
        >
    }{}()) Push 1 if it's a number
    {
        ({}[](<>)) Push length of list to other stack
        (<>)((()()()()()){}) Push 10
        Div/mod algorithm
        {(({}<({}())>)){({}[()])<>}{}}{}<>([{}()]{}((((()()()){}){}){}){}<>)<>
        Pushes n%10+48 to output stack and n/10+1 to the list stack
        ({}[()]) Subtract one from div
        { If div is not 0
            ({}((((()()()){}){}){}){}<>) Add 48 to it and push it to other stack
            (<>) Push 0
        }
    }{} Pop excess 0
    <>((()()()()()){})<> Push newline to other stack
}<>{} Pop extra newline

Jo King
  • 47.5k
  • 5
  • 125
  • 186