Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Create the shortest possible obfuscated FizzBuzz implementation.

To be considered obfuscated, it should satisfy at least one of the following:

  1. Does not contain any of the words "Fizz", "Buzz", or "FizzBuzz"
  2. Does not contain the numbers 3, 5, or 15.
  3. Use any of the above in a misleading way.

Remember: The goal is to be short and hard to follow.

The code sample which inspired this question follows:

public class Default
        enum FizzBuzz
            Buzz = 1,
        public static void Main(string[] args)
            byte[] foo = 
            MemoryStream ms = new MemoryStream(foo);
            byte[] myByte = new byte[1];
                FizzBuzz fb;
                ms.Read(myByte, 0, 1);
                for (int i = 0; i < 4; i++)
                    fb = (FizzBuzz)(myByte[0] >> (2 * i) 
                         & (int)FizzBuzz.FizzBuzz);
                    Console.Out.WriteLine( (((int)fb > 0) ? "" + fb : "" 
                         + ((ms.Position - 1) * 4 + i + 1)));
            } while (ms.Position < ms.Length);
share|improve this question
add comment

25 Answers

up vote 17 down vote accepted

GolfScript, 75 69 65 60 59 chars


So, you'd think GolfScript by itself is already obfuscated, right? Well, just to follow the spec, I decided to have the program not contain "fizz", "buzz", nor the numbers 3, 5, nor 15. :-)

Yes, there are some numbers with multiples of 5, like 25, 35, 90, 100, and 6875. Are they red herrings? You decide. ;-)

share|improve this answer
Although I've written commentary for all my other GolfScript submissions, none will be forthcoming for this one. Rationale: chat.stackexchange.com/transcript/message/436819#436819 :-D –  Chris Jester-Young Jan 31 '11 at 4:34
add comment

Javascript 97 chars - no numbers at all

Numbers ? Who needs number when you have Javascript !


Note: There is an infinite loop that will alert you the sequence.

Bonus (666 chars)

  • No number
  • No letter (only zfor has been use in the whole script)


share|improve this answer
+1 - The second one blows my mind. –  Kyle Rozendo Jan 28 '11 at 13:03
Real programmers code just like the second one. –  user11 Jan 29 '11 at 11:57
@M28: Yep. That's one way to build job security...'cause finding someone who can maintain this code wouldn't be the easiest thing. –  Andy Feb 2 '11 at 5:07
You can use window["eval"]('"\\'+1+7+2+'"') for z. –  Nabb Feb 3 '11 at 2:25
@stevether It's mostly about abusing type conversion (ex.: +!![] is the same as 1 and ({}+"")[5] is the same as c) and abusing array notation to access method (ex.: window['eval']( is the same eval( ). –  HoLyVieR Aug 19 '12 at 5:06
show 6 more comments

PostScript, 96 bytes

So obfuscated it looks like random garbage.

