11
\$\begingroup\$

Challenge

Input:

An integer \$b\$ between 2 and 62 (inclusive).

Output:

Count from \1ドル\$ to the equivalent of \5000ドル_{10}\$ in base \$b\$, using any reasonable representation for the digits.

However:

  • If the number is divisible by \$\lfloor b÷2+1\rfloor\$ (rounded down, e.g base 7 would be 7/2=3.5, 3.5+1=4.5, rounded to 4), then output 'Fizz' instead of the number.

  • If the number is divisible by \$\lceil b÷3+3\rceil\$ (rounded up, e.g 11/3=3.666, 3.666+3=6.666, rounded to 7), then output 'Buzz'.

  • As you can probably guess, if your number is divisible by both, output 'Fizzbuzz'.

Examples

Using [0-9], [A-Z] and [a-z] as the digits

(I've only included the first 10 values to keep the examples short - normally there'd by 4990 more items in each sequence)

Input: 10 (so 'Fizz' = 6 and 'Buzz' = 7)

Output: 1, 2, 3, 4, 5, Fizz, Buzz, 8, 9, 10

Input: 2 (so 'Fizz' = 2 and 'Buzz' = 4)

Output: 1, Fizz, 11, Fizzbuzz, 101, Fizz, 111, Fizzbuzz, 1001, Fizz

