g | x | w | all
Bytes Lang Time Link
118Go240721T025705Zbigyihsu
035CJam230213T174851ZHelen
01205AB1E210831T065331ZKevin Cr
122Python 3210829T120438ZOliveIsA
317CSASM v2.5.1210826T183439Zabsolute
109Java JDK210813T090703ZOlivier
094Scala210813T185550Zuser
075Bash210811T185631Zplentyof
063Python 2210810T041505ZWasif
048J210811T055012ZJonah
064R210811T073411Zpajonk
069Haskell210810T160358Zlynn
065Python 3210810T122113ZJitse
008Jelly210810T031155Zcaird co
059Julia 0.7210810T125757ZMarcMush
029K ngn/k210810T101329ZRazetime
019Charcoal210810T100911ZNeil
056Perl 5210810T095324ZKjetil S
014Japt R210810T091916ZShaggy
059JavaScript V8210810T074642ZArnauld
008Vyxal210810T031118Zlyxal

Go, 118 bytes

import(."fmt")
func f(m map[int]string,n int)(s string){for k,v:=range m{if n%k<1{s+=v}}
if s==""{s=Sprint(n)}
return}

Attempt This Online!

Input is a mapping of a factor to its string, and a number to get the FizzBuzz string of it. Returns the FizzBuzzed string.

CJam, 36 35 bytes

q~{)1${\_@~;%!},_@aa?{1=}%:+oNo}%];

Try it online!

Explanation

q~                                       read the factor array and upper bound in one go
  {)                            }%       for each i from 1 to n
    1${       },                          get all the input factors i contains
       \_@~;%!                              by checking i mod f = 0 for each input factor f
                _@aa?                     if there *are* factors in i,
                                            keep the relevant factors [[f, "Foo"], ...]
                                            otherwise keep the number in the form [[i]]
                     {1=}%                keep the 2nd element in each subarray
                                            this is the texts ["Foo","Bar","Baz",...]
                                            or just [i] if there were no input factors
                          :+              sum them all (concatenating texts together)
                            oNo           print in the required format
                                 ];       clean up

(-1 byte) dropping ,: CJam automatically turns a number n into [0, n) when you map using %


Possible Changes

(-2 bytes) using p instead of oNo but this prints "Foo"/"BarBaz" instead of Foo/BarBaz
(-2 bytes) using n instead of oNo but this feature isn't in any releases (and most likely will never be)

05AB1E, 12 bytes

∞ε¹ÖÏJy‚õKн,

Integers and strings as two separated input-lists.
Outputs the infinite sequence.

Try it online.

Explanation:

∞            # Push an infinite positive list: [1,2,3,...]
 ε           # Foreach `y` over these integers:
  ¹Ö         #  Check for each integer in the first input-list whether it divides the
             #  current integer
    Ï        #  Get the strings of the second (implicit) input-list at the truthy indices
     J       #  Join this list of strings (it's now "" if none were divisible)
      y‚     #  Pair it with the current integer `y`
        õK   #  Remove empty strings from this pair
          н  #  Pop and leave the first item
           , #  And print it with trailing newline
           

Python 3, 122 bytes

exec("g="+input())
n=1
while 1:
 b=1
 for k,v in g:
  if n%k<1:
   print(v,end='')
   b=0
 print(n)if b else print()
 n+=1

Input:

((4, "Foo"), (7, "Bar"), (9, "Baz"))

Try it online!

Fairly obvious way of going about the challenge. Using a tuple of tuples saves 1 byte over a dict. Looking at the other python submissions, I realize I missed a lot of optimizations. Lessons to bring to the next code golf, I hope.

CSASM v2.5.1, 317 bytes

func a:
.local a : i32
push 1
add
pop $3
pop $2
dup
len
pop $4
pop $1
lda 1
.lbl a
push 0
pop a
push -1
pop $5
push $a
push 1
sub
brfalse c
.lbl b
inc $5
push $5
push $4
sub
brfalse c
push $a
push $1
ldelem $5
rem
brtrue b
push 1
pop a
push $2
ldelem $5
print
br b
.lbl c
push a
brtrue d
push $a
print
.lbl d
push '\n'
print
inc $a
push $a
push $3
sub
brtrue a
ret
end

