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

Pages: 1-

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-28 21:20

Do you want it clearer or more obfuscated?

Name: Anonymous 2011-01-28 21:28

for 1..100 -> $n {
    my %fb = <Fizz Buzz> Z=> ( $n <<%%<< (3,5) );
    say ([+] %fb.values)    ?? %fb.map: { (.value ?? .key !! '') }
                            !! $n;
}

Name: Anonymous 2011-01-28 21:37

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

Name: Anonymous 2011-01-29 0:55

Darn you fizzybuzzy.

public class FizzBuzz
{
   public static void main(String[] arg)
   {
      int i = 1;
      while(i < 100) // I forget; do we count the 100 too?
      {
         String s = String.format("%s%s\n", i%3==0?"Fizz":"",i%5==0?"Buzz":"");
         if(s.length() > 1) System.out.print(s);
         else System.out.printf("%d\n",i);
         ++i;
      }
   }
}

Name: Anonymous 2011-01-29 1:32

>>4
VALID PERL CODE

Name: Anonymous 2011-01-29 4:40

#include<iostream>
using namespace std;

int main() {
  for(int i = 1; i <= 100; i++)
    cout << i%15? i%5? i%3? i: "Fizz": "Buzz": "FizzBuzz" << '\n';
  return 0;
}

Name: Anonymous 2011-01-29 5:37

+>>>+>>>++++++++++>-<[->+>>[-]-<++++++++++[->+>+<<<<<<<
-[->+>+<<]>[-<+>]+>[[-]<->]<[<+++>-++++++++++[->+++++++
<]>.[-]>>>>>[-]<<<<<<]<<<<-[->+>+<<]>[-<+>]+>[[-]<->]<[
<+++++>-++++++++++[->+++++++<]>----.[-]>>>>>>>>[-]<<<<<
<<<<]>>>>>>>>>[[-]++++++++++++[-<++++<<++++>>>]<<<.>>.>
++++++++++++[-<----<<---->>>]]++++++++++.[-]<<]<<]

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;
}

Name: Anonymous 2011-01-29 7:14

>>9
>expert solution
>requires O(n) space
>3*n passes
congrats

Name: Anonymous 2011-01-29 7:16

check my dubz

Name: Anonymous 2011-01-29 7:27

>>10
JEALOUS MUCH

Name: Anonymous 2011-01-29 7:29

>>10
do not forget dynamic allocation on each iteration
damn you are stupid.

Name: Anonymous 2011-01-29 7:35

Sieve:
my @a;
for 3,6,9 ...^ *>100 { @a[$_] = 'Fizz' };
for 5,10,15 ...^ *>100 { @a[$_] ~= 'Buzz' };
for ^100 { (@a[$_].so ?? @a[$_] !! $_).say };



Also /thread: http://rosettacode.org/wiki/FizzBuzz

Name: Anonymous 2011-01-29 8:24


def anus(x):
    if x % 15 == 0: return "FizzBuzz"
    if x % 5 == 0: return "Buzz"
    if x % 3 == 0: return "Fizz"
    return x

print map(anus, range(1,20))

Name: Anonymous 2011-01-29 9:00

