36

# 例子

```嘶嘶声

```

``````2
fizz
4
``````

```嗡嗡声

```

``````buzz
fizz
7
``````

```

```

``````13
14
fizzbuzz
16
17
``````

``````1
``````

```嘶嘶声

```

``````zzubzzif
``````

```

```

``````zzubzzif
``````

17

# Java，205个字节

``s->{o:for(int i=0,j,h=s.length;++i<16;){for(j=h;j-->0;)if(s[j].contains("fizz")^(i+j)%3<1||s[j].contains("buzz")^(i+j)%5<1)continue o;String z=i+"";for(j=1;j<h;)z+="\n"+(i+j++);return z;}return"zzubzzif";}``

``````public class C {

static final java.util.function.Function<String[], String> f = s -> {
o:
for (int i = 0, j, h = s.length; ++i < 16;) {
for (j = h; j --> 0;) {
if (s[j].contains("fizz") ^ (i + j) % 3 < 1 ||
s[j].contains("buzz") ^ (i + j) % 5 < 1) {
continue o;
}
}
String z = i + "";
for (j = 1; j < h;) {
z += "\n" + (i + j++);
}
return z;
}
return "zzubzzif";
};

public static void main(String[] args) {
System.out.print(f.apply(new String[]{"fizz", "", "buzz"}));
}
}``````

1
s / fizz / f，s / buzz / b
djechlin

10

# C＃，212个字节

``string[]R(string[]a){for(int i,l=a.Length,n=0;n++<15;){for(i=l;i-->0;)if(((n+i)%3<1?"fizz":"")+((n+i)%5<1?"buzz":"")!=a[i])goto z;for(i=l;i-->0;)a[i]=a[i]==""?""+(n+i):a[i];return a;z:;}return new[]{"zzubzzif"};}``

``````string[]R(string[]a){
for(int i,l=a.Length,n=0;n++<15;){
for(i=l;i-->0;)
if(((n+i)%3<1?"fizz":"")+((n+i)%5<1?"buzz":"")!=a[i])
goto z;
for(i=l;i-->0;)
a[i]=a[i]==""?""+(n+i):a[i];
return a;
z:;
}
return new[]{"zzubzzif"};
}``````

C＃没有`break`关键字吗？

2
@cat可以，但是会`goto`跳出内部循环并跳过外部循环的其余逻辑。
Hand-E-Food

sergiol

4

# CJam，72个字节

``````"zzubzzif":MaqN/:Q,_F+{)_[Z5]f%:!MW%4/.*s\e|}%ew{:sQ1\$A,sff&:s.e|=}=N*o;
``````

### 怎么运行的

``````"zzubzzif" e# Push that string.
:Ma        e# Save it in M and wrap in in an array.
qN/:Q      e# Split the input into lines and save in Q.
,_F+       e# Count the lines and add 15 to a copy of the result.
{          e# For each integer I between 0 and lines+14:
)_       e#   Increment I and push a copy.
[Z5]     e#   Push [3 5].
f%       e#   Map % to push [(I+1)%3 (I+1)%5].
:!       e#   Apply logical NOT to each remainder.
MW%4/    e#   Push ["fizz" "buzz"].
.*       e#   Vectorized string repetition.
s\       e#   Flatten the result and swap it with I+1.
e|       e#   Logical OR; if `s' pushed an empty string, replace it with I+1.
}%         e#
ew         e# Push the overlapping slices of length "lines".
{          e# Find; for each slice:
:s       e#   Cast its elements to string (e.g., 1 -> "1").
Q1\$      e#   Push the input and a copy of the slice.
A,s      e#   Push "0123456789".
ff&      e#   Intersect the slice's strings' characters with that string.
:s       e#   Cast the results to string. This replaces "fizz", "buzz"
e#   and "fizzbuzz" with empty strings.
.e|      e#   Vectorized logical OR; replace empty lines of the input
e#   with the corresponding elements of the slice.
=        e#   Check the original slice and the modified input for equality.
}=         e# Push the first match or nothing.
e# We now have ["zzubzzif"] and possibly a solution on the stack.
N*         e# Join the topmost stack item, separating by linefeeds.
o          e# Print the result.
;          e# Discard the remaining stack item, if any.
``````

1

# Perl，140个字节

``\$f=fizz;\$b=buzz;@a=<>;@x=map{s!\d!!gr.\$/}@s=map{\$_%15?\$_%3?\$_%5?\$_:\$b:\$f:\$f.\$b}(++\$c..\$c+\$#a)while\$c<15&&"@x"ne"@a";print\$c<15?"@s":zzubzzif``

1. `@a` 是输入线的数组
2. `while`循环内部
3. `@s` 具有生成的嘶嘶声序列
4. `@x`与相同，`@s`但用空字符串替换数字，并在每个元素上添加新行（以与匹配`@a`
5. `\$c` 是从1到15的计数器
6. 循环运行直到`@x`变得与输入相同`@a`
7. 在循环外部，`@s`根据是否`\$c`在极限范围内，输出为或zzufzzib

1

# Python，176字节

``````def f(a):l=len(a);g=lambda n:'fizz'*(n%3<1)+'buzz'*(n%5<1);r=range;return next(([g(x)or x for x in r(i%15,i%15+l)]for i in r(1,16)if all(g(i+x)==a[x]for x in r(l))),g(0)[::-1])
``````

``````def f(a):
l = len(a)
g = lambda n: 'fizz'*(n%3<1)+'buzz'*(n%5<1)
r = range
return next(
(
[g(x) or x for x in r(i % 15,i % 15 + l)]
for i in r(1,16)
if all(
g(i + x) == a[x] for x in r(l)
)
),
g(0)[::-1]
)
``````

1

Todd

arcyqwerty 2015年

1
python 2允许在没有歧义的情况下在关键字之前删除一些空格：例如`..] for` 可以写成`..]for`。应用这个技巧，您将获得177个字符

Todd 2015年