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

fizzbuzz

Name: Anonymous 2011-01-28 20:49

(define (main num)
  (if (= num 100) (exit))
  (set! tmp (modulo num 15))
  (if (or (= tmp 1) (= tmp 2) (= tmp 4) (= tmp 7) (= tmp 8) (= tmp 11) (= tmp 13) (= tmp 14))
      (display num)
      (begin
        (if (or (= tmp 3) (= tmp 6) (= tmp 9) (= tmp 0) (= tmp 12)) (display "Fizz"))
        (if (or (= tmp 5) (= tmp 10) (= tmp 0)) (display "Buzz"))))
  (newline)
  (main (+ num 1)))
(define tmp 0)
(main 1)

can you do better?

Name: Anonymous 2011-01-29 7:04

I think we've had this thread before http://dis.4chan.org/read/prog/1259905156 ...

Here was my expert solution...


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define f(x) for(i=(x)-1;i<n;i+=(x)) a[i]+=(x);
int main() {
  int i,b=3,a[100],n=sizeof(a)/sizeof(int);
  char *s="fizzbuzz ",*p,*m;
  memset(a,0,sizeof(a));
  f(b);
  b+=2;
  f(b);
  b--;
  for(i=0;i<n;i++)
    if(a[i]) {
      m = p = strdup(s);
      if(a[i]&8)
        goto pr;
      p+=(a[i]&4);
      p[b]=(!(a[i]&2))<<(b+1);
pr:
      printf("%s\n",p);
      free(m);
    }
    else
      printf("%d\n",i+1);
  return 0;
}

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