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

Pages: 1-

fizzbuzz

Name: Anonymous 2012-03-13 7:15

#include <stdio.h>
int main(void) {
    int i = 0;
    char *s[] = {"%d\n", "fizz\n", "buzz\n", "fizzbuzz\n"};
    while (i++ < 100)
        printf(s[(!(i%3))|((!(i%5))<<1)], i);
    return 0;
}


http://codepad.org/nkFXJqlG

Name: Anonymous 2012-03-13 8:07

Yep, it's a Fizzbuzz.

Name: Anonymous 2012-03-13 8:32

more like
int main(frozenvoid) {

amirite? xD

Name: Anonymous 2012-03-13 9:46

printf(s[(!(i%3))|((!(i%5))<<1)], i);

It's like Lisp and C++ had a retarded baby!

Name: Anonymous 2012-03-13 10:18

Yep, it's an undefined behaviour.

Name: Anonymous 2012-03-13 10:51

OMG OPTIMIZED

#include <stdio.h>
char *s[] = {"%d\n", "fizz\n", "buzz\n", "fizzbuzz\n"};
int main(int i) {(i<101)?(printf(s[(!(i%3))|((!(i%5))<<1)], i),main(i+1)):0;}

Name: Anonymous 2012-03-13 12:12

>>6
Yep it's a perfect copy of the original post, but merely stripped of any already nonexistant readability.

Congratulations.

Name: Anonymous 2012-03-13 12:25

If it ain't fizzin', it's buzzin'.

Name: Anonymous 2012-03-13 13:16

Time for some benchmarks.

- GCC 4.6.3 -march=native -mtune=native -O3
- glibc 2.15
- Linux 3.2.9 SMP PREEMPT
- i5 2500K clocked at 3.30GHz
- stdout is /dev/null
- 50000000 iterations
- Programs are run two times and the best result is used.

>>1's fizzbuzz:
real    0m3.034s
user    0m3.023s
sys    0m0.007s


My fizzbuzz:
real    0m1.696s
user    0m1.677s
sys    0m0.017s


#include <stdio.h>

void fizzbuzz(unsigned int n)
{
  char *s[] = {"%d\n", "Fizz\n", "Buzz\n", "FizzBuzz\n"};
  unsigned int coarse = n >> 4;
  unsigned int i = 1;

  for (; coarse; coarse--) {
    printf("%d\n"
           "%d\n"
           "Fizz\n"
           "%d\n"
           "Buzz\n"
           "Fizz\n"
           "%d\n"
           "%d\n"
           "Fizz\n"
           "Buzz\n"
           "%d\n"
           "Fizz\n"
           "%d\n"
           "%d\n"
           "FizzBuzz\n",
           i, i + 1, i + 3, i + 6, i + 7, i + 10, i + 12, i + 13);
    i += 15;
  }

  i--;
  while (i++ < n)
    printf(s[(!(i%3))|((!(i%5))<<1)], i);
}

int main() {
  fizzbuzz(100);

  return 0;
}

Name: Anonymous 2012-03-13 13:21

>>5
Wanna point out where, shithead?

Name: Not >>5 2012-03-13 13:24

>>11
Calling printf with the wrong number of parameters might be undefined behaviour.

Name: 11 2012-03-13 13:29

Actually the norm says it is perfectly safe to pass more arguments than described in the format string.

Name: Anonymous 2012-03-13 13:32

>>11
No, extra parameters to printf are ignored, ``faggot''. Try again.

Name: Anonymous 2012-03-13 13:45

>>9
can you test this too

#include <stdio.h>
 
#define N 100
 
int main(void) {
  char arr[] = "%d\n%d\nfizz\n%d\nbuzz\nfizz\n%d\n%d\nfizz\nbuzz\n%d\nfizz\n%d\n%d\nfizzbuzz\n";
  int news[]={0,3,6,11,14,19,24,27,30,35,40,43,48,51,54,63};
  int i=N/15, j=1;
 
  while(i--){
   printf(arr, j, j+1, j+3, j+6, j+7, j+10, j+12, j+13);
   j+=15;
  }
  arr[news[N%15]]='\0';
  printf(arr, j, j+1, j+3, j+6, j+7, j+10, j+12, j+13);
 
  return 0;  
}

Name: Anonymous 2012-03-13 13:47

>>14
actually we pretty much did the same thing.
http://dis.4chan.org/read/prog/1327861621/1

Name: Anonymous 2012-03-13 13:50

>>14
real    0m1.598s
user    0m1.587s
sys    0m0.007s

That's even better. It seems the <15times iteration at the end is actually a time eater!

Name: Anonymous 2012-03-13 16:32

BogoBuzz

Randomly generate a list of 100 elements, each element containing either: an int 1-100, "fizz", "buzz" or "fizzbuzz".
Check if the result is correct.
If correct, print out result. If not, start over.

Name: Anonymous 2012-03-13 16:45

So are you retards really timing I/O? Why don't you just allocate a single huge buffer and then write the entire thing to stdout at the end? It will be a lot faster and then you can jerk off since your implementation defined behavior is faster than someone else's.

Name: Anonymous 2012-03-13 16:58

>>17
now all I need is a quantum computer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define N 5

char *s[] = {"%d\n", "fizz\n", "buzz\n", "fizzbuzz\n"};

void randomfizzbuzzgenerator(char *c, int n){
  int i;
  for(i=1; i<=n; i++)
    c += sprintf(c, s[rand()&3], rand()%n+1);
}
   
void realfizzbuzzgenerator(char *c, int n){
  int i;
  for(i=1; i<=n; i++)
    c += sprintf(c, s[(!(i%3))|((!(i%5))<<1)], i);
 
}

int main(){
  int i;
  char buff[9*N+1];
  char result[9*N+1];
  srand(time(0));
 
  realfizzbuzzgenerator(result, N);
  while(1){
    randomfizzbuzzgenerator(buff, N);
    if(!strcmp(buff, result)) break;
  }
   
  printf("%s", buff);
   
  return 0;
}

>>18
umad because your implementation is slower

Name: Anonymous 2012-03-13 17:17

USING: kernel io math math.functions math.ranges math.parser
sequences ;
IN: FizzBuzz

PREDICATE: fizz < integer  3 divisor? ;
PREDICATE: buzz < integer  5 divisor? ;
INTERSECTION: f&b fizz buzz ;

GENERIC: say ( n -- )
M: integer say   number>string print ;
M: fizz say   drop "Fizz" print ;
M: buzz say   drop "Buzz" print ;
M: f&b say   drop "FizzBuzz" print ;

: fizzbuzz ( -- ) 100 [1,b] [ say ] each ;

MAIN: fizzbuzz

Name: Anonymous 2012-03-14 9:05

>>20
A new level of fizzbuzz faggotry has been unlocked

Name: Dubs Guy 2012-03-17 15:46

DUBS, DUBS EVERYWHERE!

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