A function named a which expects an ~arr:i32 for the values, an ~arr:str for the names and an i32 representing \$n\$ on the stack, pushed in that order specifically.

Explanation:

func a:
    ; Used as the flag for if a string was printed
    .local a : i32
    
    ; stack: [ values array, strings array, amount to print ]
    push 1
    add
    pop $3
    pop $2
    ; Duplicate "values array", get its length and store it into $4
    dup
    len
    pop $4
    pop $1

    ; $1 = values, $2 = strings, $3 = final number

    ; Initialize $a to 1
    lda 1

    .lbl a
        ; Reset the "string printed" flag
        push 0
        pop a
        
        ; Reset the "numbers array" iteration
        push -1
        pop $5

        ; If $a == 1, skip to the end
        push $a
        push 1
        sub
        brfalse c

        .lbl b
            inc $5
            push $5
            push $4
            sub
            brfalse c

            ; Loop through each value in the numbers array and check if a$ % them is zero
            ; If they are, print that string
            push $a
            push $1
            ldelem $5
            rem
            brtrue b
            
            ; Modulo was zero
            push 1
            pop a

            push $2
            ldelem $5
            print
            br b
    .lbl c
        push a
        brtrue d
        ; Print the current number
        push $a
        print
    .lbl d
        ; Print the newline
        push '\n'
        print

        ; Loop while $a != $3
        inc $a
        push $a
        push $3
        sub
        brtrue a
    ret
end

Sample Program:

func main:
    push $i32:[3,5]
    
    push 2
    newarr str
    pop $a

    push $a
    push "Fizz"
    stelem 0
    push $a
    push "Buzz"
    stelem 1

    push $a
    push 30

    call a

    ret
end

; "func a" would be defined here

Java (JDK), 109 bytes

l->{for(int i=1;;i++){var s="";for(var e:l)if(i%e.getKey()<1)s+=e.getValue();System.out.println(s==""?i:s);}}

Try it online!

Notes

The s=="" works here because of the constants pool: the two references to the empty string are actually one reference and have the same address in memory. s==new String("") wouldn't have worked for instance.

Credits

Scala, 94 bytes

b=>1 to _ map(x=>println(Seq(b.collect{case(k,s)if x%k<1=>s},Seq(x))maxBy(_.size)mkString ""))

Try it online!

Outputs the first n lines of the sequence.

b => //A Map with the keys being divisors (4, 7, 9) and the values being strings ("Foo", "Fizz", etc.)
1 to _ //Make a range to n
 map(x=> //For each x in the range, output either "x" or a string made from its divisors
  println( //Print with newline
   Seq(   //Make a Seq with the two alternatives ^
    b.collect{ //The Fizz, Buzz, FizzBuzz alternative
     case(k,s) //For every divisor k and its accompanying string s,
      if x%k<1 //If k divides x
      =>s},    //Add s to this alternative
    Seq(x)  //The second alternative is just the number itself
   ) maxBy(_.size) //Find the alternative with more elements (if both have 1, the first is chosen)
    mkString ""  //Join into a single string
  )
 )

Bash, 100 80 75 bytes

-20 bytes thanks to @Dude coinheringaahing

-5 bytes and extra readability thanks to @Jonah