(I've included the first 50 values of the following to better show how they work)

Input: 55 (so 'Fizz' = \28ドル_{10}\$ = \$s_{55}\$ and 'Buzz' = \22ドル_{10}\$ = \$m_{55}\$)

Output: 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, g, h, i, j, k, l, Buzz, n, o, p, q, r, Fizz, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N

Rules

  • Standard loopholes are forbidden
  • This is Code Golf, so shortest answer in bytes wins
  • Input and output can be through console, or function arguments/returns
  • Leading/trailing white space is fine, as are empty lines
  • Spaces between 'Fizz' and 'Buzz' are disallowed
  • Any capitalization variant of 'Fizz'/'Buzz'/'Fizzbuzz' is fine.
  • Outputs should be separated by newlines.
  • If you return a array of base 10 'digits' instead of representing them with characters, then they have to be in the correct order!
Toby Speight
6,9941 gold badge30 silver badges43 bronze badges
asked Feb 22, 2019 at 15:37
\$\endgroup\$
11
  • 2
    \$\begingroup\$ I don't really mind. If you want to use emoji instead of digits, I still don't mind. It's the base that matters, not the representation. \$\endgroup\$ Commented Feb 22, 2019 at 21:42
  • 2
    \$\begingroup\$ Ok, clarified now. \$\endgroup\$ Commented Feb 22, 2019 at 22:00
  • 6
    \$\begingroup\$ Technically, in base 36 the word buzz appears by itself at index 553391, fizz at 724463, and fizzbuzz at 1216820199599. Sadly, none of them are divisible by that base's numbers \$\endgroup\$ Commented Feb 22, 2019 at 22:36
  • 3
    \$\begingroup\$ Why isn't base 10 the original FizzBuzz?: I couldn't think of an algorithm which would both generate the original numbers in base 10, and transfer well to other bases. And I didn't want to add a special case for denary since that would just overcomplicate the question, in my opinion. \$\endgroup\$ Commented Feb 23, 2019 at 10:11
  • 3
    \$\begingroup\$ For your future challenges, please consider allowing more flexible I/O. Cumbersome I/O formats is the most upvoted topic in Things to avoid when writing challenges. \$\endgroup\$ Commented Feb 23, 2019 at 17:03

12 Answers 12

4
\$\begingroup\$

Charcoal, 40 bytes

×ばつ5φ∨+⎇%ι⊕÷θ2ωFizz⎇%ι÷+11θ3ωBuzz⍘ιθ

Try it online! Link is to verbose version of code. Explanation:

Nθ Input `b` into variable `q`
 1 Literal 1
 ...· Inclusive range to
 φ Predefined variable 1000
 ×ばつ Multiplied by
 5 Literal 5
E Map to
 ι Current value
 % Modulo
 θ Input value
 ÷ Floor divide
 2 Literal 2
 ⊕ Incremented
 ⎇ If nonzero
 ω Then predefined empty string
 Fizz Otherwise literal `Fizz`
 + Concatenated with
 ι Current value
 % Modulo
 θ Input value
 + Plus
 11 Literal 11
 ÷ Integer divided by
 3 Literal 3
 ⎇ If nonzero
 ω Then predefined empty string
 Buzz Otherwise literal `Buzz`
 ∨ Logical Or
 ι Current value
 ⍘ Converted to base
 θ Input value
 Implicitly print each result on its own line
answered Feb 23, 2019 at 1:06
\$\endgroup\$
3
\$\begingroup\$

Jelly, (削除) 42 38 34 33 29 (削除ここまで) 32 bytes

+3 to adhere to strict formatting rules

×ばつ"=%»ḟ0Fȯb@K\ð€Y

A full program which prints 5000 lines of text, each line containing a series of integers (the digits) or one of fizz, buzz, or fizzbuzz (works fine beyond base 62).

Try it online!

How?

Note that
\$\lfloor b÷2+1\rfloor\ = \lfloor b÷2\rfloor+1\$
...and
\$\lceil b÷3+3\rceil = \lceil b÷3+2\rceil+1 = \lceil (b+6)÷3\rceil+1 = \lfloor (b+8)÷3\rfloor+1\$

updating...

×ばつ"=%»ḟ0Fȯb@ð€ - Link: integer, b
5ȷ - 5*103 = 5000
 ɓ ð€ - for €ach n in [1,2,...,5000] get this f(b,n):
 8 - eight
 ; - concatenate -> [b,8]
 Ä - cumulative sums -> [b,b+8]
 2,3 - pair literal [2,3]
 : - integer division -> [b//2, (b+8)//3]
 ‘ - increment -> [b//2+1, (b+8)//3+1]
 ḍ - divides n? -> [n is fizzy?, n is buzzy?]
 ×ばつ"=%» - list of dictionary strings = ['fizz','buzz']
 " - zip with:
 ȧ - logical AND -> [0,0], ['fizz',0], [0,'buzz'],
 - or ['fizz','buzz']
 0 - zero
 ḟ - filter discard -> [], ['fizz'], ['buzz'],
 - or ['fizz','buzz']
 F - flatten -> [], ['fizz'], ['buzz'],
 - or ['fizzbuzz']
 @ - using swapped arguments:
 b - (n) to a list of digits in base (b) (say, [nb])
 ȯ - logical OR -> [nb], ['fizz'], ['buzz'],
 - or ['fizzbuzz']
answered Feb 22, 2019 at 22:23
\$\endgroup\$
4
  • \$\begingroup\$ The challenge states that output must be on seperate lines \$\endgroup\$ Commented Feb 23, 2019 at 4:02
  • \$\begingroup\$ True. While I'm fine with the representation (though it's borderline), outputting an array isn't the same as playing the game. However, if you output the array of digits on each line, I'll accept it. \$\endgroup\$ Commented Feb 23, 2019 at 10:00
  • 3
    \$\begingroup\$ @GezaKerecsenyi Updated. However, I don't understand how the representation is "borderline" - in base b the digits are in \$[0,n-1]\$. Or how outputting an array isn't "playing the game" ("Input and output can be through console, or function arguments/returns"). Using some other arbitrary output is as simple as substitution and formatting is just boilerplate and orthogonal to the core of the challenge. \$\endgroup\$ Commented Feb 23, 2019 at 16:11
  • \$\begingroup\$ A terser implementation could just take a list of the desired digits, instead of the numerical base, like this. \$\endgroup\$ Commented Feb 23, 2019 at 16:11
3
\$\begingroup\$

R, (削除) 163 (削除ここまで) 131 bytes

b=scan();for(d in 1:5e3)cat(list(d%/%b^rev(0:log(d,b))%%b,'fizz','buzz','fizzbuzz')[[1+(!d%%((b+2)%/%2))+2*!d%%((b+11)%/%3)]],'\n')

Try it online!

Thanks to @digEmAll for saving 23 bytes. I then further golfed @digEmAll’s efforts to save a further 9.

answered Feb 23, 2019 at 13:38
\$\endgroup\$
5
  • \$\begingroup\$ 140 byte I worked on this without looking at your answer, but it's too similar for another post ;) \$\endgroup\$ Commented Feb 23, 2019 at 16:40
  • \$\begingroup\$ @digEmAll thanks. I’ve further golfed your answer to get 131 bytes and given you credit; hope that’s ok. \$\endgroup\$ Commented Feb 23, 2019 at 18:15
  • \$\begingroup\$ absolutely ! ;) \$\endgroup\$ Commented Feb 23, 2019 at 18:16
  • \$\begingroup\$ BTW, if you have any discussion about golfing in R ask on this chat \$\endgroup\$ Commented Feb 23, 2019 at 19:04
  • \$\begingroup\$ Oops, didn't realize there was already an R answer, my answer might be helpful for a bit more golfing? \$\endgroup\$ Commented Feb 25, 2019 at 22:56
2
\$\begingroup\$

Python 2, 116 bytes

b=input()
i=0
exec"a=i=i+1;d=[]\nwhile a:d=[a%b]+d;a/=b\nprint'Fizz'*(i%(b/2+1)<1)+'Buzz'*(i%(~-b/3+4)<1)or d;"*5000

Try it online!

Or with 0-9a-zA-Z output:

Python 2, 143 bytes

b=input()
i=0
exec"a=i=i+1;d=''\nwhile a:d=chr(a%b+48+(a%b>9)*39-a%b/36*58)+d;a/=b\nprint'Fizz'*(i%(b/2+1)<1)+'Buzz'*(i%(~-b/3+4)<1)or d;"*5000

Try it online!

answered Feb 23, 2019 at 20:24
\$\endgroup\$
2
\$\begingroup\$

JavaScript (ES6), (削除) 117 (削除ここまで) 116 bytes

Outputs comma-delimited digits, each digit being expressed as a decimal quantity (e.g. \19ドル_{20}\$ is \19ドル\$ and \21ドル_{20}\$ is \1,1ドル\$).

b=>(g=n=>n>1?g(n-1)+`
`+((s=n%(b+2>>1)?'':'Fizz',n%(b/3+3.9|0)?s:s+'Buzz')||(g=n=>n?[...g(n/b|0),n%b]:s)(n)):1)(5e3)

Try it online!

(limited to 100 so that TIO's output does not blow up)

answered Feb 22, 2019 at 21:28
\$\endgroup\$
2
  • \$\begingroup\$ Any chance you could explain what |0 and (5e3) does? \$\endgroup\$ Commented Feb 26, 2019 at 15:16
  • \$\begingroup\$ @psinaught Performing a bitwise OR with \0ドル\$ on a number \$n\$ forces it to be coerced to the nearest smaller integer, so it's basically equivalent to Math.floor(n) (except it only works for \0ドル\le n<2^{31}\$). 5e3 is the exponential notation for 5000 -- which is here the argument passed to the outer arrow function \$g\$. \$\endgroup\$ Commented Feb 26, 2019 at 15:48
2
\$\begingroup\$

Vyxal, 26 bytes

121⁄2ƛ?8"¦23f/›ḊkF1⁄2*∑n?τ$∨;⁋

Try it Online!

answered Jun 11, 2022 at 18:59
\$\endgroup\$
2
\$\begingroup\$

Julia, 108

h(b,N)=join((n->[string(n,base=b),"Buzz","Fizz","FizzBuzz"][1+(1>n%(b÷2+1))*2+(1>n%((b+11)÷3))]).(1:N),"\n")

ATOable

answered Jun 11, 2022 at 17:33
\$\endgroup\$
2
  • 1
    \$\begingroup\$ 100 bytes answers are scored in bytes, not chars, and ATO gives the count at the top \$\endgroup\$ Commented Jun 13, 2022 at 15:43
  • \$\begingroup\$ you're supposed to count to 5000, not take it as an input I think \$\endgroup\$ Commented Jun 13, 2022 at 21:15
1
\$\begingroup\$

Perl 6, 91 bytes

{$!=0;('Fizz'x++$!%%($_/2+|0+1)~'Buzz'x$!%%(($_+8)/3+|0+1)||[R,] $!.polymod($_ xx*))xx𐄦}

Try it online!

Anonymous code block that returns a list of either strings of Fizz/Buzz/FizzBuzz or a (削除) reversed (削除ここまで) list of integers in the base.

answered Feb 23, 2019 at 4:05
\$\endgroup\$
1
1
\$\begingroup\$

05AB1E, (削除) 39 (削除ここまで) (削除) 37 (削除ここまで) 36 bytes

8+‚U54*LεX23S÷>Ö"Fi×ばつJDõQiyIв]»

-2 bytes by creating a port of @JonathanAllan's Jelly answer.

Try it online or verify all test cases (but as list-output and with the first 100 instead of 5000).

Explanation:

8+ # Add 8 to the (implicit) input
 ‚ # Pair it with the (implicit) input
 U # Pop and store it in variable `X`
54*L # Create a list in the range [1,5000]
 ε # Map each value `y` to:
 X23S÷ # Integer-divide the input by 2, and the input+8 by 3
 > # Increase both by 1
 Ö # Check for both if they divide value `y` evenly (1 if truthy; 0 if falsey)
 "FizzÒÖ" # Push dictionary string "Fizz Buzz"
 # # Split on spaces
 ×ばつ # Repeat the strings the result amount of times (0 or 1)
 J # Join both strings together to a single string
 DõQi # If this string is empty:
 yIв # Push value `y` in Base-input (as list) instead
 ] # Close the if-statement and map
 » # Join the list by new-lines (and inner lists by spaces implicitly)
 # (and output the result implicitly)

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why "FizzÒÖ" is "Fizz Buzz".

answered Feb 25, 2019 at 8:14
\$\endgroup\$
5
  • \$\begingroup\$ I have a looping version at 33 bytes in case you wanna try and optimize this. Still a byte longer than Jelly though :( \$\endgroup\$ Commented Feb 26, 2019 at 11:52
  • \$\begingroup\$ @Emigna Have you already post it? Or it's fairly similar to my answer and it is meant as a golf? PS: Jelly has a few short-cut builtins with for example the [input, input+8] part, and the filter part afterwards (which I now do as DõQi yIв, but I have the feeling it can be golfed some more..) \$\endgroup\$ Commented Feb 26, 2019 at 12:31
  • \$\begingroup\$ Levenshtein-distance wise it's very different from yours (although parts can be rewritten to be more like yours). But I also use Jonathan's n+8 trick so I figured I'd let you try and golf yours down towards it if you want. Otherwise I'll post it as a separate answer. \$\endgroup\$ Commented Feb 26, 2019 at 12:38
  • \$\begingroup\$ @Emigna I'm currently a bit busy at work, so don't really have time to golf this answer. So if you want you can post it as your own answer. You've got my upvote. ;) \$\endgroup\$ Commented Feb 26, 2019 at 12:42
  • \$\begingroup\$ Unfortunately I discovered a bug in my version so now it's 34. I have some ideas that might make yours or mine shorter that I'll explore later. Beating/tying Jelly seems tough now though. \$\endgroup\$ Commented Feb 26, 2019 at 15:00
0
\$\begingroup\$

R, 138 bytes

function(b,`*`=rep)Map(function(i)"if"((s=paste0("","Fizz"*!i%%(b%/%2+1),"Buzz"*!i%%((b+11)%/%3)))>0,s,i%/%b^((log(i,b)%/%1):0)%%b),1:5e3)

Try it online!

answered Feb 24, 2019 at 1:51
\$\endgroup\$
0
\$\begingroup\$

05AB1E, 34 bytes

Uses Jonathan's mathematical insight that ceil(n/3+3) = floor((n+8)//3)+1

ŽJćG8+‚2L>÷>Ns×ばつJNIв‚õKн,

Try it online!

Explanation

ŽJćG # for N in [1 ...5001)
 8+‚2L>÷> # push [input//2+1, (input+8)//3+1]
 NsÖ # check each if N is divisible by it
 ...TMÁzz # push "fizz"
 'ÒÖ # push "buzz"
 ‚ # pair
 ×ばつ # repeat a number of times corresponding to the result of the 
 # divisibility test
 J # join to string
 NIв‚ # pair with N converted to base <input>
 õK # remove empty string
 н, # print head of the remaining list
answered Feb 26, 2019 at 14:57
\$\endgroup\$
0
\$\begingroup\$

C# (Visual C# Interactive Compiler), (削除) 180 (削除ここまで) (削除) 171 (削除ここまで) 168 bytes

n=>{for(int i=1,p;i<5001;){var j=new Stack<int>();for(p=i;p>0;p/=n)j.Push(p%n);var s=i%~(n/2)<1?"Fizz":"";Print(i++%((n+11)/3)<1?s+"Buzz":s==""?string.Join("-",j):s);}}

Outputs like Arnauld's answer. Thanks to digEmAll for the idea of using a stack to reverse the output.

Saved 3 bytes thanks to ceilingcat

Try it online!

answered Feb 23, 2019 at 4:01
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I'm going to have to say 'no' to the reverse digits. While it's the correct idea mathematically, it's not the Fizzbuzz program, say an employer would want. It's unfortunate that C# doesn't have an array reverse function. \$\endgroup\$ Commented Feb 23, 2019 at 7:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.