xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
And a better one that doesn't use variables:
Code:
: prog1 
20 1 do
0
i 3 mod 0= if ." fizz" drop 1 then
i 5 mod 0= if ." buzz" drop 1 then
0= if i . else ."  " then
loop ;
shency's Avatar, Join Date: Oct 2008
Go4Expert Member
Code:
<?php
    for($i = 1; $i <= 100; $i++)
    {
     echo (($i%3 ==0) && ($i%5 ==0)) ? 'FizzBuzz<br>' : (($i%3==0) ? 'Fizz<br>' :(($i%5==0) ? 'Buzz<br>' : "$i<br>"));
    }
?>
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
@ xpi0t0s : Please do mention the language (atleast in your code-block), before posting any code.

BTW, that code looks like Forth, am I right ??


One more by me : (in HLA = High Level Assembly)
Code: asm
program FizzBuzz;

#include ("stdlib.hhf");

static
    Number:   int32 := 1;

begin FizzBuzz;
    mov(101, ebx);
    mov(1, Number);
    while(Number < ebx) do
        mov(0,ecx);
        mov(Number,eax);
        mov(3,dl);
        div(dl);
        if (ah = 0) then
            mov(1,ecx);
            stdout.put("Fizz");
        endif;
        mov(Number,eax);
        mov(5,dl);
        div(dl);
        if(ah = 0) then
            mov(1,ecx);
            stdout.put("Buzz");
        endif;
        if(! ecx) then
            stdout.put(Number);
        endif;
        stdout.put(nl);
        inc(Number);
    endwhile;
end FizzBuzz;
 

Last edited by SaswatPadhi; 28May2009 at 19:21.. Reason: Added HLA Code
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Quote:
Originally Posted by SaswatPadhi
Please do mention the language (atleast in your code-block), before posting any code.

BTW, that code looks like Forth, am I right ??
You are, and I did, but it's on page 1:
Quote:
Originally Posted by xpi0t0s
Forth (developed and tested with Win32Forth)
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Oh ! : , I didn't see it !
[ Bad habit of jumping to the last post, directly ]
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Finalllyyyy... After struggling with BrainF*ck for 3 hours, I conclude that the language truly justifies its name !

Here is my BF code for some thing as simple as a Fizz-Buzz test :

Code:
<    * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
   # *   (+) FIZZ-BUZZ PROGRAM BY SASWAT PADHI >             *
 # # *                                                       *
 # # *   This BrainF*ck program is written by Saswat Padhi   *
 # # *   I have done much labour on this code as writing a   *
 # # *   BF code is not easy; even harder than ASM     ;)    *
 # # *                                                       *
 # # *   Believe it or not I have spent 3 hours writing this *
 # # *   shit(looking) code !                                *
 # # *                                                       *
 # # *   If you want to use this code; please give me some   *
 # # *   credit by atleast mentioning my name :) Thanks      *
 # # *                                                       *
 # # *   PLEASE NOTE THAT THIS IS THE UNCOMMENTED VERSION OF *
 # # *   MY ORIGINAL FIZZBUZZ PROGRAM; SO BETTER NOT TO TRY  *
 # # *   READING IT ;)     IF YOU WANT A MORE HUMAN_FRIENDLY *
 # # *   VERSION THAT IS WELL COMMENTED; YOU MAY CONTACT ME  *
 # # *                                                       *
 # # * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # #     >


************************************************************************
******************** FIZZBUZZ BF SOURCE CODE BEGINS ********************
************************************************************************
**                                                                    **
**                                                                    **
**  >++++++++++++++++++++++++++++++++++++++++++++[[>]+++++++++++++++  **
**  ++++++++++++++++++++++++++++++++++++++++++++++++++[<]>-]>+++++.>  **
**  ++++++++.>+++++++++++++++++++++++++.>+++++++++++++++++++++++++.>  **
**  --------------------.>+.>++++++++++++++++++++.>+++++++++++++++++  **
**  ++++++++.>+++++++++++++++++++++++++.>---------------------------  **
**  ------.>+++++++++++++++.>+++++++++++++++++.>++++++++++++++.>++++  **
**  ++.>+++++++++++++++++.>.>++++++++++++.>-------------------------  **
**  --------.>+.>++++++++++++++++++++++++.>-------------------------  **
**  --------.>++++++++++++++++++.>.>++++++++++++++++++.>++++++++++++  **
**  ++++++++++.>.>+++++++++++++++++++.>-----------------------------  **
**  ----.>+++++++++++++++.>.>+++.>+++++++.>++++++++.>---------------  **
**  ----------------------------------------..>---------------------  **
**  -------------------------------------------->+++++>++++++++>++++  **
**  +++++++++++++++++++++>+++++++++++++++++++++++++>----------------  **
**  ------------------------------------------------->+>++++++++++++  **
**  ++++++++>+++++++++++++++++++++++++>+++++++++++++++++++++++++>>++  **
**  ++++++++>>++++++++++++++++++++++++++++++++++++++++++++++++>+++++  **
**  ++++++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++>  **
**  >>>>>>>>>++<<<<<<<<<<<<<<[>++++++++++>>----------<<[>>+>>[-]>[-]  **
**  >[-]>[-]+>[-]+>[-]+>[-]>[-]>[-]>+>[-]<[>+>+<<-]>>[<<+>>-]<<---[<  **
**  <<<<<[-]>>>>>[-]+>-]<[>>[<+>-]>+<<<-]>>>[<<<+>>>-]<<<<<<<<<<<<<[  **
**  >>+>+<<<-]>>>------------------------------------------------[>>  **
**  >[-]>>[-]+<<<<+<-]>[<+>-]<-----[>>>>[-]>>[-]+<<<<<<-]<[<<+>>-]>>  **
**  >[<<<<<<<<<<[<]<[<]>.>.>.>.>>>>>>>>>>>>>>>-]>[<<<<<<<<<<<[<]>.>.  **
**  >.>.>>>>>>>>>>>-]>[<<<<<<<<<<<<[<]>.>.>.>.>>>>>>>>>>>>-]>[>[>[<<  **
**  <<<<<<<<<.>.>>>>>>>>>>-]<-]<-]<<<<<<<.<<<-]>+<<-]<<[<]>.>.>.>.<>  **
**                                                                    **
**                                                                    **
************************************************************************
******************** END OF FIZZBUZZ BF SOURCE CODE ********************
************************************************************************


Program Size    :: 4254 bytes
Instructions    :: 1669
Number of moves :: 694083
Average RunTime :: 30 ms

Notes :
(*) Compile with option "Allow wrapping of pointers = TRUE"
(*) Compile with option "Allow wrapping of values = TRUE"
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Thats really a BrainF*ck really
pradeep's Avatar, Join Date: Apr 2005
Team Leader
:O That's some code. For people who don't know about Brain*uck check this link http://cydathria.com/bf/
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Code: JavaScript
for(var i = 1; i <= 100; i++)
{
    document.write(((i%3 ==0) && (i%5 ==0)) ? 'FizzBuzz<br>' : ((i%3==0) ? 'Fizz<br>' :((i%5==0) ? 'Buzz<br>' : i+"<br>")));
}
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Code: QBASIC
FOR I = 1 TO 100
    Flag = 0
    IF I MOD 3 = 0 THEN PRINT "FIZZ"; : Flag = 1
    IF I MOD 5 = 0 THEN PRINT "BUZZ"; : Flag = 1
    IF Flag = 0 THEN PRINT I;
    PRINT ""
NEXT I
END