Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-8081-

fizzbuzz

Name: übermench 2011-12-26 15:04

just wanted to post my awesome fizzbuzz implementation
#include <stdio.h>
#include <stdlib.h>

void main(int j) {
  printf(((char*[]){"%d\n","fizz\n","buzz\n","fizzbuzz\n"})[!(j%3)+!(j%5)*2], j);
  (&main + (&exit - &main)*(j/100))((j+1)*(1-j/100) );
}

Name: Anonymous 2011-12-26 17:19

>>1
This is crap.

Name: Anonymous 2011-12-26 17:56

i=0;
while [[ $i -lt 100 ]]; do
    echo -n "$i: "
    [[ $[i % 3] == 0 ]] && echo -n "fizz"
    [[ $[i % 5] == 0 ]] && echo "buzz" || echo
    i=$[i + 1]
done


u jelly OP?

Name: Anonymous 2011-12-26 18:53

>>3
I prefer marmalade, but thank you anyway.

Name: Anonymous 2011-12-26 19:12

a;main(){while(a++<100){!(a%15)?printf("FizzBuzz\n"):!(a%5)?printf("Buzz\n"):!(a%3)?printf("Fizz\n"):printf("%d\n",a);}}

Name: Anonymous 2011-12-26 20:12

the best fizzbuzz uses FORMAT

Name: Anonymous 2011-12-26 20:23


1.upto 100 do |a|
b = false   
if (a % 3 == 0) then
b = true; print "Fizz" end
if (a % 5 == 0) then
b = true; print "Buzz" end
unless b print a end
print "\n"
end

Name: übermench 2011-12-26 20:55

>>3,5,7
eww unoptimized shit.

Name: Anonymous 2011-12-26 21:29

>*2
EWW, UNOPTIMIZED SHIT

Name: Anonymous 2011-12-27 0:26

>1+:55+55+*`#v_v           @
 v             <           
             >             ^
         > :0\25*           v
     >:5%|                  
         >  0"zzuB"25*     v
 >:3%|                     
         >  0"zziF"25*     v
     >:5%|                 
         >  0"zzuBzziF"25* v
^     $  <                 
   ,>:#._^                  >
    >:#,_^                 >

Name: Anonymous 2011-12-27 0:28

Is it possible to make a fizzbuzz program in Lisp?

Name: Anonymous 2011-12-27 0:30

>>10
>1+:55+55+*`#v_v           @
 v             <          
             >             ^
         > :0\25*           v
     >:5%|                 
         >  0"zzuB"25*     v
 >:3%|                    
         >  0"zziF"25*     v
     >:5%|                
         >  0"zzuBzziF"25* v
^     $  <                
   ,>:#._^                  >
    >:#,_^                 >


Herp.

Name: Anonymous 2011-12-27 0:35

>>11
no

Name: Anonymous 2011-12-27 3:47

section .data
fizz:   db      "Fizz", 0
buzz:   db      "Buzz", 0
fmt:    db      "%d", 0
three:  db      3
five:   db      5

section .text
        global  _start
        extern  putchar
        extern  printf
        extern  exit
_start:
        mov     ecx, 1
.loop:
        mov     [esp+4], ecx
        cmp     ecx, 100
        jg      .fin

        mov     ax, cx
        div     byte [three]
        test    ah, ah
        jz      .fizz

        mov     ax, cx
        div     byte [five]
        test    ah, ah
        jz      .buzz

        mov     [esp-4], ecx
        mov     dword [esp], fmt
        call    printf
.end:
        mov     byte [esp], 0xa
        call    putchar

        mov     ecx, [esp+4]
        inc     ecx
        jmp     .loop
.fin:
        mov     byte [esp], 0
        call    exit
.fizz:
        mov     dword [esp], fizz
        call    printf

        mov     ax, [esp+4]
        div     byte [five]
        test    ah, ah
        jz      .buzz

        jmp     .end
