Movatterモバイル変換


[0]ホーム

URL:


Sorry, we no longer support your browser
Please upgrade toMicrosoft Edge,Google Chrome, orFirefox. Learn more about ourbrowser support.
Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities includingStack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Loading…
Code Golf

You are notlogged in. Your edit will be placed in a queue until it ispeer 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*

The Return of FizzBuzz

Intro

Beauty lies in the eye of the beholder. Output lies in the choice of the compiler. There are some codes that give different outputs based on what language they are executed in. Take for instance, the code given below:

# include <stdio.h># define print(a) int main(){printf("C is better"); return 0;}print("Python is better")

When executed in C, it prints "C is better". When using a python interpreter, it prints "Python is better".

Challenge

The challenge is a modification of the FizzBuzz challenge. Write a code that gives different outputs based on language it is executed in. When executed with the first language, it prints all numbers from 1 to 1000 (both inclusive) which are not divisible by 2. If a number is divisible by 2, it outputs "FizzBuzz". When executed with the second language, if a number is not divisible by 3, it is printed. Else, the string "FizzBuzz" is printed.

Example

Output when executed in language 1 would be

1 FizzBuzz 3 FizzBuzz 5 FizzBuzz 7 FizzBuzz 9 FizzBuzz ... (upto FizzBuzz 999 FizzBuzz)

Output when executed in language 2 would be

1 2 FizzBuzz 4 5 FizzBuzz 7 8 FizzBuzz 10 11 FizzBuzz 13 14 FizzBuzz ... (upto 998 FizzBuzz 1000)

Optional Challenge

You can optionally allow the program to execute in more than 2 languages. For the ith language, every multiple of (i+1) is substituted with FizzBuzz. It isn't necessary, but at least 2 languages are compulsory.

Constraints

Need to write a fully functioning code. For instance, a method/function/procedure alone (which could not independently execute) would not be acceptable

Can use only 1 file

All outputs to be printed to standard output (not to standard error)

All other standard rules of code-golf apply

EDIT: Fixed a loophole:

No taking of user inputs during execution

Edit I got a comment saying the question wasn't clear if a non-empty separator is mandatory between the numbers. Assume it's not mandatory

Scoring

Total score = Number of bytes in the program.

Winning

Consider different participation brackets (based on number of languages being used). Person with least characters in each bracket can be considered a winner.

Answer*

More generally…

  • …Please make sure to answer the question and provide sufficient detail.

  • …Avoid asking for help, clarification or responding to other answers (use comments instead).

Draft saved
Draft discarded
Cancel
5
  • 3
    \$\begingroup\$this deserves an equivalent of the IOCCC Abuse of the rules award! :)\$\endgroup\$CommentedMay 13, 2020 at 14:53
  • \$\begingroup\$I'd say that only the first 1000 versions of R would count then, since everything after that will produce identical results given the sample range.\$\endgroup\$CommentedMay 13, 2020 at 17:20
  • \$\begingroup\$just using$sv is shorter.strtoi might work instead ofas.double?\$\endgroup\$CommentedMay 13, 2020 at 17:24
  • \$\begingroup\$I have a nagging feeling that$-completion wasn't in very early versions of R (was it in S-plus?).strtoi might have been around the whole time though — it's annoyingly hard to find documentation for ancient versions of R!\$\endgroup\$CommentedMay 13, 2020 at 17:29
  • \$\begingroup\$@Darrel there is no requirement that the outcome change, just that the solution is a valid program in the specified language(s). If the challenge had said 1 million instead of 1000, this solution would still work (with minor modifications)\$\endgroup\$CommentedMay 14, 2020 at 7:26
Add a comment | 
How to Edit
  • Correct minor typos or mistakes
  • Clarify meaning without changing it
  • Add related resources or links
  • Always respect the author’s intent
  • Don’t use edits to reply to the author
How to Format
  • create code fences with backticks ` or tildes ~
    ```
    like so
    ```
  • add language identifier to highlight code
    ```python
    def function(foo):
        print(foo)
    ```
  • put returns between paragraphs
  • for linebreak add 2 spaces at end
  • _italic_ or**bold**
  • indent code by 4 spaces
  • backtick escapes`like _so_`
  • quote by placing > at start of line
  • to make links (use https whenever possible)
    <https://example.com>
    [example](https://example.com)
    <a href="https://example.com">example</a>
  • MathJax equations\$\sin^2 \theta\$

MathJax help »

How to Tag

A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.

  • complete the sentence:my question is about...
  • use tags that describe things or concepts that areessential, not incidental to your question
  • favor usingexisting popular tags
  • read the descriptions that appear below the tag

If your question is primarily about a topic for which you can't find a tag:

popular tags »



[8]ページ先頭

©2009-2025 Movatter.jp