(define fizzbuzz
  (λ (from to)
    (map (λ (x)
           (if3/zero? (remainder x 5)
                      (remainder x 3)
                      'fizzbuzz 'buzz 'fizz x))
         (range from to))))

(display (fizzbuzz 1 20))


(if3/zero? p1 p2 tt tf ft ff) is a macro that expands to (if3 (zero? p1) (zero? p2) tt tf ft ff)
if3 is a shorthand to three-way-if, that is another macro that evaluates tt is p1 and p2 are true, tf if p1 is true, ft if p2 is true or ff if both are false.

Name: Anonymous 2011-01-29 10:35

>>16
Post source of macro or does not count.

Name: Anonymous 2011-01-29 11:13

There's already (at least) one entire thread about FizzBuzz:
http://dis.4chan.org/read/prog/1209141432
90% of /prog/ can't write FizzBuzz
1 Name: The antagonist : 2008-04-25 12:38

    Prove me wrong

    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".

Name: Anonymous 2011-01-29 11:31


x.{?%15==0 -> "FizzBuzz"
   ?%5==0  -> "Buzz"
   ?%3==0  -> "Fizz"
   _       -> x}

Name: Anonymous 2011-01-29 11:39


if fb:"$(x.{?%3==0  -> say "Fizz"{)$(x.{?%5==0 -> say "Buzz"})" != ""
  then fb
  else x

Name: Anonymous 2011-01-29 11:41

>>20

"$(x.{?%3==0 -> say "Fizz"})$(x.{?%5==0 -> say "Buzz"})".{""->x; fb->fb}

Name: Anonymous 2011-01-29 11:41

>>17
(define-syntax (ifn stx)
  (syntax-case stx ()
    ((~ 0 t) #'t)
    ((~ 1 p t f) #'(if p t f))
    ((~ 2 p1 p2 tt tf ft ff)
     #'(if p1
           (ifn 1 p2 tt tf)
           (ifn 1 p2 ft ff)))
    ((~ 3 p1 p2 p3
        ttt ttf
        tft tff
        ftt ftf
        fft fff)
     #'(ifn 1 p1
            (ifn 2 p2 p3 ttt ttf tft tff)
            (ifn 2 p2 p3 ftt ftf fft fff)))
    ((~ #:map p n r ...)
     (exact-positive-integer? (syntax->datum #'n))
     (let*-values (((preds exprs)
                    (split-at (syntax->list #'(r ...)) (syntax->datum #'n))))
       #`(~ n #,@(map (λ (x) (list #'p x)) preds)
            #,@exprs)))
    ((~ n r ...)
     (let ((nn (syntax->datum #'n)))
       (and (exact-positive-integer? nn)
            (= (+ nn (expt 2 nn))
               (length (syntax->list #'(r ...))))))
     (let*-values (((nn) (syntax->datum #'n))
                   ((preds exprs)
                    (split-at (syntax->list #'(r ...)) nn))
                   ((nn1 cdrp)
                    (values (sub1 nn) (cdr preds)))
                   ((all-true) (car exprs))
                   ((rest all-false)
                    (split-at-right (cdr exprs) 1))
                   ((true-branch false-branch)
                    (split-at rest (/ (length rest) 2))))
       #`(~ 1 #,(car preds)
            (~ #,nn1 #,@cdrp
               #,@(cons all-true true-branch))
            (~ #,nn1 #,@cdrp
               #,@(append false-branch all-false)))))))
(define-syntax (define-if-syntax stx)
  (syntax-case stx ()
    ((~ id n)
     (exact-positive-integer? (syntax->datum #'n))
     #'(define-syntax id
         (syntax-rules ()
           ((id . r) (ifn n . r)))))
    ((~ id pred)
     #'(define-syntax id
         (syntax-rules ()
           ((id p t f) (ifn #:map pred p t f)))))
    ((~ id n pred)
     (exact-positive-integer? (syntax->datum #'n))
     #'(define-syntax id
         (syntax-rules ()
           ((id . r) (ifn #:map pred n . r)))))))
(define-if-syntax if2/zero? 2 zero?) ; it was if2, not if3, my bad.

Name: Anonymous 2011-01-29 11:44

I originally wrote this on a napkin.

%macro    modtest    1
    mov    eax, ecx
    mov    ebx, %1
    xor    edx, edx
    div    ebx
    test    edx, edx
%endmacro

%macro    write    2
    pushad
    mov    eax, 4
    mov    ebx, 1
    mov    ecx, %1
    mov    edx, %2
    int    0x80
    popad
%endmacro

section    .data
fizz:    db    "Fizz"
buzz:    db    "Buzz"
nl:    db    0xa

section    .bss
buff:    resb    32

section    .text
    global    _start

_start:
    xor    ecx, ecx
.loop:
    inc    ecx
    cmp    ecx, 100
    jg    .ret

    modtest    3
    jz    .fizz

    modtest    5
    jz    .buzz

    call    print_int
.endl:
    write    nl, 1
    jmp    .loop
.ret:
    mov    eax, 1
    mov    ebx, 0
    int    0x80
.fizz:
    write    fizz, 4
    modtest    5
    jz    .buzz
    jmp    .endl
.buzz:
    write    buzz, 4
    jmp    .endl

print_int:
    pushad
    mov    al, cl
    lea    ecx, [buff + 32]
.loop:
    dec    ecx

    mov    bl, 10
    xor    ah, ah
    div    bl

    add    ah, 0x30
    mov    byte [ecx], ah

    test    al, al
    jnz    .loop
.ret:
    mov    eax, 4
    mov    ebx, 1
    lea    edx, [buff + 32]
    sub    edx, ecx
    int    0x80
    popad
    ret

Name: Anonymous 2011-01-29 14:43

well damn i can't read any of this shit

Name: Anonymous 2011-01-29 15:07

>>24
Learn to program.

Name: Anonymous 2011-02-02 14:50

#if 0
exec gcc-4.2 -o faztbuzz -O999 -ffast-math -fomit-frame-pointer \
    -falign-loops=32 -fno-align-labels -march=core2 "$0"
#endif

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

__attribute__((fastcall, destructor, always_inline)) static inline void fizzbuzz()
{
    register uint_fast8_t n = -4;
    goto begin;
    for (; n < 100; n += 15)
    {
        printf("%"PRIuFAST8"\n", n);
        puts("Fizz");
        printf("%"PRIuFAST8"\n", n+2);
        printf("%"PRIuFAST8"\n", n+3);
        puts("FizzBuzz");
    begin:
        printf("%"PRIuFAST8"\n", n+5);
        printf("%"PRIuFAST8"\n", n+6);
        puts("Fizz");
        printf("%"PRIuFAST8"\n", n+8);
        puts("Buzz");
        puts("Fizz");
        printf("%"PRIuFAST8"\n", n+11);
        printf("%"PRIuFAST8"\n", n+12);
        puts("Fizz");
        puts("Buzz");
    }
}

int main(void) {return 0;}

Name: Anonymous 2011-02-02 14:59

>>26
How about a duff's device?

Name: Anonymous 2011-02-02 15:48

[list] [*]How did I do this [*]A duff's device is fine too [*]sega goes in the field [*]polecat is pole [/list]

Name: Anonymous 2011-02-02 15:59

#include<stdio.h>
int main (int n,char**u){n=u?atoi(*++u):n;printf(!(n%3)||!(n%5)?"%s\n":"%d\n",(n%3)?(n%5)?n:"Buzz":(n%5)?"Fizz":"FizzBuzz");return--n?main(n,0):0;}


Usage:

./a.out 15
FizzBuzz
14
13
Fizz
11
Buzz
Fizz
8
7
Fizz
Buzz
4
Fizz
2
1

Name: Anonymous 2011-02-02 17:04

>>26
#if 0
exec gcc-4.2 -o faztbuzz -O999 -ffast-math -fomit-frame-pointer \
    -falign-loops=32 -fno-align-labels -march=core2 "$0"
#endif

I fucking love you.

Name: Anonymous 2011-02-02 17:07

>>24
Read SICP.

Name: Anonymous 2011-02-02 19:19

Now try dictating your fizzbuzz program without typing out and looking at your code.

Name: Anonymous 2011-02-02 19:56

>>29
[code]
#include<stdio.h>
int main(int n,char**u){n=u?atoi(*++u):n;printf(!(n%3)||!(n%5)?"%s\n":"%d\n",n%3?n%5?n:"Buzz":n%5?"Fizz":"FizzBuzz");return--n?main(n,0):0;}[code]

[b][i]OMG OPTIMIZED![/i][/b]

Name: Anonymous 2011-02-03 3:00

for i=0,99 do print(({"Fizz","Buzz","FizzBuzz"})[math.floor(809895440/2^(2*i%30))%4]or i+1)end
NO BITSHIFTS

Name: Anonymous 2011-02-04 13:33

Name: TrEy 2012-03-17 3:58

でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額 でたらめの非常識な金額

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