for((i=1;;i++));{
o=
for a;{((0==i%${a% *}))&&o=$o${a#* };}
echo ${o:-$i}
}

Try it online!

Takes arguments as strings in the form '$num $str' and uses variable expansion to split them out into their component parts. Outputs infinitely.

I'm pretty sure this one has lots of potential for further golfing, but I'll take an even 100 for my first submission.

Python 2, 63 bytes

def f(k,i=1):
 print''.join(y*(i%x<1)for x,y in k)or i;f(k,i+1)

Attempt This Online!

-1 bytes thanks to @dingledooper

-3 bytes thanks to @pxeger

J, 48 bytes

1 :'(|:@([:(,0=+/)0=u|/]);@#"1(,"#:<@":"+))1+i.'

Try it online!

This was bizarrely difficult to golf in J.

R, 76 64 bytes

-12 bytes thanks to @Dominic

function(N,S)repeat{F=F+1;cat(F[all(k<-F%%N)],S[!k],"
",sep="")}

Try it online!

Takes vectors of Numbers and corresponding Strings.

Outputs infinitely.

Haskell, 69 bytes

[]%n=show n
x%_=x>>=id
f a=unlines[[y|(x,y)<-a,mod i x<1]%i|i<-[1..]]

Try it online!

f [(3, "Fizz"), (5, "Buzz"), (10, "Boom")] is an infinite string with newlines in it.

Python 3, 65 bytes

f=lambda a,n=1:print(''.join(j*(n%i<1)for i,j in a)or n)+f(a,n+1)

Try it online!

-1 byte thanks to MarcMush

Jelly, 8 bytes

⁴ḍTị⁵ȯ)Y

Try it online!

Full program that takes \$n\$, the list of numbers \$L\$ and the list of strings \$S\$ as command line argument, and returns a newline separated string

How it works

⁴ḍTị⁵ȯ)Y - Main link. Takes n on the left, L as ⁴ and S as ⁵
      )  - Over each integer 1 ≤ i ≤ n:
⁴ḍ       -   Map each element in L to 1 if i is divisible by it, else 0
  T      -   Indices of 1s
   ị⁵    -   Select the elements of S at those indices
     ȯ   -   If this is the empty list, replace it with i
       Y - Join on newlines

Julia 0.7, 59 bytes

N\d=1:N.|>n->println((a=prod(p->p[2]^(n%p[1]<1),d))>""?a:n)

Try it online!

K (ngn/k), 29 bytes

{{$[a:&~x!'y;,/a;y]}[x]'1+!y}

Try it online!

Takes a dict with (string, number) pairs.

Explanation

{{$[a:&~x!'y;,/a;y]}[x]'1+!y}
                        1+!y  range 1..y
                       '      for each number
                    [x]       with x as constant first argument:
 {$[              ]}           if:
        x!'y                    the values of x mod y
       ~                        logical NOTed
      &                         filter out keys which have truthy values
    a:                          store in a
            ;,/a                return a if non-empty
                ;y              otherwise return number y

Charcoal, 19 bytes

Eθ∨⭆η⎇﹪⊕ι§λ⁰ω§λ¹I⊕ι

Try it online! Link is to verbose version of code. Prints the first n terms. Explanation:

 θ                  Input `n`
E                   Map over implicit range
    η               Input list of pairs
   ⭆                Map over pairs and join
        ι           Outer index
       ⊕            Incremented
      ﹪             Modulo
         §λ⁰        First element of pair
     ⎇              If non-zero then
            ω       Empty string
             §λ¹    Else second element of pair
  ∨                 Logical Or
                  ι Current index
                 ⊕  Incremented
                I   Cast to string
                    Implicitly print on separate lines

Note: Using trunk Charcoal (not available on TIO) this would be only 15 bytes:

Eθ∨⭆η⎇﹪⊕ιμωλI⊕ι

Explanation: Takes the input as a dict, which means that iterating over it populates the loop variables directly without having to index into the pairs.

Perl 5, 56 bytes

sub{say join('',map$.%$$_[0]?'':$$_[1],@_)||$.while++$.}

Try it online!

Japt -R, 14 bytes

õ@VËÌpXvDÎìªX

Try it

õ@VËÌpXvDÎìªX     :Implicit input of integer U & array V
õ                  :Range [1,U]
 @                 :Map each X
  VË               :  Map each D in V
    Ì              :    Last element
     p             :    Repeat
      Xv           :      Is X divisible by
        DÎ         :      First element of D
          Ã        :  End map
           ¬       :  Join
            ªX     :  Logical OR with X
                   :Implicit output joined with newlines

JavaScript (V8), 59 bytes

Prints the sequence forever.

a=>{for(k=0;++k;)print(a.map(([m,s])=>k%m?'':s).join``||k)}

Try it online!

Vyxal, 8 bytes

ƛ¹Ḋ⁰*∑∴,

Try it Online!

Since y'all complaining about flags, I'll give you a tie with jelly.

Expects Limit, Divisors, Strings

Explained

ƛ¹Ḋ⁰*∑∴,
ƛ        # for each n in the range [1, L]:
 ¹Ḋ      #     Push n % D == 0 (epicly vectorised)
   ⁰*    #     Push ^ * S (which is vectorised python string multiplication) 
     ∑∴  #     Push max(sum(^), n)
       , #     and print ^ with a newline

This would be 7 with the j flag