fizzbuzz
1
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) );
}
2
Name:
Anonymous
2011-12-26 17:19
3
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?
4
Name:
Anonymous
2011-12-26 18:53
>>3
I prefer marmalade, but thank you anyway.
5
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);}}
6
Name:
Anonymous
2011-12-26 20:12
the best fizzbuzz uses FORMAT
7
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
8
Name:
übermench
2011-12-26 20:55
>>3,5,7
eww unoptimized shit.
9
Name:
Anonymous
2011-12-26 21:29
>*2
EWW, UNOPTIMIZED SHIT
10
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
^ $ <
,>:#._^ >
>:#,_^ >
11
Name:
Anonymous
2011-12-27 0:28
Is it possible to make a fizzbuzz program in Lisp?
12
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.
13
Name:
Anonymous
2011-12-27 0:35
14
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
15
Name:
Anonymous
2011-12-27 3:57
>>14
omg, so many branches, unoptimized
16
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));
}
17
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 opin
end
18
Name:
Anonymous
2011-12-27 4:36
19
Name:
Anonymous
2011-12-27 5:37
>>17
#define := =
#define [...] []
That's not a C compiler.
20
Name:
Anonymous
2011-12-27 6:21
Which Touhou would fizz?
21
Name:
Anonymous
2011-12-27 6:21
Which Touhou would buzz?
22
Name:
Anonymous
2011-12-27 6:36
check them
23
Name:
Anonymous
2011-12-27 8:03
>>8
How would you optimize
>>7
24
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
25
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.
26
Name:
Anonymous
2011-12-27 10:52
>>25
Ups, fucked up indentation. Fucking emacs.
27
Name:
Anonymous
2011-12-27 11:04
>>26
It's actually your fault, not Emacs' fault.
28
Name:
Anonymous
2011-12-27 11:36
>>25
Protip: cond and loop
also, zerop.
29
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)))
30
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.
31
Name:
Anonymous
2011-12-27 14:00
>>29
you are leading him astray!!
32
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?
33
Name:
Anonymous
2011-12-27 14:33
>>32
* no conditional branches
34
Name:
Anonymous
2011-12-27 14:34
And it is in C, not a lesser language like lisp.
Nice try, FrozenVoid.
35
Name:
Anonymous
2011-12-27 15:03
>>1
>übermench
It's written ```````````````````````````````````übermensch''''''''''''''''''''''''''''''''''
36
Name:
Anonymous
2011-12-27 15:46
>>19
get a better compiler
37
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
}
38
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);
}
39
Name:
Anonymous
2011-12-27 20:21
My ``FHQ9+'' version:
f
40
Name:
Anonymous
2011-12-27 20:46
Perl golf version:
print$_%15?$_%5?$_%3?$_:Fizz:Buzz:FizzBuzz,"\n"for 1..100
Newer Posts