.buzz:
        mov     dword [esp], buzz
        call    printf

        jmp     .end

Name: Anonymous 2011-12-27 3:57

>>14
omg, so many branches, unoptimized

Name: Anonymous 2011-12-27 4:08

further optimized it by removing those unnecessary division, multiplication operations. now it can print over 9000 fizzbuzzes per microsecond

#include <stdio.h>
#include <stdlib.h>

void main(int j) {
  printf(((char*[]){"%d\n","fizz\n","buzz\n","fizzbuzz\n"})[!(j%3)|!(j%5)<<1], j);
  (&main + (&exit - &main)*!(j-100))((j+1)*!!(j-100));
}

Name: Anonymous 2011-12-27 4:22

Step aside faggots


#define procedure void
#define main:() main() {
#define for ;for(int
#define to ; i <=
#define do ;++i){
#define is ==
#define isnt !=
#define and &&
#define or ||
#define := =
#define end );}}
#define mod %
#define print ;puts(
#define let ;char
#define [...] []
#define if ;if(
#define then )

procedure main:()
  let op[...] := { "", "Fizz\n","Buzz\n","FizzBuzz\n" }
  let in := 0
  for i := 1 to 100 do
    in := 0
    if i mod 3 is 0 then
      in := 1
    if i mod 5 is 0 then
      in := in + 2
    print op
in
  end

Name: Anonymous 2011-12-27 4:36

>>17
PIG DISGUSTING!

Name: Anonymous 2011-12-27 5:37

>>17
#define := =
#define [...] []

That's not a C compiler.

Name: Anonymous 2011-12-27 6:21

Which Touhou would fizz?

Name: Anonymous 2011-12-27 6:21

Which Touhou would buzz?

Name: Anonymous 2011-12-27 6:36

check them

Name: Anonymous 2011-12-27 8:03

>>8

How would you optimize >>7

Name: Anonymous 2011-12-27 9:33


10 LET A=0
20 LET A=A+1
30 IF A MOD 15=0 THEN 80
40 IF A MOD 3=0 THEN 100
50 IF A MOD 5=0 THEN 120
60 GOTO 140
80 PRINT"FIZZBUZZ"
90 GOTO 20
100 PRINT"FIZZ"
110 GOTO 20
120 PRINT"BUZZ"
130 IF A<100 THEN 20
131 SLEEP
132 END
140 PRINT A
150 GOTO 20

Name: Anonymous 2011-12-27 10:33


(defun mult? (n m)
  (eql (mod n m) 0))

(defun fizz-buzz ()
  (dotimes (x 100)
    (if (mult? (1+ x) 3)
    (format t "Fizz"))
    (if (mult? (1+ x) 5)
    (format t "Buzz")
    ;; else
    (if (not (mult? (1+ x) 3))
        (format t "~d" (1+ x))))
    (format t "~%")))


Help me OPTIMIZE this, I'm still learning.

Name: Anonymous 2011-12-27 10:52

>>25
Ups, fucked up indentation. Fucking emacs.

Name: Anonymous 2011-12-27 11:04

>>26
It's actually your fault, not Emacs' fault.

Name: Anonymous 2011-12-27 11:36

>>25
Protip: cond and loop

also, zerop.

Name: Anonymous 2011-12-27 11:52

>>25
Here, an IDIOMATIC AND EXTENSIBLE version for you.

(defun divisible-by-p (num div)
  (zerop (mod num div)))

(defun fizzablep (num) (divisible-by-p num 3))
(defun buzzablep (num) (divisible-by-p num 5))

(defun fizz-buzz ()
  (loop for x from 1 to 100 do
       (when (fizzablep x)
         (princ "Fizz"))
       (if (buzzablep x)
           (princ "Buzz")
           (when (not (fizzablep x))
             (princ x)))
       (terpri)))

Name: Anonymous 2011-12-27 12:22

>>28
You're right, with loop I can start the count at 1 instead of doing (1+ x). My code was very UNOPTIMIZED ;_;

