Neon Rocket

Even Neo is Impressed

RSS 2.0

Wicked Cool FizzBuzz in Perl

Stack_Overflow_website_logo

The FizzBuzz problem is a simple coding demonstration to write an application in any language that counts from 1 to 100:

Write a program that prints the numbers from 1 to 100. 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”.

I found the following on Stackprinter (deleted Stackoverflow questions) by  “ysth”; probably the best example of wicked-cool code obsfucation, ever.

(                       (
''))=~('('.'?'.'{'.("`"|
'%').('['^'-').('`'|'!').
('`'|',').'"'.('['^'+').(
         ((            (
         (             ((
         (             ((
         '['         ))))
          )))))^(')')).(
           '`'|")").(
         (              (
         '`'))|'.').('['^
         '/').'+'.('(').(
         '`'^'&').(('`')|
                     ((
                      ((
                    ')'))
                   ))).+(
                   "["^

         (              (
         '!'))).('['^'!')    .')'
         .'['.''.('$').    '_'.
         '%'.('^'^(('`')|     ((
         (              (
         '-')))))).(']').
         '.'.'('.('`'^'"'
         ).('['^'.').('['
                       ^
                       ((
                       ((
         '!'))))).(('[')^
         '!').')'.('[').
         ''.'$'.'_'
                        .
            '%'.('^'^('`'|'+'
         )).']'.'|'.'|'.''.
         '$'.'_'.','.''.'$'
         .+             (
         ((
           (
                  (
                  (
                  (
                  (
            '/')))))))).(
                  (
                  (
                  (
                   '`')))|
              '&').('`'|"/").(
           '['^')').('{'^'[').('^'
         ^('`'|'/'         )).".".
         ((                      '.'

         )                         )
         .                         (
         '^'^('`'|'/')).('^'^(('`')|
         '.')).('^'^('`'|'.')).('!'^
         (              (          (
         (              (          (
                        (          (
                        (          (
                       '+'         )
                      )))))        )
                                   )
                                  ))
                               ).'"'

         .              (
         '}').')');$:='.'    ^'~'
         ;$~='@'|"(";$^=    ')'^
         '[';$/='`'|".";     $,
                     ='('
         ^+           '}'
         ;($)         =(
         ('`'))|        (
         (  "!"));     (
         (    $:))=')'  ^
         (       '}');$~=
         (          '*')|
         ((            ((
         '`')
                     )));
         $^           =((
         '+'))         ^+
         '_';$/=        (
         (  "&"))|     (
         (    '@'));$,  =
         (       '[')&'~'
         ;          ($)=
         ((            ((
         ',')

         )))^                   '|';
         $:=('.')^         "~";$~=
           '@'|'(';$^=')'^"[";$/=
               '`'|'.';$,='('

                   ^'}';$
              ='`'|'!';$:=")"^
           '}';$~='*'|'`';$^="+"^
         ('_');$/=         '&'|'@';
         $,                      =((

           (             "[")))&
          ((           ('~')));$=
         ((           ','))^    '|'
         ;           ($:)=        ((
        '.'))^'~';$~='@'|'(';$^=")"^
         (          '[');          (
         (          $/))=          (
        '`')|'.';$,='('^'}';$=('`')|
         ((        '!')            )
         ;$:=    (')')^           (
           ('}'));$~=            (

         (
         (
         (
         (
         (
         (
         (
         (

         (                     ((
         '*')                ))  ))
            )))             )      )
               ))|          (      (
                   '`'       ));$^=
           '+'       ^((
         ((   ((        '_'
         )                  )))
         )     )              ;$/
          ='&'|                  '@'

          ;$,                    =
         '['                     &+
         ((                       ((
         (                         (
         (                         (
         (             ((          (
         '~'         ))))))      )))
         )));(    ($))  =','^"|";
          $:='.'^"~";    $~="@"|
            "(";$^=

         ')'^                   '[';
         $/=('`')|         ".";$,=
           '('^'}';$='`'|"!";$:=
               ')'^'}';$~='*'

          |+
         '`';
         ($^)

                   =('+')^
              '_';$/='&'|'@';$,
           ='['&'~';$=','^'|';$:=
         '.'^"~";         $~="@"|
         ((                      '('

         )                         )
         ;                         (
         $^)=')'^'[';$/='`'|".";$,=
         '('^'}';$='`'|'!';$:=")"^
         (              (          (
         (              (          (
         (              (          (
         (              (          (
         (             '}'        ))
         ))           ))))       )))
         ));(       $~)= '*'|'`';$^
          ='+'^"_";$/=   '&'|'@';
            $,='['&'~'      ;$=
              ","^
                        (
           '|');$:=('.')^
         '~';$~='@'|"(";
         $^=')'^('[');$/=
         ((
         ((
          (
         '`')))))|'.';$,=
         '('^'}';$="`"|
         '!';$:=')'^"}";
                     ($~)
         =(           '*'
         )|'`'         ;(
         $^)='+'        ^
         (  '_');$/     =
         (    '&')|'@'  ;
         (       $,)='['&
         (          '~');
         $            =(
         ',')
                     ^'|'
         ;(           $:)
         ='.'^         ((
         "~"));        (
         (  ($~)))=     (
         (    ('@')))|  (
         (       '('));$^
         =          ")"^
         ((            ((
         '[')

         )));                   ($/)
         ='`'|'.';         $,="("^
           '}';$='`'|'!';$:=")"^
               '}';$~='*'|'`'

                   ;$^='+'
              ^'_';$/='&'|"@";
           $,='['&'~';$=','^"|";
         $:=('.')^         "~";$~=
         ((                      '@'

           )             )|'(';$^
          =(           ')')^'[';$/
         =(           "`")|    '.'
         ;           ($,)=        ((
        '('))^'}';$='`'|'!';$:=")"^
         (          '}');          (
         (          $~))=          (
        '*')|'`';$^='+'^'_';$/=('&')|
         ((        '@')            )
         ;$,=    ('[')&           (
           ('~'));$=            (

         (
         (
         (
         (
         (
         (
         (
         (

         (                     ((
         ',')                ))  ))
            )))             )      )
               ))^          (      (
                   '|'       ));$:=
           '.'       ^((
         ((   ((        '~'
         )                  )))
         )     )              ;$~
          ='@'|                  '('

          ;(           ($^))=
         ((             (  (')'))))^
         (              ((      '[')
         )              );      ($/)
         =              ((      '`')
         )|            '.'      ;$,=
         "("^      '}';$      ='`'
          |'!';$:=')'^'}'       ;$~=
            '*'|'`';$^=         '+'^

         '_';                   ($/)
         ='&'|'@';         $,="["&
           '~';$=','^'|';$:="."^
               '~';$~='@'|'('

          ;(               ($^))=
         ')'^   '[';$/='`'|('.');$,=
         '('^      '}';$='`'|"!";

          $:               =")"^
         '}';   $~='*'|'`';$^=('+')^
         '_';      $/='&'|('@');$,=

           (             '[')&'~'
          ;(           $)=','^'|'
         ;(           ($:))=    '.'
         ^           "~";        $~
        ='@'|'(';$^=')'^'[';$/=('`')|
         (          '.');          (
         (          $,))=          (
        '(')^'}';$='`'|'!';$:=(')')^
         ((        '}')            )
         ;$~=    ('*')|           (
           ('`'));$^=            (

         (
         (
         (
         (
         (
         (
         (
         (

          ((
         '+')
       ))))))

           )             )))^'_';
          $/           ='&'|'@';$,
         =(           "[")&    '~'
         ;           ($)=        ((
        ','))^'|';$:='.'^'~';$~="@"|
         (          '(');          (
         (          $^))=          (
        ')')^'[';$/='`'|'.';$,=('(')^
         ((        '}')            )
         ;$=    ('`')|           (
           ('!'));$:=            (

         (
         ')')
            )^+
               '}'
                   ;$~
                     =((
                        '*'
                            ))|
                              '`'
                                 ;$^
                        =
         '+'^'_';$/='&'|"@";$,=
         '['&'~';$=','^'|';$:='.'^
         '~';$~='@'|'(';$^=')'^"[";
                        (      $/  )
                        =     ('`')|
                              ".";
              ($,)=
           '('^'}';$=
          '`'|'!';$:=')'
         ^+           ((
         (              (
         (              (
         (             ((
         '}')       ))))
           ))));$~='*'|
             "`";$^=
         (              (
         '+'))^'_';$/='&'
         |'@';$,='['&'~';
         $=','^('|');$:=
                     ((
                      ((
                    '.'))
                   ))^'~'
                   ;($~)

         =
         (                    (
         '@'))|'(';$^=')'^'[';$/=
         '`'|'.';$,='('^'}';$='`'
         |
         (
          ((
         '!')
         ));(

          $:
         )=((
         ')')

         )
         ^                    (
         '}');$~='*'|'`';$^="+"^
         '_';$/='&'|'@';$,='['&'~'
         ;
         (
                  $)=","^
             '|';$:='.'^'~';$~=
           '@'|'(';$^=')'^'[';$/=
          "`"|               ".";
         $,                       =(
         (                         (
         (                         (
         ((                      '('
          )))))               ))^((
           '}'));$='`'|('!');$:=
              ')'^'}';$~="*"|

                  ('`');$^=
             '+'^'_';$/='&'|'@'
           ;$,='['&'~';$=','^'|'
          ;($:)               ='.'^
         ((                       ((
         (                         (
         (                         (
         ((                      '~'
          )))))               )))))
           ;$~='@'|'(';$^=')'^'['
              ;$/='`'|".";#;#

Save the above Asciiart into a file called, for example, fizz.pl.

Then run it: perl fizz.pl

Enhanced by Zemanta
Bryan