Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Nth FizzBuzz Number

Introduction

Everyone knows the FizzBuzz sequence. It goes something like this:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
.
.
.

In case you don't know, if the number is divisible by 3, it's Fizz. If it is divisible by 5, it's Buzz. If it is divisible by both, it's FizzBuzz. If it is not divisible by both, it's just the original number.

Task

Take two inputs, for example (space separated here)

Fizz 3

For this specific example input, you should output 9, the third Fizz. To be more general, take a word and a number, output the numberth word.

The word input may be Number, and in this case, you should output the numberth number in the FizzBuzz sequence that is not Fizz, Buzz, or FizzBuzz.

You may choose any 4 distinct, consistent inputs representing Fizz, Buzz, FizzBuzz and Number.

Test Cases

Fizz 3 => 9
Buzz 4 => 25
FizzBuzz 2 => 30
Number 312 => 584

Scoring

Shortest code wins!

Rules

  • No standard loopholes.

Answer*

Draft saved
Draft discarded
Cancel
5
  • \$\begingroup\$ Here's one pair of parens less. \$\endgroup\$ Commented Dec 18, 2021 at 6:36
  • \$\begingroup\$ @pajonk - Thanks! I really should try to understand the precedence rules... \$\endgroup\$ Commented Dec 18, 2021 at 8:07
  • \$\begingroup\$ stat.ethz.ch/R-manual/R-devel/library/base/html/Syntax.html is my favourite site when golfing in R ;) \$\endgroup\$ Commented Dec 18, 2021 at 10:04
  • \$\begingroup\$ And one pair less again. \$\endgroup\$ Commented Dec 18, 2021 at 10:11
  • \$\begingroup\$ @pajonk - Thanks. I think I ought to transfer this answer to you, after you've fixed all my parentheses... \$\endgroup\$ Commented Dec 18, 2021 at 12:42

AltStyle によって変換されたページ (->オリジナル) /