1<~0o0@eOuP7\C+tf6HS7j&H?t`<0f>,/0TnSG01KZ%H9ub#H@9L>I=%,:23M].P!+.F6?RU#I;*;AP#XYnP"5~>cvx exec

Usage: $ gs -q -dNODISPLAY -dNOPROMPT file.ps

share|improve this answer
I bet that passes diehard. –  kaoD Feb 6 '13 at 4:27
add comment

Python - 78 chars

while 1:i+=1;print"".join("BzuzzizF"[::2*j]for j in(-1,1)if 1>i%(4+j))or i
share|improve this answer
Took me 10 minutes to understand what you did there. Nice and twisted. –  Trufa Jun 8 '11 at 15:04
add comment

C++: 886 chars

I've tried to hide the 'fizz' and the 'buzz'. Can you spot them?

#include <iostream>
#define d(a,b) a b
#define _(a,b) d(#b,#a)
#define b(b) _(b,b)
#define y _(i,f)c
#define x _(u,b)c
#define c b(z)
#define i int
#define p main
#define s char
#define q 810092048
#define h for
#define m 48
#define a ++
#define e ==
#define g 58
#define n 49
#define l <<
#define oe std::cout<<
#define v '\n'

int  p   (i,  s*t     ){i   j  =   q;h   (*(
i    *     )    t     =  m  ;  2     [     t
]?   0    :    1      ??(   t  ]    ?     a
1    [   t    ]       e  g  ?  1   [     t
]    =   48,  ++0     ??(    t]e   g?0   ??(

t]=  n   ,1[  t]=
2    [     t    ]
=m   :    1    :
1    :   a    0
[    t   ??)  ==g

?0[   t  ]   =49   ,1[
t  ]  =  m     :     1
;j=   (  j    /     4
)  |  (  (   j     &
3)l    28)   )oe   (j&

3?j  &   1?j  &2?
y    x     :    y
:x   :    t    )
l    v   ;    }
i    f   =m&  ~g;
share|improve this answer
That confuzzlesing my brane. –  muntoo Mar 11 '11 at 3:17
I think you meant membrane –  Korvin Szanto Dec 14 '11 at 22:34
add comment

DC (256 255 bytes)

Here it is, I tried (rather successfully, if I may say so myself) to hide anything except for letters, and +-[];:= (which are vital and impossible to obfuscate). It does segfault after getting to about 8482 or so on my machine, but that is to do with stack issues related to the way the recursion is implemented. The solution itself is correct. 255 bytes if you remove the whitespace (included for ease of reading) Enjoy:

share|improve this answer
+1 for dc. Even unobfuscated, of course, it's not especially readable. –  Jesse Millikan Mar 14 '11 at 21:29
add comment

Brainfuck - 626 656


Goes from 1 to 255

share|improve this answer
Turns out this actually does BuzzFizz. It gets FizzBuzz correct for %15, but it swaps %3 and %5. I may try to fix it, but for now my brain is officially F'ed –  CMP Dec 15 '11 at 23:32
Fixed at cost of 30. Could have golfed it more with effort, but I have already wasted enough time on this. –  CMP Dec 15 '11 at 23:36
add comment

Haskell - 147 142 138 characters

zZ%zz=zZ zz$zZ%zz
z=zipWith3(((#).).(++))(bu%"Fi")(fi%"Bu")$map show[1..]

The code is 19 characters longer than it needs to be, but I thought the aesthetics were worth it! I believe all three "objectives" are satisfied.

> take 20 z
share|improve this answer
Hi, I try to get to understand your code, but I am unable to run it! The function zZ' is applied to six arguments, but its type (a0 -> b0 -> c0) -> [a0] -> [b0] -> [c0]' has only three –  RobAu Jan 31 '13 at 20:07
And I, while being able to run it, only get ["1","2","3","4","5","6"...]. –  Artyom Kazak Feb 1 '13 at 18:14
Fixed - The right version was still on my disk... must have mis-pasted the text long ago! –  MtnViewMark Feb 5 '13 at 4:52
add comment

Scala, 295 characters

object F extends Application{var(f,i,z)=("",('z'/'z'),"FBiuzzzz");while(i<(-'b'+'u'+'z'/'z')*('¥'/'!')){if(i%(-'f'+'i'/('z'/'z'))==0)f+=z.sliding(1,2).mkString;if(i%((-'b'+'u'+'z'/'z')/('f'/'f'+'i'/'i'+'z'/'z'+'z'/'z'))==0)f+=z.drop(1).sliding(1,2).mkString;if(f=="")f+=i;println(f);i+=1;f="";}}
share|improve this answer
add comment

Ruby - 165 characters

(1..100).each{|i|i%0xF==0? puts(["46697A7A42757A7A"].pack("H*")):i%(0xD-0xA)==0? puts(["46697A7A"].pack("H*")):i%(0xF-0xA)==0? puts(["42757A7A"].pack("H*")):puts(i)}

This was my first attempt at code golf. I had a lot of fun. =)

share|improve this answer
add comment

JavaScript 111 chars - no key numbers


share|improve this answer
add comment

C# - 218 characters

using System;class D{static void Main(){int l,i,O=1;l++;string c="zz",a="fi",b="bu";l++;l++;i=l;i++;i++;for(;O<101;O++)Console.WriteLine(((O%l)>0&&1>(O%i))?a+c:(1>(O%l)&&(O%i)>0)?b+c:(1>(O%l)&&1>(O%i))?a+c+b+c:O+"");}}

Could be shortened if I introduced other numbers like so: (210 characters total)

using System;class D{static void Main(){int l=1,i,O=1;string c="zz",a="fi",b="bu";l+=2;i=l;i+=2;for(;O<101;O++)Console.WriteLine(((O%l)>0&&1>(O%i))?a+c:(1>(O%l)&&(O%i)>0)?b+c:(1>(O%l)&&1>(O%i))?a+c+b+c:O+"");}}

Decided to remove the obvious word fizz and buzz and go for slightly more obfuscation. Second one is shorter than the first one but is slightly more direct on what's occurring in the addition.

share|improve this answer
add comment

C (237 209 characters)

#define e printf  

Though I'm not sure this conforms to the C standard :)
It works, though. On Linux using GCC, that is.

share|improve this answer
add comment


use MIME::Base64;print map{map{(++$i,'Fizz','Buzz','FizzBuzz')[$_]."\n"}(3&ord,3&ord>>2,3&ord>>4,3&ord>>6)}split//,decode_base64"EAZJMIRBEgxhkARDGCTBEAZJMIRBEgxhkA"

One I made in 2009. It's pretty easy to figure out, though.

Edit: Darn, it uses "Fizz" and "Buzz!" :( I thought I changed that. Nevermind then.

share|improve this answer
add comment

Python 3 - 338

import sys
def fibu():
        (F,I,B,U),i,u,z=sys._getframe(0).f_code.co_name,0xf,0xb,lambda x,y:x%((i//u)+(i^u))==u>>i if y>u else x%(((u<<(u>>2))&i)>>(u>>2))==i>>u
        A,RP = "",chr(ord(U)+((i//u)+(i^u)))*2
        for x in range(100):print(x if not (z(x,u)or z(x,i))else A.join((F+I+RP if z(x,u)else A,B+U+RP if z(x,i)else A)))

This is my first golf. Not the shortest, but it's pretty ugly! None of the forbidden numbers or string literals. Firp, Burp!

share|improve this answer
add comment

Python - 157

from itertools import cycle as r
[c(c(c(z+y,'x','fix'),'y','bux'),'x','zz').strip() or x for z,y,x in zip(r('  y'),r('    x'),range(1,101))]

Not quite the shortest, but I hope the reader will appreciate the pure functional style and extensibility to arbitrarily long counts.

share|improve this answer
add comment

This isn't exactly golfed, its about 120 lines.

I thought I'd do something that took advantage of all the fun potential for undefined behavior with C++ memory management.

#include <iostream>
#include <string>

using namespace std;

class Weh;
class HelloWorld;

class Weh

    string value1;
    string value2;
    void (*method)(void * obj);


    string getV1();

    static void doNothing(void * obj);

class HelloWorld
    static const int FOO = 1;
    static const int BAR = 2;
    static const int BAZ = 4;
    static const int WUG = 8;

    string hello;
    string world;
    void (*doHello)(HelloWorld * obj);


    void * operator new(size_t size);

    void tower(int i);
    const char * doTower(int i, int j, int k);

    static void doHe1lo(HelloWorld * obj);

    method = &doNothing;

void Weh::doNothing(void * obj)
    string s = ((Weh *) obj)->getV1();
    ((HelloWorld *) obj)->tower(1);

string Weh::getV1()
    value1[0] += 'h' - 'j' - 32;
    value1[1] += 'k' - 'g';
    value1[2] += 'u' - 'g';
    value1[3] = value1[2];
    value2 = value1 = value1.substr(0, 4);

    value2[0] += 'd' - 'h';
    value2[1] += 'w' - 'k';
    value2[2] = value1[2];
    value2[3] = value1[3];

    return "hello";

void * HelloWorld::operator new(size_t size)
    return (void *) new Weh;

    hello = "hello";
    world = "world";

void HelloWorld::doHe1lo(HelloWorld * obj)
    cout << obj->hello << " " << obj->world << "!" << endl;

void HelloWorld::tower(int i)
    doTower(0, 0, i);
    tower(i + (FOO | BAR | BAZ | WUG));

const char * HelloWorld::doTower(int i, int j, int k)
    static const char * NOTHING = "";
    int hello = BAR;
    int world = BAZ;
    int helloworld = FOO | BAR | BAZ | WUG;

    if ((hello & i) && (world & j))
        cout << this->hello << this->world << endl;
    else if (hello & i)
        cout << this->hello << endl;
        cout << doTower(0, j + 1, k + 1);
    else if (world & j)
        cout << this->world << endl;
        cout << doTower(i + 1, 0, k + 1);
        cout << k << endl;
        cout << doTower(i + 1, j + 1, k + 1);

    return NOTHING;

int main()
    HelloWorld * h = new HelloWorld;
share|improve this answer
add comment

Ruby - 89 chars

puts (0..99).map{|i|srand(1781773465)if(i%15==0);[i+1,"Fizz","Buzz","FizzBuzz"][rand(4)]}

I can't take credit for this piece of brilliance, but I couldn't leave this question without my favorite obfuscated implementation :)

The implementation above was written by David Brady and is from the fizzbuzz ruby gem. Here is the explanation from the source code:

Uses the fact that seed 1781773465 in Ruby's rand will generate the 15-digit sequence that repeats in the FizzBuzz progression. The premise here is that we want to cleverly trick rand into delivering a predictable sequence. (It is interesting to note that we don't actually gain a reduction in information size. The 15-digit sequence can be encoded as bit pairs and stored in a 30-bit number. Since 1781773465 requires 31 bits of storage, our cleverness has actually cost us a bit of storage efficiency. BUT THAT'S NOT THE POINT!

Ruby - 87 chars

puts (0..99).map{|i|srand(46308667)if(i%15==0);["FizzBuzz","Buzz",i+1,"Fizz"][rand(4)]}

Here's a different version which uses a shorter seed but the lookup table is in a different order. Here is the explanation from the source code:

The first implementation (89 chars) adheres to the specific ordering of 0=int, 1=Fizz, 2=Buzz, 3=FizzBuzz. It may be possible to find a smaller key if the ordering is changed. There are 24 possible permutations. If we assume that the permutations are evenly distributed throughout 2*31 space, and about a 50% probability that this one is "about halfway through", then we can assume with a decent confidence (say 20-50%) that there is a key somewhere around 1.4e+9 (below 2*28). It's not much gain but it DOES demonstrate leveraging rand's predefined sequence to "hide" 30 bits of information in less that 30 bits of space.

Result: The permutation [3,2,0,1] appears at seed 46308667, which can be stored in 26 bits.

share|improve this answer
add comment

K, 155

{m:{x-y*x div y};s:{"c"$(10-!#x)+"i"$x};$[&/0=m[x]'(2+"I"$"c"$49;4+"I"$"c"$49);s"<`rs<pvw";0=m[x;2+"I"$"c"$49];s"<`rs";0=m[x;4+"I"$"c"$49];s"8lrs";x]}'!100

I could golf it quite a bit but I'd rather it be more obfuscated.

share|improve this answer
add comment

Squeak (4.4) Smalltalk 206 bytes

|f i zz b u z|z:=''.b:=28r1J8D0LK. 1to:100do:[:o|0<(f:=(i:=(zz:=b\\4)//2*4)+(u:=zz\\2*4))or:[z:=z,o].b:=zz<<28+(b//4).z:=z,((z first:f)replaceFrom:1to:f with:28r1A041FHQIC7EJI>>(4-i*u*2)startingAt:1),'

Or same algorithm with less explicit messages, same number of characters

|l f i zz b u z|z:=#[].b:=36rDEB30W. 1to:100do:[:o|0<(f:=(i:=(zz:=b\\4)//2)+(u:=zz\\2)*4)or:[z:=z,('',o)].b:=zz<<28+(b//4).l:=36r2JUQE92ONA>>(1-u*i*24).1to:f do:[:k|z:=z,{l-((l:=l>>6)-1<<6)}].z:=z,'

My apologizes to Alan Kay for what I did to Smalltalk.
Some of these hacks are portable across Smalltalk dialects, some would require a Squeak compatibility layer...

Note that if you execute in a Workspace, you can omit declarations |f i zz b u z| and gain 14 characters.

If we can afford 357 characters (315 with single letter vars), then it's better to avoid trivial #to:do: loop:

|fizz buzz if f fi zz b u bu z|f:=fizz:=buzz:=0.z:=#[].b:=814090528.if:=[:i|i=0or:[fi:=28.zz:=27<<7+i.u:=26.(fizz:=[zz=0or:[z:=z,{(u:=u//2)\\2+1+(zz+((fi:=fi//2)\\2+2-(zz:=zz//8)*8)*4)}.fizz value]])value]].(buzz:=[(f:=f+1)>100or:[(fi:=(zz:=b\\4)//2*17)+(bu:=zz\\2*40)>0or:[z:=z,('',f)].b:=zz<<28+(b//4).if value:fi;value:bu.z:=z,'
'.buzz value]])value.'',z
share|improve this answer
add comment

C 216 bytes

#define t(b) putchar(p+=b);
main(p,v,c){p=70;for(v=c=1;v<=p*2-40&&!(c=0);++v){if(!(v%(p/23))){t(0)t(35)t(17)t(0)++c;}if(!(v%(p/(14+c*9)))){t(-56+!c*52)t(51)t(5)t(0);++c;}if(c){t(-112)p+=60;}else printf("%i\n",v);}}
share|improve this answer
add comment

PHP - 157 154 95 chars

<?$x="zz";for(;++$i<=100;){?> <?$j=$i%(4-1)^0?"":"Fi$x";$j.=$i%(4+1)^0?"":"Bu$x";echo$j?$j:$i;}

And no whitespace! Only one space!

share|improve this answer
add comment

Haskell 226 bytes, including the whitespace for layout ;)

z=[fI$ (++)            \ 
(fi zz 1 "Fi" )        \  
(fi zz 2 "Bu" )        \ 
:[show zz]  | zz<-[1..]]
fI (zZ:zz)  | zZ==[]   \
= concat zz | 1==1=zZ  
fi zZ bu zz | zZ%bu=   \
(zz++"zz")  | 1==1=[] 
bu%zz=mod bu (zz*2+1)==0

The 'real' code is 160 bytes and can be compressed, but loses fizz-buzz-ness then.

Run it (for nice output):

putStrLn (unwords (take 20 z ))


1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz 
share|improve this answer
add comment

Python, 180 chars

from random import*;seed(0);_,y=''.join(sample('zzzzuiFB',8)),5**2<<2
print chr(int(`y`[::2])).join(filter(bool,map(lambda z:(not z%(y>>5))*_[:1<<2:]+(1>z%5)*_[1<<2::],range(1,y))))
share|improve this answer
add comment

C Solution

    #include  <stdio.h>
    #define a b b b b b
    #define b c c c c c
    #define c d d d d d
   #define  h(k,s)k?s:""
  #define x !(n%('0'>>4))
  #define y !(n%('P'>>4))
  #define d if(100>=++n)\
int main(){static int n; a}
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.