Code Golf Asked on December 10, 2021
In our recent effort to collect catalogues of shortest solutions for standard programming exercises, here is PPCG’s first ever vanilla FizzBuzz challenge. If you wish to see other catalogue challenges, there is “Hello World!” and “Is this number a prime?”.
Write a program that prints the decimal numbers from 1 to 100 inclusive. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
The output will be a list of numbers (and Fizzes, Buzzes and FizzBuzzes) separated by a newline (either n
or rn
). A trailing newline is acceptable, but a leading newline is not. Apart from your choice of newline, the output should look exactly like this:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
The only exception to this rule is constant output of your language’s interpreter that cannot be suppressed, such as a greeting, ANSI color codes or indentation.
This is not about finding the language with the shortest approach for playing FizzBuzz, this is about finding the shortest approach in every language. Therefore, no answer will be marked as accepted.
Submissions are scored in bytes in an appropriate preexisting encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score–if in doubt, please ask on Meta.
Nothing can be printed to STDERR.
Feel free to use a language (or language version) even if it’s newer than this challenge. If anyone wants to abuse this by creating a language where the empty program generates FizzBuzz output, then congrats for paving the way for a very boring answer.
Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.
If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck derivatives like Alphuck and ???), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.
Because the output is fixed, you may hardcode the output (but this may not be the shortest option).
You may use preexisting solutions, as long as you credit the original author of the program.
Standard loopholes are otherwise disallowed.
As a side note, please don’t downvote boring (but valid) answers in languages where there is not much to golf; these are still useful to this question as it tries to compile a catalogue as complete as possible. However, do primarily upvote answers in languages where the authors actually had to put effort into golfing the code.
var QUESTION_ID=58615;var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var OVERRIDE_USER=30525;var answers=[],answers_hash,answer_ids,answer_page=1,more_answers=true,comment_page;function answersUrl(index){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(index,answers){return"https://api.stackexchange.com/2.2/answers/"+answers.join(';')+"/comments?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){answers.push.apply(answers,data.items);answers_hash=[];answer_ids=[];data.items.forEach(function(a){a.comments=[];var id=+a.share_link.match(/d+/);answer_ids.push(id);answers_hash[id]=a});if(!data.has_more)more_answers=false;comment_page=1;getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){data.items.forEach(function(c){if(c.owner.user_id===OVERRIDE_USER)answers_hash[c.post_id].comments.push(c)});if(data.has_more)getComments();else if(more_answers)getAnswers();else process()}})}getAnswers();var SCORE_REG=/<hd>s*([^n,<]*(?:<(?:[^n>]*>[^n<]*</[^n>]*>)[^n,<]*)*),.*?(d+)(?=[^nd<>]*(?:<(?:s>[^n<>]*</s>|[^n<>]+>)[^nd<>]*)*</hd>)/;var OVERRIDE_REG=/^Overrides*header:s*/i;function getAuthorName(a){return a.owner.display_name}function process(){var valid=[];answers.forEach(function(a){var body=a.body;a.comments.forEach(function(c){if(OVERRIDE_REG.test(c.body))body='<h1>'+c.body.replace(OVERRIDE_REG,'')+'</h1>'});var match=body.match(SCORE_REG);if(match)valid.push({user:getAuthorName(a),size:+match[2],language:match[1],link:a.share_link,});else console.log(body)});valid.sort(function(a,b){var aB=a.size,bB=b.size;return aB-bB});var languages={};var place=1;var lastSize=null;var lastPlace=1;valid.forEach(function(a){if(a.size!=lastSize)lastPlace=place;lastSize=a.size;++place;var answer=jQuery("#answer-template").html();answer=answer.replace("{{PLACE}}",lastPlace+".").replace("{{NAME}}",a.user).replace("{{LANGUAGE}}",a.language).replace("{{SIZE}}",a.size).replace("{{LINK}}",a.link);answer=jQuery(answer);jQuery("#answers").append(answer);var lang=a.language;lang=jQuery('<a>'+lang+'</a>').text();languages[lang]=languages[lang]||{lang:a.language,lang_raw:lang.toLowerCase(),user:a.user,size:a.size,link:a.link}});var langs=[];for(var lang in languages)if(languages.hasOwnProperty(lang))langs.push(languages[lang]);langs.sort(function(a,b){if(a.lang_raw>b.lang_raw)return 1;if(a.lang_raw<b.lang_raw)return-1;return 0});for(var i=0;i<langs.length;++i){var language=jQuery("#language-template").html();var lang=langs[i];language=language.replace("{{LANGUAGE}}",lang.lang).replace("{{NAME}}",lang.user).replace("{{SIZE}}",lang.size).replace("{{LINK}}",lang.link);language=jQuery(language);jQuery("#languages").append(language)}}
body{text-align:left!important}#answer-list{padding:10px;width:290px;float:left}#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table>
range(1;101)|. as $n|[(select(.%3==0)|"Fizz"),(select(.%5==0)|"Buzz")]|add//$n
Answered by customcommander on December 10, 2021
body{counter-reset:n}
p::after{counter-increment:n;content:counter(n)}
p:nth-child(3n)::after{content:"Fizz"}
p:nth-child(5n)::after{content:"Buzz"}
p:nth-child(15n)::after{content:"FizzBuzz"}
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
<p><p><p><p><p><p><p><p><p><p>
Answered by customcommander on December 10, 2021
takemetourheart
give a up [*range(1,101)[::-1]]
togetherforeverandnevertopart
give i up a.pop()
give s up "Fizz"*(i%3<1)+"Buzz"*(i%5<1)
ijustwannatelluhowimfeeling [str(i),s][s>""]+"n"
RickRoll-Lang keywords do not need spaces between them
takemetourheart -- main() function declaration
give a up [*range(1,101)[::-1]] -- set a to reverse of int range [1, 101)
togetherforeverandnevertopart -- infinite loop
give i up a.pop() -- pop last element of a and store in i
give s up "Fizz"*(i%3<1)+"Buzz"*(i%5<1) -- string multiplcation to form fizzbuzz depending on modulus remainders
ijustwannatelluhowimfeeling [str(i),s][s>""]+"n" -- print i if s is empty else s and a newline
-- implicit "say goodbye" (end block) at the end
-- another say goodbye
Answered by Hydrazer on December 10, 2021
The following program must be saved as x
, which is for 1 byte of penalty.
''
((++x%3))||Fizz
((x%5))||$_Buzz
echo ${_:-$x}
((x>99))||. x
Answered by nrgmsbki4spot1 on December 10, 2021
G'DAY MATE!
I RECKON x IS A WALKABOUT FROM[1TO 100]<YA RECKON x %15<1?<GIMME "FizzBuzz";>WHATABOUT x %5<1?<GIMME "Buzz";>WHATABOUT x %3<1?<GIMME "Fizz";>WHATABOUT ?<GIMME x;>>CHEERS C***!
Fair dinkum, this was hard yakka cause there's no way to golf the whitespace because the parser seems to be strict. I coulda sworn it never worked when I tried to remove whitespace.
-33 thanks to @Bubbler
-3 thanks to @JoKing
Wanna hear what it actually sounds like? Wonder no more: https://youtu.be/ewu1CmjZcmQ
Answered by lyxal on December 10, 2021
output.xml
<?xml-stylesheet type="text/xsl" href="s.xsl"?><n></n>
s.xsl
<x:stylesheet version="1.0" xmlns:x="http://www.w3.org/1999/XSL/Transform"><x:output method="text" /><x:template match="n"><x:text>1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
</x:text></x:template></x:stylesheet>
Hardcoding it is shorter than doing it the fun way :(
So here's the old way for posterity
output.xml
<?xml-stylesheet type="text/xsl" href="s.xsl"?><n><N>1</N><N>2</N><N>3</N><N>4</N><N>5</N><N>6</N><N>7</N><N>8</N><N>9</N><N>10</N><N>11</N><N>12</N><N>13</N><N>14</N><N>15</N><N>16</N><N>17</N><N>18</N><N>19</N><N>20</N><N>21</N><N>22</N><N>23</N><N>24</N><N>25</N><N>26</N><N>27</N><N>28</N><N>29</N><N>30</N><N>31</N><N>32</N><N>33</N><N>34</N><N>35</N><N>36</N><N>37</N><N>38</N><N>39</N><N>40</N><N>41</N><N>42</N><N>43</N><N>44</N><N>45</N><N>46</N><N>47</N><N>48</N><N>49</N><N>50</N><N>51</N><N>52</N><N>53</N><N>54</N><N>55</N><N>56</N><N>57</N><N>58</N><N>59</N><N>60</N><N>61</N><N>62</N><N>63</N><N>64</N><N>65</N><N>66</N><N>67</N><N>68</N><N>69</N><N>70</N><N>71</N><N>72</N><N>73</N><N>74</N><N>75</N><N>76</N><N>77</N><N>78</N><N>79</N><N>80</N><N>81</N><N>82</N><N>83</N><N>84</N><N>85</N><N>86</N><N>87</N><N>88</N><N>89</N><N>90</N><N>91</N><N>92</N><N>93</N><N>94</N><N>95</N><N>96</N><N>97</N><N>98</N><N>99</N><N>100</N></n>
s.xsl
<x:stylesheet version="1.0" xmlns:x="http://www.w3.org/1999/XSL/Transform"><x:output method="text" /><x:template match="n"><x:for-each select="N"><x:if test=".mod 3=0">Fizz</x:if><x:if test=".mod 5=0">Buzz</x:if><x:if test=".mod 3*.mod 5!=0"><x:value-of select="."/></x:if><x:text> </x:text></x:for-each></x:template></x:stylesheet>
W...why did I do this to myself?
Example output (using Firefox + privacy.file_unique_origin = false
):
XSLT/XML doesn't (afaik) have a nice easy way of generating ranges...so I have to manually place all the numbers in tags so I can use for-each
later on.
<x:stylesheet version="1.0"
xmlns:x="http://www.w3.org/1999/XSL/Transform"> <!-- Define the XSL namespace to be "X" for brevity -->
<x:output method="text" /> <!-- Textual output -->
<x:template match="n"> <!-- Match the root tag n -->
<x:for-each select="N"> <!-- For each N, which is a number in the range 1...100 -->
<x:if test=".mod 3=0">Fizz</x:if> <!-- If N % 3 == 0, write "Fizz" -->
<x:if test=".mod 5=0">Buzz</x:if> <!-- If N % 5 == 0, write "Buzz" -->
<x:if test=".mod 3*.mod 5!=0"> <!-- If N isn't divisible by either 3 or 5, write the number -->
<x:value-of select="."/>
</x:if>
<x:text> </x:text> <!-- Add a newline -->
</x:for-each>
</x:template>
</x:stylesheet>
Answered by lyxal on December 10, 2021
f(){ [ $((i%$1)) = 0 ]&&j=$2zz$j;};for i in `seq 100`;do(f 5 Bu;f 3 Fi;echo ${j-$i});done
As a bonus this is partially obfuscated, containing neither Fizz
nor Buzz
(even saved 2 bytes in doing so).
f(){(: $((0/(i%$1))))||j=$2zz$j;};for i in `seq 100`;do(f 5 Bu;f 3 Fi;echo ${j-$i});done
This solution was an attempt to reduce the bytes used by the conditional. In the end it saved only 1 byte, but it spams STDERR, which actually looks OK on TIO because it separates the streams. Even so I’m not sure it’s a proper solution due to the spam, but honestly I’m quite proud of the trickery involved. We could suppress the errors with a redirect but that eats up precious bytes :)
EDIT: the trickery probably bears an explanation as the mechanism may not be immediately obvious.
Most of this explanation applies to the 89 byte, the only change is the conditional.
f(){
Define function f
, easy enough.
(: $((0/(i%$1))))
This is the (most) sneaky bit
(
begin a subshell, use :
'true' to perform some maths $((
in which we take 0
and divide /
by the result of (i%$1)
, end the maths ))
and end the subshell )
.
This whole construct returns exit code 0
when the result of i % $1
is non-zero, otherwise it returns 1
.
This works because when the i % $1
operation results in a zero we get a "division by zero" error terminating the subshell and causing it to return exit code 1.
This trumps the :
"true" that the maths is running behind.
In all other instances we are taking zero and dividing it by a non-zero i % $1
result, which is obviously always zero by definition but the key thing is that it doesn't error the shell (thus the :
stands) and from this we can catch the "division by zero" without the whole script bombing out.
||j=$2zz$j;};
Catch the error from the subshell via ||
and set j=
to the value of $2
appending zz
(to complete our Fizzes and Buzzes) and prepending the whole thing to $j
(the prepend action stems from an earlier iteration and only remains so because there's no advantage in making it an append. Even more so now I've done this explanation), then just finish up the function ;};
.
NB j
lives and dies inside another subshell which calls this function, and is assumed to always start empty (but we'll get to that later).
for i in `seq 100`;do
As it appears, for
loop through 1-100.
(f 5 Bu;f 3 Fi;echo ${j-$i})
The second (very mildly) sneaky part -- we start a subshell (
and for every number in the sequence, we call f
twice. Once each for the FizzBuzz numbers 5, 3 (to be used in the i % $1
statement) and the corresponding two prefix letters which get used in making j
. We then print the value of j
or, if it's empty, insert the current $i
value.
When we close the subshell, j
gets reset to its starting value (empty, assuming we started in a clean room).
;done
Yes, I do believe we are.
Answered by bxm on December 10, 2021
F takes I&S
let M be N/I
turn up M
if N-I*M
S's""
return S
N's0
while N-100
let N be+1
say F taking 3,"Fizz"+F taking 5,"Buzz" or N
Try it here (Code will need to be pasted in)
Answered by Shaggy on December 10, 2021
1&0&'F0&'B1&n
++[]'i[]'u[]/
1%3&'z5&'z6&0&
1&%%'z%%'z==??
%%3&/5&/ &
1&>> >>6&[]
>> ??/
::
Ungolfed:
" 0 1 2 3 4 5 6
---------------------"
1& 0& 'F 0& 'B 1& n
++ [] 'i [] 'u [] /
1% 3& 'z 5& 'z 6& 0&
1& %% 'z %% 'z == ??
%% 3& / 5& / 0&
1& >> >> 6& []
>> ?? /
::
Thread 0 increments the accumulator (acc
) every iteration, stopping execution if acc == 101
, then jumps to thread 1.
Thread 1 checks if (acc % 3) > 0
. If so, it jumps to thread 3, otherwise it jumps to thread 2.
Thread 2 prints Fizz
, then jumps to thread 3.
Thread 3 checks if (acc % 5) > 0
. If so, it jumps to thread 5, otherwise it jumps to thread 4.
Thread 4 prints Buzz
, then jumps to thread 6.
Thread 5 looks back to thread 1 to see if (acc % 3) == 0
. If so, it jumps to thread 6, otherwise it prints acc
, then jumps to thread 6.
Thread 6 prints a newline, then jumps back to thread 0.
I think this could probably be refactored to golf away some of the whitespace, but I'm not doing that since if I do, I'll likely get sucked in and do nothing else for ~8 hours or so. :/
Answered by Aaroneous Miller on December 10, 2021
range(1;101)|if.%15<1then"FizzBuzz"elif.%3<1then"Fizz"elif.%5<1then"Buzz"else. end
Yet to golf it!
Removed superfluous spaces thanks to @DLosc.
Answered by AviFS on December 10, 2021
ef̀|3 5^ŹFh̃õ
e 1e2 (i.e. 100)
f̀ for i in 1:100
|3 5 Divisibility by [3, 5] (vectorizes)
^ String repeat by (vectorizes):
ŹF "FizzBuzz"
h̃ Halved (i.e. ["Fizz", "Buzz"])
õ Logical OR with i
(in Fact, lists are false when all items are "" or 0
or when the list is empty)
Implicit grid (smash inner lists and join outer list by newline)
ef̀|3 5^'b̀M̀b̀Ò'h̃õ
No "FizzBuzz"
builtin, simply uses string compression
Answered by 2x-1 on December 10, 2021
тLv”FizzÒÖ”#y3 5‚ÖÏJy‚éθ,
I figured I'd add a fourth 05AB1E answer to this challenge. This uses my favourite "vectorise is-divisible and then repeat the fizbuzz list accordingly" approach.
тLv”FizzÒÖ”#y3 5‚ÖÏJy‚éθ,
тL # The range 1 .. 100
v # For each N in that range:
”FizzÒÖ”# # Push the list ["Fizz", "Buzz"]
y3 5‚Ö # Push N % [3, 5] == 0 (vectorised)
Ï # "Multiply" the two lists as you would in Vyxal
J # And concatenate that into a single string
y‚ # And pair that with N
é # Sorting that by length, so that the value we want is always last
θ, # And print it with a newline
Answered by lyxal on December 10, 2021
100 times context 1 add "Buzz"context 1 add 5 mod 0 equal repeat "Fizz"context 1 add 3 mod 0 equal repeat add logicor print
Context is everything. This is different to Wasif's Javastack answer because it uses a loop instead of a map, as well as extensive use of the context variable (totally not inspired by a certain golfing language made by a certain cg user with Flowey as his pfp).
Roughly equivalent to:
100ʁ ( n 1+ `Fizz` n 1+ 3 ḋt ¬ẋ `Buzz` n 1+ 5 ḋt ¬ẋ + ⟇, )
in vyxal.
You don't know how nice it was to write a Javastack answer without restrictions after 13 rounds of C&R.
Answered by lyxal on December 10, 2021
100 range map 1 add duplicate 3 mod 0 equal "Fizz"swap repeat swap 5 mod 0 equal "Buzz"swap repeat swap add swap 1 add swap logicor end "\n"join
-17 thanks to exedraj -22 thanks to new mod builtin
Answered by wasif on December 10, 2021
for i in range(100):print(i%3//2*'Fizz'+i%5//4*'Buzz'or-~i)
Answered by ryno on December 10, 2021
Today I learned that and
has higher precidence than or
or xor
; I suffered from making a proper control flow
eval q y eval q x ord or return cos while chop and chop and chop x and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y xor eval q y print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos if length q q s s q eq chr ord reverse length or not chr ord reverse length y or eval q x print length unless length q q s s q eq chr ord reverse length or not chr ord reverse length x xor print chr hex qw q and q while s qq q and length ne ord qw q eq
# fizz part
eval q y
# if(length%3==0)
eval q x
# instead of length or return 1
ord or return cos
while
# instead of s/...//
chop and chop and chop
x and
# print 'Fizz'
print chr ord uc qw q for q and
print chr ord q tie gt and
print chr length q else x oct oct ord q eq le and
print chr length q else x oct oct ord q eq le and
# for truthy
return cos
for
# instead of $_
uc
y
xor
# buzz part
eval q y
# print 'Buzz'
print uc chr ord q dbmopen and and
print chr ord q dump and and
print chr length q else x oct oct ord q eq le and
print chr length q else x oct oct ord q eq le and
# for truthy
return cos
if
# instead of length%5, /[05]$/
length q q s s q eq chr ord reverse length or
not chr ord reverse length
y
or
# this block is done when length%15==0 or length%3&&length%5
eval q x
print length
unless
# instead of length%5
length q q s s q eq chr ord reverse length or
not chr ord reverse length
x
xor
# newline
print chr hex qw q and q
while
s qq q and
# ord qw q eq == 101
length ne ord qw q eq
eval q y eval q kill and length or return cos while s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and s q qq and ok and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y or eval q y eval q kill and length or return cos while s q qq and s q qq and s q qq and s q qq and s q qq and ok and print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y or eval q y eval q kill and length or return cos while s q qq and s q qq and s q qq and ok and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc y or print length xor print chr length q q x x x x eq while s qq q and length ne ord qw q eq
# fizzbuzz part
eval q y
# length%15==0?
eval q k
ill and length or return cos
while
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and
s q qq and s q qq and s q qq and o
k and
# then print FizzBuzz, as in first ppencode
print chr ord uc qw q for q and
print chr ord q tie gt and
print chr length q else x oct oct ord q eq le and
print chr length q else x oct oct ord q eq le and
print uc chr ord q dbmopen and and
print chr ord q dump and and
print chr length q else x oct oct ord q eq le and
print chr length q else x oct oct ord q eq le and
# cos is for TRUTHY
return cos
# don't change $_ outside
for uc
# buzz part, like above
y or eval q y
eval q kill and length or return cos while s q qq and s q qq and s q qq and s q qq and s q qq and ok and print uc chr ord q dbmopen and and print chr ord q dump and and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc
# fizz part, like above
y or eval q y
eval q kill and length or return cos while s q qq and s q qq and s q qq and ok and print chr ord uc qw q for q and print chr ord q tie gt and print chr length q else x oct oct ord q eq le and print chr length q else x oct oct ord q eq le and return cos for uc
# no special strings
y or print length
# print LF
xor print chr length q q x x x x eq
# pretty familiar, isn't it?
while s qq q and length ne ord qw q eq
Answered by nrgmsbki4spot1 on December 10, 2021
Using binary encoding:
000000 31 88 01 88 64 7b 2f 69 92 3e 92 33 28 46 69 7a
000010 7a 42 75 7a 7a 29 69 88 0f 28 42 75 7a 7a 29 69
000020 20 35 28 46 69 7a 7a 29 69 88 03 33 7b 92 6a 30
000030 92 3d 7b 2f 69 92 3e 92 33 7d 7b 92 75 7d 92 55
000040 7d 92 83 69 20 3d 7d 92 48
Try it online! (thanks to tail spark rabbit ear, ignore TIO's character count).
This is a straight-forward encoding of the following 101 byte program (in binary encoding, 136 n is a signed 8-bit integer and 146 n is command n from the system name encoding list in appendix F of the PostScript language reference).
1 1 100{/i exch def(FizzBuzz)i 15(Buzz)i 5(Fizz)i 3 3{mod 0 eq{/i exch def}{pop}ifelse}repeat i =}for
The non-binary encoded version can be reduced to 98 bytes if we don't mind leaving /i on the stack.
/i 1 1 100{def(FizzBuzz)i 15(Buzz)i 5(Fizz)i 3 3{mod 0 eq{/i exch def}{pop}ifelse}repeat i =/i}for
Answered by PertinentDetail on December 10, 2021
this is uncompetitive, but this was so fun I couldn't help but post it here.
#include <bits/stdc++.h>
using namespace std;auto f=[](int i){return i%15?(i%5?(i%3?to_string(i):"Fizz"):"Buzz"):"FizzBuzz";};int main(){for(auto i:views::iota(1,100)|views::transform(f))cout<<i<<endl;}
Answered by Matthew Roh on December 10, 2021
Hj
, -6 bytes thanks to Aaron
-7 bytes thanks to the legend himself (lyxal)
Nothing against Lyxal's answer but uses a different technique
ƛ₃kf*n₅kb*+∴ stack is preset to a 100 because of the `H` flag
ƛ lambda map with variable n
₃ push 1 if n%3 == 0 (we'll call the return a)
kf push constant Fizz to the stack
* push a*kF
n push n
₅ push 1 if n%5 == 0 (we'll call it b)
kb push Buzz to the stack
* push b*kB
+ add last two elements of the stack ""/Fizz/Buzz
∴ push the maximum of n and ""/Fizz/Buzz/FizzBuzz
Vyxal prints out the last element of the stack by default (the `j` flag joins the list with newlines)
Answered by math on December 10, 2021
n=N whilst C>n{t=""n=n+I if!(n%3){t="Fizz"}if!(n%V){t=t+"Buzz"}proclaim((t||arabic(n))+"
")}
Hear ye, hear ye! Unbeknownst to some, Sampersand hath also created Squire, a companion language to ye lowly language Knight. Squire hath many possessions, but alas, it doth not golfeth as well as its brethren. Thou shalt check it out as well, though.
I cannot provideth thee with a demo link yet as the interpreter is a very lengthy incantation.
Ungolfeth:
# Createth a variable known by most as "n",
# He shalt begin his journey as a mere
# peasant with naught but the value zero.
# (Behold! Squire permits thee to write numbers
# in Roman numerals)
n = N
# Loop thine program unto n approacheth 100
whilst C > n {
# Lo! I spotteth another variable,
# who goes by the name of "t".
# It shall start off as a lonely empty string.
t = ""
# Increase n's wealth by bestowing upon it the number one
n = n + I
# If n divideth evenly into 3...
if !(n % 3) {
# Replaceth t with the string "Fizz"
t = "Fizz"
}
# If n also divideth evenly into 5...
if !(n % V) {
# Accompany t with the string "Buzz"
t = t + "Buzz"
}
# Proclaim to ye standard output...
proclaim(
# Either...
(
# t if it is not a lonely empty string...
t
# or n, converteth to ye foreign Arabic
# number system, used in lands afar.
|| arabic(n)
)
# Appendeth upon it a newline to start
# another journey.
+ "n"
)
}
A more favorable program is as follows:
n=N whilst C>n{t=""n=n+I if!(n%III){t="Fizz"}if!(n%V){t=t="Buzz"}proclaim((t||string(n))+"
")}
This program useth Roman numerals, but nay, thine great quest beseecheth that one must outputeth thy program using this unusual number system.
Answered by EasyasPi on December 10, 2021
;=n 0W>101=n+1nO|+*"Fizz"!%n 3*"Buzz"!%n 5n
-2 bytes: use string multiplication instead of IF
-5 bytes: I completely overlooked |
, I assumed it had C semantics.
Ungolfed:
# start with n at 0
; = n 0
# increment n and loop while less than 101
: WHILE > 101 (= n + 1 n)
# outlined from the output for clarity
# concatenate:
; = fizzbuzz +
# Fizz if n % 3 == 0
: * "Fizz" ! (% n 3)
# Buzz if n % 5 == 0
: * "Buzz" ! (% n 5)
# If fizzbuzz is not empty, output it, otherwise output n
: OUTPUT | fizzbuzz n
Answered by EasyasPi on December 10, 2021
Answered by RezNesX on December 10, 2021
i:1|i<101|i:i+1@(i%3+i%5=0?print:"FizzBuzz"|i%3=0?print:"Fizz"|i%5=0?print:"Buzz"|print:i)
Answered by wasif on December 10, 2021
declarex=0
loop100{
x=x+1
ifx%15<1{
printLine("FizzBuzz")
}
ifx%3<1&&x%5>0{
printLine("Fizz")
}
ifx%5<1&&x%3>0{
printLine("Buzz")
}
ifx%3>0&&x%5>0{
printLine(x)
}
}
Yes... 164 bytes.
The problem with my language is that it's almost impossible to golf, because:
declare
keyword+=
or %=
false
is the only falsey valueprintLine
and
The good thing is that because of my sloppy lexer, we can mash together expressions. You would never see ifx%15<1
or loop100
in Python, for example. [it's not a bug, it's a feature ...?]There also happens to be no documentation for PPL at the moment.
Answered by user100690 on December 10, 2021
^//C//70/105/122Z/zc/66/117/z/za1O[/ob3^%Vc/v?[./]b5^%Wcw?[./]a/vbw^*/0bo^?[#0]a10.o}O/;b101^-]
Try it on the online Branch interpreter!
The first part basically loads "Fizz" and "Buzz" along the left branches of two trees, so it looks like:
0
/
0 0
/| /
F 0 B 0
/ /
i u
/ /
z z
/ /
z z
Then, start the value at 1. Each time, load the value to the left child and 3
to the right child, modulo, move that to the left fork, and branch on condition. If it's 0
, it goes to the left branch with "Fizz" and otherwise to the right branch with just 0. [./]
keeps printing as a character and moving to the left child so long as the value is not 0
, so this prints "Fizz" if it's a multiple of three, and nothing happens otherwise.
Then, do the same thing but with 5
and move to the "Buzz" branch. Finally, load the results of both modulos (using registers to save and move these values) and multiply them. Loading 0
to the left child and the current value into the right branch, using ?
on the product will go to the 0
if either modulo was 0
, and to the value otherwise. Then, [#0]
keeps outputting the value and zeroing it if it is not zero; in other words, if the modulo product was 0
, it skips this, and otherwise, it outputs the current value as a number once.
Finally, output a newline, increment the current value, and check if it's high enough to end the program, and if so, exit the main loop.
Answered by hyper-neutrino on December 10, 2021
åS╬╕▌≡º$)ö;▀├Xè¶XΔ£≈♀
Not sure why recursive's solution from the tutorial hasn't been posted here yet. Probably the most minimal fizzbuzz possible in stax.
Answered by Razetime on December 10, 2021
{iiiii}dc{dddd}ic{iiii}c{dddd}c{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iic{dddd}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiiic{dddd}dddddc{iiii}iiiiiic{dddd}ddddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiii}dcc{dddd}ic{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}dciic{dddd}dc{iiii}dciiic{dddd}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{ddddd}ddddddc{iiiii}iciiiiicc{{d}}{d}ddc{iiii}dciiiiic{dddd}ddddc{iiii}dciiiiiic{dddd}dddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}dc{i}ddc{ddddd}iiic{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}cc{dddd}c{iiii}cic{dddd}dc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiii}ciiiic{dddd}ddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}ciiiiiic{dddd}ddddddc{iiii}c{i}dddc{ddddd}iiic{iiiiii}c{iii}iiiiic{ii}dddcc{ddddd}ddddddc{iiiii}iciiiiicc{{d}}{d}ddc{iiii}icddc{dddd}ic{iiii}icdc{dddd}c{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}icic{dddd}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iciiiic{dddd}dddddc{iiii}iciiiiic{dddd}ddddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iicdddc{dddd}ic{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iicdc{dddd}dc{iiii}iicc{dddd}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{ddddd}ddddddc{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iiciic{dddd}ddddc{iiii}iiciiic{dddd}dddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiciiiiic{ddddd}iiic{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiicdddc{dddd}c{iiii}iiicddc{dddd}dc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iiicic{dddd}ddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiciiic{dddd}ddddddc{iiii}iiiciiiic{ddddd}iiic{iiiiii}c{iii}iiiiic{ii}dddcc{ddddd}ddddddc{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iiiicdddddc{dddd}ic{iiii}iiiicddddc{dddd}c{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiicddc{dddd}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiicic{dddd}dddddc{iiii}iiiiciic{dddd}ddddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iiiiicddddddc{dddd}ic{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiiicddddc{dddd}dc{iiii}iiiiicdddc{dddd}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{ddddd}ddddddc{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iiiiicdc{dddd}ddddc{iiii}iiiiicc{dddd}dddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiiiciic{ddddd}iiic{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiiiicddddddc{dddd}c{iiii}iiiiiicdddddc{dddd}dc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiii}iiiiiicddc{dddd}ddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiii}iiiiiicc{dddd}ddddddc{iiii}iiiiiicic{ddddd}iiic{iiiiii}c{iii}iiiiic{ii}dddcc{ddddd}ddddddc{iiiii}iciiiiicc{{d}}{d}ddc{iiiii}dddc{d}iic{dddd}ic{iiiii}dddc{d}iiic{dddd}c{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}dddcdddddc{dddd}ddc{iiiii}iiiiiic{iiiii}iciiiiicc{{d}}{d}ddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}dddcddc{dddd}dddddc{iiiii}dddcdc{dddd}ddddddc{iiiiii}c{iii}iiiiic{ii}dddcc{{d}}{d}ddc{iiiii}iiiiiic{iiiii}iciiiiicc
Oof.
Answered by emanresu A on December 10, 2021
for(int x=0;x++<100;)System.Console.WriteLine((x%3<1?"Fizz":"")+(x%5<1?"Buzz":x%3<1?"":x));
I do not take credit for this solution. I merged two solutions together:
This solution requires C# 9, but does not use Linq.
Answered by speyck on December 10, 2021
fun main(){(1..100).map{i->println(when(0){i%15->"FizzBuzz";i%3->"Fizz";i%5->"Buzz";else->i})}}
Answered by Roan Cooney on December 10, 2021
As usual, @Bubbler nailed it. Go upvote one of his answers!
100 [1,b] [ dup [ 3 mod 0 = dup [ "Fizz"write ] when ] [ 5 mod 0 = dup [ "Buzz"write ] when ] bi or [ nl ] [ . ] if ] each
Old version:
1 [ dup 100 > ] [ dup [ 3 mod 0 = dup [ "Fizz"write ] when ] [ 5 mod 0 = dup [ "Buzz"write ] when ] bi or [ ""print ] [ dup . ] if 1 + ] until
Amazingly, until now no one posted a Factor answer. It is not really golfed much, probably can be improved.
Answered by hdrz on December 10, 2021
func main:
push 1
pop $a
.lbl a
clf.o
push $a
push 15
rem
push 0
comp
push $f.o
brtrue e
push $a
push 3
rem
push 0
comp
push $f.o
brtrue b
push $a
push 5
rem
push 0
comp
push $f.o
brtrue d
push $a
print.n
br c
.lbl b
push "Fizz"
print.n
br c
.lbl d
push "Buzz"
print.n
br c
.lbl e
push "FizzBuzz"
print.n
.lbl c
clf.o
inc $a
push $a
push 101
comp
push $f.o
brfalse a
ret
end
Commented and Ungolfed:
func main:
; Initilize the counter in the accumulator
push 1
pop $a
.lbl loop
; Reset the Comparison flag
clf.o
; $a % 15 == 0
push $a
push 15
rem
push 0
comp
; Jump to label "printFizzBuzz" if the Comparison flag is true
push $f.o
brtrue printFizzBuzz
; $a % 3 == 0
push $a
push 3
rem
push 0
comp
; Jump to label "printFizz" if the Comparison flag is true
push $f.o
brtrue printFizz
; $a % 5 == 0
push $a
push 5
rem
push 0
comp
; Jump to label "printBuzz" if the Comparison flag is true
push $f.o
brtrue printBuzz
; None of the above were true. Just print the number itself
push $a
print.n
br checkCounter
.lbl printFizz
; Print "Fizz"
push "Fizz"
print.n
br checkCounter
.lbl printBuzz
; Print "Buzz"
push "Buzz"
print.n
br checkCounter
.lbl printFizzBuzz
; Print "FizzBuzz"
push "FizzBuzz"
print.n
.lbl checkCounter
; Clear the Comparison flag
clf.o
inc $a
; $a == 101
push $a
push 101
comp
push $f.o
; Keep looping until the above is false
brfalse loop
ret
end
```
Answered by absoluteAquarian on December 10, 2021
Thanks, Neil, for providing a workaround for -15 bytes!