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

Pages: 1-

MOST OPTIMIZED FIZZBUZZ IMPLEMENTATION

Name: Anonymous 2012-01-29 13:27

ever. (for any arbitery n)

#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-01-29 13:30

MOST
Nope.

Name: Anonymous 2012-01-29 13:33

>>2
I don't see you are doing any better

Name: Anonymous 2012-01-29 13:39

No, It only works when looping from 1 to n.

fails to tell me the fizzbuzz of a single number by itself

will not work properly if n is not a multiple of 15

Name: Anonymous 2012-01-29 13:41

>>4
I believe fizzbuzz is supposed to work with 1-n. but it could be easily modified for any interval
will not work properly if n is not a multiple of 15
it does

Name: Anonymous 2012-01-29 14:28

>>2
We already had many Fizzbuzz threads, I'm not going to point you to them. The reason I said "Nope" is because anyone who understands basic CS knows that Kolmogorov complexity of a string (such as the final FizzBuzz output) is uncomputable, although I suppose one can get good approximations for specific machines if they're willing to do a lot of specific mathematical proofs (usually mechanized). In a bit more general terms, no perfect optimizing compiler can exists as well: http://en.wikipedia.org/wiki/Full_employment_theorem
No more than an universal halting problem solver (although specific-case can be done, and possibly self-improving as well, although it's provable that there will always be programs you won't be able to decide, just like there will always be arithmetical truths that won't be reachable by proofs, by Godel's incompleteness theorem).

Name: >>6,>>2 2012-01-29 14:29

Previous post was meant to be directed at >>3, not at >>2.

Name: Anonymous 2012-01-29 14:48

>>6
the set of terminating programs is recursively enumerable, and fizzbuzz clearly terminates

Name: Anonymous 2012-01-29 15:15

>>8
Sure, let's restrict ourselves to that set, it would make things easier. I'll give you the honor of constructing the set since it was your idea. Shouldn't be too hard, just use Jot1 to enumerate all programs and select the terminating ones among them. Jot is handy for this task, if you used binary-coded Jot, the new Gödel numbering is the code.

Once you've constructed the set I'll do the analysis to find the most efficient one.

[1] http://semarch.linguistics.fas.nyu.edu/barker/Iota/

Name: Anonymous 2012-01-29 15:20

printf formatting
Sure is optimized here.

Name: Anonymous 2012-01-29 15:39

>>9
OK I'm done.

Name: Anonymous 2012-01-29 15:59

>>11
Please post the selection function and I will begin streaming the analysis immediately.

Name: Anonymous 2012-12-08 15:26

( ͡° ͜ʖ ͡°)

Name: Anonymous 2012-12-08 20:00

Unnecessary arithmetic. Unnecesary branching. printf.
Not optimized at all.

#include <stdio.h>

#define FBSTR(a,b,c,d,e,f,g,h) #a "\n" #b "\nFizz\n" #c "\nBuzz\nFizz\n" #d   \
                               "\n" #e "\nFizz\nBuzz\n" #f "\nFizz\n" #g "\n" \
                               #h "\nFizzBuzz\n"
#define FBSTRA(a,b) FBSTR(a##1,a##2,a##4,a##7,a##8,b##1,b##3,b##4)
#define FBSTRB(a,b) FBSTR(a##6,a##7,a##9,b##2,b##3,b##6,b##8,b##9)
#define FBSTRAB(a,b,c) FBSTRA(a,b) FBSTRB(b,c)

int main(void)
 { write(0, FBSTRAB(,1,2) FBSTRAB(3,4,5) FBSTRAB(6,7,8) FBSTRA(9,), 413); }

Name: Anonymous 2012-12-08 20:16

>>14
actually, that #include <stdio.h> is unnecessary, unless you want to replace write (POSIX) with fwrite (standard C, almost always implemented using write).

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