>>29
That's some fucking good lisp code. I didn't even know that princ and terpri existed.

Thanks guys.

Name: Anonymous 2011-12-27 14:00

>>29

you are leading him astray!!

Name: übermench 2011-12-27 14:28

I don't get it guys, I wrote a fizzbuzz with no conditional. And it is in C, not a lesser language like lisp. why are you still working on the problem?

Name: Anonymous 2011-12-27 14:33

>>32
* no conditional branches

Name: Anonymous 2011-12-27 14:34

And it is in C, not a lesser language like lisp.
Nice try, FrozenVoid.

Name: Anonymous 2011-12-27 15:03

>>1
>übermench

It's written ```````````````````````````````````übermensch''''''''''''''''''''''''''''''''''

Name: Anonymous 2011-12-27 15:46

>>19
get a better compiler

Name: Anonymous 2011-12-27 16:21

Hi... sorry i'm late

My perl6 version

my $cycle = 0;
for ( (1 .. 100) X% [(3,5)] ) -> $fizz, $buzz {
   print ("fizz", "buzz", ++$cycle) >>x>> ($fizz==0, $buzz==0, ($fizz > 0) && ($buzz > 0 ));
   say
}

Name: 37 2011-12-27 16:46

>>37
This one is a bit shorter


my $cycle = 0;
for ( (1 .. 100) X% [(3,5)] ) -> $fizz, $buzz {
   print ("fizz", "buzz", ++$cycle, "\n") >>x>> ($fizz==0, $buzz==0, ($fizz > 0 < $buzz), 1);
}

Name: Anonymous 2011-12-27 20:21

My ``FHQ9+'' version:
f

Name: Anonymous 2011-12-27 20:46

Perl golf version:
print$_%15?$_%5?$_%3?$_:Fizz:Buzz:FizzBuzz,"\n"for 1..100

Name: Anonymous 2011-12-27 22:50

>>36
Any compiler that compiles that is not a real C compiler, those are not valid identifiers for a macro, hate to tell you but your compiler is shit.

Name: Anonymous 2011-12-28 3:21

>>17

proggles.c:12:9: error: macro names must be identifiers

Name: Anonymous 2011-12-28 3:37

>>42
get a better compiler with a better preprocessor

>>41
u jelly that my own compiler has a better preprocessor than your shitty default gnu one?


god forbid we allow more customization.

Name: Anonymous 2011-12-28 3:43

>>43
Name a better compiler, then.

Name: Anonymous 2011-12-28 3:43

>>43
It's not a valid preprocessor, it does not comply to the standard, therefore it's shit, anyone can make a non-conformant piece of crap.

Name: VIPPER 2011-12-28 4:48

Why not make perl the preprocessor?

Name: Anonymous 2011-12-28 5:02

>>44
my own compiler

I'm amazed people on /prog/ aren't capable of making their own preprocessor for their own compiler or hell even a preprocessor that then pipes into gcc,tcc,etc

>>45
standard is shit

Name: Anonymous 2011-12-28 5:05

>>47
You are shit

Name: Anonymous 2011-12-28 5:07

>>47
standard is shit
And who are you? Which language committees have been in?

Name: Anonymous 2011-12-28 5:09

>>47
Take your toy language elsewhere.

Name: Anonymous 2011-12-28 5:31

>>50
Are you calling C a toy language now?

>>49
I am someone clearly smarter than you

>>48
u mad?

Name: Anonymous 2011-12-28 5:59

>>51
Are you calling C a toy language now?
No, the language you're using a silly toy language, it's not C.
C is a good language.

Name: Anonymous 2011-12-28 7:48

>>51
u mad

And that's how all arguments of >>51-san became meaningless.

back to /b/ with you

Name: Anonymous 2011-12-28 8:07

>>51,53
/polecat kebabs/

Name: Anonymous 2011-12-28 9:14

The reason using a non-compliant C compiler is wrong is because non-standard code will not compile on a compliant compiler. If your code is only going to compile on your compiler on your machine then go ahead and use non-standard stuff, but if you're posting it on the Internet where everyone uses different compilers, and you expect people to not be annoyed by your use of non-standard 'features', then you're a retard.

Name: Anonymous 2011-12-28 11:59

>>53-54 fuck off and die you fucking fagstorm

>>55
A useful subset of GNU C is followed by gcc itself, clang and tcc.

Name: Anonymous 2011-12-28 13:28

>>56
A useful subset of GNU C is followed by gcc itself, clang and tcc.
ICC as well, and that's because most of the GNU extensions are sane and useful, your shitty broken preprocessor isn't, it's fucking harmful and retarded. So fuck off with your toy language you piece of shit moron.

Name: Anonymous 2011-12-28 13:40

Check your lips at the door woman, shake your hips like battleships.

Name: Anonymous 2011-12-28 14:19

>>57
Post >>56 was the first one I made in this thread, ``fatflaps''.

Name: Anonymous 2011-12-28 14:21

>>59
Inconsequential, you're still a fucking retard.

The discussion was about a non-compliant compiler, the ones you posted are compliant, just to another language, GNU-C.

Name: Anonymous 2011-12-28 14:24

>>1..1000
fuck off, fuckfucks.

Name: Anonymous 2011-12-28 14:25

>>60
Fuck you man, I'm high and trolling your faggot ass is my highlight of the day.

Name: Anonymous 2011-12-28 15:02

not enough python

Name: Anonymous 2011-12-28 15:17

This thread?

PROG QUALITY!

Name: Anonymous 2011-12-28 15:43

for i = 0,99 do print(({"fizz","buzz","fizzbuzz"})[math.floor(0x30490610/2^(i*2%30)%4)] or i+1) end
Terrible! back to javascript!

Name: Anonymous 2011-12-28 16:06

I ran this code and it hacked my virus.

Name: Anonymous 2011-12-28 16:31

>>62
>>60
>>55
Y'all niggas so mad. I use gcc just like you, but I pipe my files through my perl preprocessor script which then compiles via gcc. Keep on hatin

Name: Anonymous 2011-12-28 16:32

>>67
That still doesn't make it C, or non-shit.

Name: Anonymous 2011-12-28 16:37

>>68
Changing preprocessor rules =/= making a new language

To you anyone that uses non-standard C is then using some silly toy language.

Name: Anonymous 2011-12-28 16:41

>>69
Standard C preprocessor is a separate language to Standard C. You are using non-standard C preprocessor, which is yet another language; the third language referenced in this post.

Name: Anonymous 2011-12-28 16:43

>>70
Reference my anus.

Name: Anonymous 2011-12-28 16:55

>>71
________________________________
[1] ISO/IEC 9899:1990
[2] ISO/IEC 9899:1999
[3] http://en.wikipedia.org/wiki/C_preprocessor -- The
language of preprocessor directives ...

Name: Anonymous 2011-12-28 17:33

I hope you guys don't use that toy language that's gnu gcc C with their non-standard preprocessor abilities.

Name: Anonymous 2011-12-28 17:34

>>73
fuck you M$ fag$torm

Name: Anonymous 2011-12-28 18:01

>>74
if you're going to whine about someone elses non-standard use then don't be a hypocrite and do it yourself with GNU gcc shit.

I'm ashamed to even hear that /prog/iganites are using gcc freedom at all costs

Name: Anonymous 2011-12-28 18:22

>>75

It's ok if your code remains within the standard, and you can give gcc options to only accept standard C (although in my experience, it still accepts things like nested functions in ansi mode).

Name: Anonymous 2011-12-28 19:54

Name: Anonymous 2011-12-28 20:09

>>77

                  / ̄∧_∧ ̄ ̄ ̄ // ̄\\
           __ ⊂/__(´∀` )__  /_⊃___| |\フ ヽ  CFLAGS JUST KICKED
       ,  ´_  /   / ̄ ̄ __ / ̄ ヽ    __ヽ ̄ ̄ |  IN, YO!
      /∠__/―/-。―/――∠_/__∧  |       | ∧_.| 
      ,========――´=============/⌒ヽ=|.=====| | ヽ ̄〕 
      | _   |GENTOO|    _  ″  |⌒| |/   __ /|  )ノ    vroom
      )_旧_∈≡≡≡≡∋_旧_″_|| ノ丿_ -――┘ 丿      vroom!
       \ \_ノ  ̄ ̄ ̄三三三\ \_ノ    三三三三 
        三三三三三三三三三三三三三三三三三三三三三三三三
           三三三三三三三三三三三三三三三三三三三三三三三
              三三三三三三三三三三三三三三三三三三三三三三三三三三
                      三三三三三三三三三三三三三三三三三三
                            三三三三三三三三三三三

Name: Anonymous 2011-12-28 20:58

>>78
Nice kopipe, ``faggot''.

Name: Anonymous 2011-12-28 21:03

>>77

it was around three years ago.

Name: Anonymous 2011-12-28 21:06

>>77
what kind of humongous faggot would use -pedantic?

Name: >>77 2011-12-28 21:42

>>81

I thoought it might have been the old version, but when I compile that code without the -pedantic flag, it works fine and doesn't complain about the nested function. One would expect the -ansi flag to be sufficient. But oh well. I guess if you want your code to be portable across compilers, you better use -pedantic.

Name: >>82 2011-12-28 21:53

Name: Anonymous 2011-12-29 0:36

>>69
You're using a different language, whatever piece of shit toy language you're using it does not conform to the C standard, therefore it must be a different language.

Name: Anonymous 2011-12-29 0:43

>>84
GNU GCC C is a toy language, say it faggot. FUCKING SAY IT

Name: Anonymous 2011-12-29 0:52

>>85
ANSI C is a faggot toy language, real men use GNU C.

Name: Anonymous 2011-12-29 0:55

>>86
K & R C > ANSI C > ISO C > GNU C > TOY LANGUAGE C

Name: Anonymous 2011-12-29 1:00

>>87
you must be a faggot. enjoy your AIDS

Name: Anonymous 2011-12-29 1:36

Name: Anonymous 2011-12-29 5:28

>>87
In 1983, the American National Standards Institute (ANSI) formed a committee, X3J11, to establish a standard specification of C. In 1989, the standard was ratified as ANSI X3.159-1989 "Programming Language C". This version of the language is often referred to as ANSI C, Standard C, or sometimes C89.

In 1990, the ANSI C standard (with formatting changes) was adopted by the International Organization for Standardization (ISO) as ISO/IEC 9899:1990, which is sometimes called C90. Therefore, the terms "C89" and "C90" refer to the same programming language.

ANSI, like other national standards bodies, no longer develops the C standard independently, but defers to the ISO C standard. National adoption of updates to the international standard typically occurs within a year of ISO publication.

`
>implying ANSI C != ISO C

Name: Anonymous 2011-12-29 7:05

>>88
No.

Name: Anonymous 2011-12-29 10:37

>>85
GNU-C is not a toy language, it has a well adopted standard, every major compiler supports it.

The shit you're using is a shitty toy language, and you're a fucking retard.

Name: Anonymous 2011-12-29 14:23

>>92
every major compiler supports it

which is why there are things you can do in the GNU preprocessor and not in any other compilers preprocessor... right?

moron stop using your toy languages and use Standard C

Name: Anonymous 2011-12-29 14:25

This thread was about fizz, you guys should be ashamed of yourselves.

Name: Anonymous 2011-12-29 15:21

Yall niggas postin in a fag thread.

Name: Anonymous 2011-12-29 19:38

>>93
implying GNU C is a toy

Don't change these.
Name: Email:
Entire Thread Thread List