Computer Science Canada

Fizz-Buzz: The Multi-Language Challenge

Author:  haskell [ Sat Mar 24, 2007 1:44 pm ]
Post subject:  Fizz-Buzz: The Multi-Language Challenge

Task

To write the same program in as many languages as possible.

Purpose

So people can see the same code written in as many languages as possible.

The Program

Count from 1-100 and write the results. If the value is divisible by 3, than write "Fizz". If the value is divisible by 5, than write "Buzz". If the value is divisible by both 3 and 5, than write "FizzBuzz".

Rules

State the language. Multiple solutions in the same language is acceptable. Use any means necessary Smile.

Enjoy Very Happy

---

C++
code:
string fizz_buzz;

for(int i = 1; i <= 100; i++) {
    if(i % 3 == 0) fizz_buzz += "Fizz";
    if(i % 5 == 0) fizz_buzz += "Buzz";
    if(fizz_buzz == "") cout << i;
    cout << fizz_buzz << endl;
    fizz_buzz = "";
}

Author:  ericfourfour [ Sat Mar 24, 2007 2:02 pm ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

Turing:
View.Set("text")

var fizzBuzz : string := ""

for i : 1 .. 100
    if i mod 3 = 0 then
        fizzBuzz += "Fizz"
    end if
    if i mod 5 = 0 then
        fizzBuzz += "Buzz"
    end if
    if fizzBuzz = "" then
        put i ..
    end if
    put fizzBuzz
    fizzBuzz := ""
end for

Author:  rdrake [ Sat Mar 24, 2007 2:02 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

I think this is what it should do...
code:
fizz_buzz = ""

100.times do |i|
    if (i % 3) == 0 then fizz_buzz += "Fizz" end
    if (i % 5) == 0 then fizz_buzz += "Buzz" end
    if fizz_buzz == "" then puts i end
    puts fizz_buzz
    fizz_buzz = ""
end

Author:  wtd [ Sat Mar 24, 2007 2:11 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

code:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Fizz_Buzz is
   function Evenly_Divisible_By(A, B : in Integer) return Boolean is
   begin
      return A mod B = 0;
   end Evenly_Divisible_By;

   Count : Integer;
begin
   for Count in 1 .. 100
   loop
      if Evenly_Divisible_By(Count, 15) then
         Put_Line("FizzBuzz");
      elsif Evenly_Divisible_By(Count, 3) then
         Put_Line("Fizz");
      elsif Evenly_Divisible_By(Count, 5) then
         Put_Line("Buzz");
      else
         Put(Count, 0);
         New_Line;
      end if;
   end loop;
end Fizz_Buzz;

Author:  wtd [ Sat Mar 24, 2007 2:22 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

code:
class
   FIZZ_BUZZ

creation { ANY }
   make

feature { NONE }
   evenly_divisible_by(a, b : INTEGER) : BOOLEAN is
      do
         Result := a \\ b = 0
      end

feature { ANY }
   make is
      local
         count : INTEGER
      do   
         from
            count := 1
         until
            count > 100
         loop
            if evenly_divisible_by(count, 15) then
               std_output.put_string("FizzBuzz")
            elseif evenly_divisible_by(count, 3) then
               std_output.put_string("Fizz")
            elseif evenly_divisible_by(count, 5) then
               std_output.put_string("Buzz")
            else
               std_output.put_integer(count)
            end

            std_output.put_new_line
         end
      end
end

Author:  haskell [ Sat Mar 24, 2007 2:32 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

C
code:
int fizz_buzz(int, int);

int main()
{
    fizz_buzz(1, 100);   

    return 0;
}

int
fizz_buzz(int l, int h)
{
    if(l % 3 == 0) printf("Fizz");
    if(l % 5 == 0) printf("Buzz");
    else if(l % 3 != 0) printf("%d", l);
   
    printf("\n");

    if(l != h) return fizz_buzz(l + 1, h);
    else return 0;
}

Author:  wtd [ Sat Mar 24, 2007 2:51 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

code:
object Test extends Application {
   def evenlyDivisibleBy(a: Int, b: Int) = a % b == 0

   def fizzbuzz(a: Int, b: Int) {
      if (a <= b) {
         if (evenlyDivisibleBy(a, 15))
            Console println "FizzBuzz"
         else if (evenlyDivisibleBy(a, 3))
            Console println "Fizz"
         else if (evenlyDivisibleBy(a, 5))
            Console println "Buzz"
         else
            Console println a

         fizzbuzz(a + 1, b)
      }
   }

   fizzbuzz(1, 100)
}

Author:  PaulButler [ Sat Mar 24, 2007 4:07 pm ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

In Java:

Java:

public class FizzBuzz {
        public static void main(String[] args) {
                for(int i = 1; i <= 100; i++){
                        String fb = "";
                        if(i % 3 == 0){
                                fb = "Fizz";
                        }
                        if(i % 5 == 0){
                                fb += "Buzz";
                        }
                        System.out.println(fb == ""? i : fb);
                }
        }
}

Author:  PaulButler [ Sat Mar 24, 2007 4:11 pm ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

php:

<?php

header('Content-type: text/plain');

for($i = 1; $i <= 100; $i++){
        $word = "";
        if($i % 3 == 0){
                $word = "Fizz";
        }
        if($i % 5 == 0){
                $word .= "Buzz";
        }
        echo ($word == "")? $i : $word;
        echo PHP_EOL;
}

?>

Author:  haskell [ Sat Mar 24, 2007 4:21 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Python
code:
def fizz_buzz(x):
    fizz = ''
    if(x <= 100):
        if((x % 3) == 0):
            fizz += 'Fizz'
        if((x % 5) == 0):
            fizz += 'Buzz'
        elif((x % 3) != 0):
            fizz += str(x)
        print fizz
        fizz = ''
        fizz_buzz(x+1)

fizz_buzz(1)

Author:  wtd [ Sat Mar 24, 2007 4:25 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

I don't get why so many people have such apparent loathing for "else" and such irrational love of mutable state.

Author:  ericfourfour [ Sat Mar 24, 2007 4:53 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

wtd what were the programming languages you used?

Author:  wtd [ Sat Mar 24, 2007 5:20 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

I was hoping someone would try to guess...

Ada, Eiffel, and Scala.

Author:  richcash [ Sat Mar 24, 2007 8:36 pm ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

In javascript in html :
Javascript:
<html>
<body>
<script type="text/javascript">
for (var i=1;i<=100;i++) {
        var output = ""
        if (i%3 == 0) {
                output += "Fizz"
        }
        if (i%5 == 0) {
                output += "Buzz"
        }
        if (output == "") {
                output = i
        }
        document.write(output)
        document.write("<br />")
}
</script>
</body>
</html>


P.S. Javascript is not a programming language, it's a scripting language.

Author:  wtd [ Sun Mar 25, 2007 12:24 am ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Javascript most certainly is a programming language. A darn good one, too.

Author:  richcash [ Sun Mar 25, 2007 2:02 am ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

Oh, I just go by what I read, and I know some people don't consider it to be a real programming language but rather a scripting language because its actions are handled by the web browser.

If you say it's a programming language, then I agree, because I also like javascript a lot. Smile

Here's another language used in html documents :

vbscript:
<html>
<body>
<script type="text/vbscript">
For i=1 to 100
        output = ""
        if i Mod 3 = 0 Then
                output = output & "Fizz"
        end If
        if i Mod 5 = 0 Then
                output = output & "Buzz"
        end If
        if output = "" Then
                output = i
        end If
        document.write(output)
        document.write("<br />")
Next
</script>
</body>
</html>

Author:  wtd [ Sun Mar 25, 2007 8:33 am ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Can you write a program in Javascript?

Yes. Well, then... it's a programming language.

"Scripting language" is most frequently a derogatory language thrown around by users of heavyweight languages (C, C++, Java, C#, etc. you know who you are) to make themselves feel better about their choice of programming language, as opposed to those who use more lightweight languages.

Those of us who use both types of language think the whole dichotomy is pure bull crap.

Author:  PaulButler [ Sun Mar 25, 2007 9:19 am ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

C#

code:

using System;
using System.Collections.Generic;
using System.Text;

namespace FizzBuzz
{
    class FizzBuzz
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 100; i++)
            {
                String s = "";
                if (i % 3 == 0)
                {
                    s = "Fizz";
                }
                if (i % 5 == 0)
                {
                    s += "Buzz";
                }
                Console.WriteLine(s.Equals("") ? i.ToString() : s);
            }
        }
    }
}

Author:  wtd [ Sun Mar 25, 2007 9:36 am ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Or perhaps we could just write the straightforward C# program...

code:
using System;

namespace FizzBuzz
{
    class FizzBuzz
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 100; i++)
            {
                if (i % 15 == 0)
                    Console.WriteLine("FizzBuzz");
                else if (i % 3 == 0)
                    Console.WriteLine("Fizz");
                else if (i % 5 == 0)
                    Console.WriteLine("Buzz");
                else
                    Console.WriteLine("{0}", i);
            }
        }
    }
}

Author:  md [ Sun Mar 25, 2007 10:32 am ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Pascal:

program Foo;
var
    i:integer;
begin
    for i := 1 to 100 do
    begin
        if (i mod 3 > 0) and (i mod 5 > 0) then
            writeln(i)
        else
        begin
            if i mod 3 = 0 then
                write('Fizz');
            if i mod 5 = 0 then
                write('Buzz');
            writeln('');
        end;
    end;
end.

Author:  PaulButler [ Sun Mar 25, 2007 10:35 am ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

SQL:

delimiter //
DROP FUNCTION IF EXISTS fizzbuzz //
CREATE FUNCTION fizzbuzz() returns text deterministic
begin
declare i int DEFAULT 1;
declare result text DEFAULT "";
while i <= 100 do
        IF i % 15 = 0 then
                SET result = concat(result, "FizzBuzz");
        elseif i % 3 = 0 then
                SET result = concat(result, "Fizz");
        elseif i % 5 = 0 then
                SET result = concat(result, "Buzz");
        else
                SET result = concat(result, i);
        end IF;
        SET result = concat(result, "\n");
        SET i = i + 1;
end while;
RETURN result;
end //
SELECT fizzbuzz() //

Author:  PaulButler [ Sun Mar 25, 2007 11:12 am ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

Ocaml:

for i = 1 to 100 do
        print_endline (
                if i mod 15 = 0 then "FizzBuzz"
                else if(i mod 5 = 0) then "Buzz"
                else if(i mod 3 = 0) then "Fizz"
                else (string_of_int i));
done;;


(PS. this is my first O'Caml program, any tips wtd?)

Author:  PaulButler [ Sun Mar 25, 2007 11:23 am ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

Ocaml:

let rec fizzbuzz i = begin
        print_endline (
                if i mod 15 = 0 then "FizzBuzz"
                else if(i mod 5 = 0) then "Buzz"
                else if(i mod 3 = 0) then "Fizz"
                else (string_of_int i));
        if i < 100 then fizzbuzz (i + 1);
end;;
fizzbuzz 1;;


O'Caml with recursion instead of imperative syntax - still wondering if this could be more O'Camlized.

Author:  PaulButler [ Sun Mar 25, 2007 11:34 am ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

Perl:

#!/usr/bin/perl

for($i = 1; $i <= 100; $i++){
        if($i % 15 == 0){
                $o = "FizzBuzz";
        } elsif($i % 3 == 0){
                $o = "Fizz";
        } elsif($i % 5 == 0){
                $o = "Buzz";
        } else {
                $o = $i;
        }
        print "$o\n";
}

Author:  md [ Sun Mar 25, 2007 1:51 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

scheme:

(define (bar i)
  (cond ((equal? (+ (remainder i 3) (remainder i 5)) 0) "Fizzbuzz")
        ((equal? (remainder i 3) 0) "Fizz")
        ((equal? (remainder i 5) 0) "Buzz")
        (else i)))

(define (foo i max)
  (display (bar i))
  (newline)
  (if (< i max)
      (foo (+ i 1) max)))

Author:  haskell [ Sun Mar 25, 2007 5:29 pm ]
Post subject:  Re: RE:Fizz-Buzz: The Multi-Language Challenge

wtd @ Sun Mar 25, 2007 10:03 am wrote:
Can you write a program in Javascript?

Yes. Well, then... it's a programming language.

"Scripting language" is most frequently a derogatory language thrown around by users of heavyweight languages (C, C++, Java, C#, etc. you know who you are) to make themselves feel better about their choice of programming language, as opposed to those who use more lightweight languages.

Those of us who use both types of language think the whole dichotomy is pure bull crap.


Never were truer words ever spoken(or typed rather).

Author:  klopyrev [ Sun Mar 25, 2007 5:47 pm ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

heh...

Java Method:
code:

    void fizzbuzz ()
    {
        for (int i = 1 ; i <= 100 ; i++)
        {
            if (i % 15 == 0)
                System.out.print ("FizzBuzz\n");
            else if (i % 3 == 0)
                System.out.print ("Fizz\n");
            else if (i % 5 == 0)
                System.out.print ("Buzz\n");
            else
                System.out.print (i + "\n");
        }
    }


C++ Method:
code:

    void fizzbuzz ()
    {
        for (int i = 1 ; i <= 100 ; i++)
        {
            if (i % 15 == 0)
                cout << "FizzBuzz\n";
            else if (i % 3 == 0)
                cout << "Fizz\n";
            else if (i % 5 == 0)
                cout << "Buzz\n";
            else
                cout << i << "\n";
        }
    }


So similar!!!

KL

Author:  haskell [ Sun Mar 25, 2007 5:56 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

In C++ you should use endl not \n to end your lines with a newline.

Just throwing it out there.

Author:  klopyrev [ Sun Mar 25, 2007 6:28 pm ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

Yeah, I know! And for Java, I should use println. Just wanted to point out how similar they are, because Java doesn't have endl and C++ doesn't have println.

Author:  wtd [ Sun Mar 25, 2007 11:34 pm ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

PaulButler @ Mon Mar 26, 2007 12:23 am wrote:
Ocaml:

let rec fizzbuzz i = begin
        print_endline (
                if i mod 15 = 0 then "FizzBuzz"
                else if(i mod 5 = 0) then "Buzz"
                else if(i mod 3 = 0) then "Fizz"
                else (string_of_int i));
        if i < 100 then fizzbuzz (i + 1);
end;;
fizzbuzz 1;;


O'Caml with recursion instead of imperative syntax - still wondering if this could be more O'Camlized.


As with your previous program, very nice.

Ocaml:

let rec fizzbuzz i =
        print_endline (
                if i mod 15 = 0 then "FizzBuzz"
                else if i mod 5 = 0 then "Buzz"
                else if i mod 3 = 0 then "Fizz"
                else string_of_int i);
        if i < 100 then fizzbuzz (i + 1);;

fizzbuzz 1;;

Author:  zylum [ Mon Mar 26, 2007 1:18 am ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Java:
class FizzBuzz {
  public static void main(String[] args) {
        for (int i = 1; i <= 100; i++)
              System.out.println(i%3==0||i%5==0?(i%3==0?"Fizz":"")+(i%5==0?"Buzz":""):i);
  }
}

Author:  OneOffDriveByPoster [ Mon Mar 26, 2007 11:54 am ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

Trying something new (for me)--please tell me if you spot anything wrong or have any suggestions:
c++:
#include <string>
#include <iostream>
#include <sstream>

template <int lower, int upper, int mod3 = lower % 3, int mod5 = lower % 5>
struct FizzBuzz;

template <int lower>
struct FizzBuzz<lower, lower, 0, 0> {
    static std::string const &o(void) {
        static std::string const o = "FizzBuzz\n";
        return o;
    }
};

template <int lower, int mod5>
struct FizzBuzz<lower, lower, 0, mod5> {
    static std::string const &o(void) {
        static std::string const o = "Fizz\n";
        return o;
    }
};

template <int lower, int mod3>
struct FizzBuzz<lower, lower, mod3, 0> {
    static std::string const &o(void) {
        static std::string const o = "Buzz\n";
        return o;
    }
};

template <int lower, int mod3, int mod5>
struct FizzBuzz<lower, lower, mod3, mod5> {
    static std::string const &o(void) {
        static std::ostringstream ss;
        static std::string const o = (ss << lower << std::endl, ss.str() );
        return o;
    }
};

template <int lower, int upper, int mod3, int mod5>
struct FizzBuzz {
    static std::string const &o(void) {
        static std::string const o =
            FizzBuzz<lower, (lower + upper) / 2>::o()
            + FizzBuzz<(lower + upper) / 2 + 1, upper>::o();
        return o;
    }
};

int main(void) {
    std::cout << FizzBuzz<1, 100>::o();
    return 0;
}


EDIT: code changed from previous version

Author:  haskell [ Tue Mar 27, 2007 7:41 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Haskell
code:
import System
import System.IO

main = fizz_buzz(1)

fizz_buzz 101 = exitWith ExitSuccess
fizz_buzz x =
  do if ((x `rem` 15) == 0)
       then putStrLn(show "FizzBizz")             
       else if ((x `rem` 3) == 0)
         then putStrLn (show "Fizz") 
         else if ((x `rem` 5) == 0)
             then putStrLn(show "Buzz")           
             else putStrLn(show x)
     fizz_buzz(x+1)

Author:  rizzix [ Thu Mar 29, 2007 10:34 am ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Haskell:
main = mapM_ (\x -> putStrLn $ f x 3) [1 .. 100]
    where
        f x 3 = (case x `mod` 3 of 0 -> "Fizz"; _ -> "") >++ f x 5
        f x 5 = (case x `mod` 5 of 0 -> "Buzz"; _ -> f x 1)
        f x 1 = if x `mod` 3 /= 0 then show x else ""

Author:  haskell [ Thu Mar 29, 2007 11:57 am ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Quote:
Not in scope: `>++'


Using GHC Interactive, version 6.6 for Haskell 98.

This is because the forum syntax highlighter added the ">" on the string operation in this case. Which is an odd error.

Author:  haskell [ Thu Mar 29, 2007 3:52 pm ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

Lisp:

(defun fizz-buzz (x)
  (cond ((eq (mod x 15) 0)
         (format t "~%FizzBuzz"))
        ((eq (mod x 3) 0)
         (format t "~%Fizz"))
        ((eq (mod x 5) 0)
         (format t  "~%Buzz"))
        (t (format t "~%~D" x))))

(dotimes (x 101) (fizz-buzz x))

Author:  BenLi [ Thu Mar 29, 2007 6:32 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

somebody please do this in an esoteric programming language

Author:  haskell [ Thu Mar 29, 2007 8:43 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

I'm working a a BF solution. So, I guess you can wait on that one lol.

Author:  haskell [ Thu Mar 29, 2007 9:40 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Lisp:
(defun fizz-buzz (x)
  (cond ((zerop (mod x 15))
         (format t "~%FizzBuzz"))
        ((zerop (mod x 3))
         (format t "~%Fizz"))
        ((zerop (mod x 5))
         (format t  "~%Buzz"))
        (t (format t "~%~D" x))))

(dotimes (x 101) (fizz-buzz x))

Author:  tw1st [ Tue Apr 03, 2007 10:09 am ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

Disclaimer:
While this example is for the most part the same as md's, it employs 'good' programming techniques, at least in Pascal where a begin and an end is necessary when there is more than one operation. Yes, I realize that it is not necessary in this example, but if the purpose of this is to show how other languages work, then this would be a good thing to show.

Pascal:

program FizzBuzz;
uses crt;

var
   i : integer;

begin
   for i := 1 to 100 do
   begin
      if ((i mod 3) <> 0) and ((i mod 5) <> 0) then
      begin
         writeln(i);
      end
      else
      begin
         if (i mod 3) = 0 then
         begin
            write('Fizz');
         end;
         if (i mod 5) = 0 then
         begin
            write('Buzz');
         end;
         writeln('');
      end;
   end;
end.

Author:  md [ Tue Apr 03, 2007 10:58 am ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

I disagree. Using begin and end where there is no need just makes things larger and harder to read. I would say that my version is better Razz

Author:  wtd [ Tue Apr 03, 2007 12:55 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Even md used an unnecessary begin and end. But on the whole, his version is better.

Author:  zylum [ Thu Apr 05, 2007 3:07 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

BrainFuck:
++++++++++[>+++++++>++++++++++>++++++++++++>+++++++>++++++++++
++>++++++++++<<<<<<-]++++++++++>>+++++>++>---->--->[>+[>+>+<<-
]>>[<<+>>-]<>                                 +++<[>[->+>+<<]>
[-<<-[>]>>>[<                                 [>>>-<<<[-]]>>]<
<]>>>+<<[-<<+>>]<<<]>[-]>>>>[-<<<             <<+>>>>>]<<<<<[>
+>+<<-]>>[<<+>>-]<<[-]>[<+++>-             ]<[>+<-]><<[>+>>+<<
<-]>>>[<<<+>>>-]<[<->-]<>>+             <<[>]>>[<<<<<<<<<.>.>.
.>>>>>>>->>>>+<<<]<[-]<[             -]<[-]<[>+>+<<-]>>[<<+>>-
]<>+++++<[>[->+>+<<]>             [-<<-[>]>>>[<[>>>-<<<[-]]>>]
<<]>>>+<<[-<<+>>]<             <<]>[-]>>>>[-<<<<<+>>>>>]<<<<<[
>+>+<<-]>>[<<+>             >-]<<[-]>[<+++++>-]<[>+<-]><<[>+>>
+<<<-]>>>[<<             <+>>>-]<[<->-]<>>+<<[>]>>[<<<<<<.>.<<
..>>>>>>>             ->>>>+<<<]<[-]<[-]<[-]<>>>>>>>>>+<<[>]>>
[<<<<<             <<<<[>+>+<<-]>>[<<+>>-]<[>+>+<<-]>>[<<+>>-]
<>+                                                     ++++++
+++                                                     <[>[->
+>+                                                     <<]>[-
<<-[>]>>>[<[>>>-<<<[-]]>>]<<]>>>+<<[-<<+>>]<<<]>[-]>>>>[-<<<<<
+>>>>>]<<<<<>>>+<<<[>]>>[-<<++++++[<++++++++>-]<.>++++++[<----
---->-]>]>[-]<<<[<---------->-]++++++[<++++++++>-]<.[-]<>>>>>>
                                  >>>->]<[-]<<[-]<<<<<<<<<<<<<
                                                      <.[>]<<-
                                                             ]

Author:  md [ Thu Apr 05, 2007 3:57 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

/me hits zylum with an entire friggin forrest.

WHY?! Good god man! won't you think of the children!

Author:  zylum [ Fri Apr 06, 2007 11:07 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Smile it was quite fun and educational. it took me 3 friggin days! i bet it could be a lot shorter though. for example, i spotted at least 5 places in my code where i have '<>' which basically cancels itself out.

eidt: damnit! why don't the syntax tags support syntax highlighting for bf?

Author:  klopyrev [ Sat Apr 07, 2007 2:50 pm ]
Post subject:  Re: Fizz-Buzz: The Multi-Language Challenge

Wow... zylum... I'm amazed that works. How the hell did you manage to do that? I couldn't even figure out how to read a number in.

KL

Author:  PaulButler [ Tue Jul 10, 2007 4:16 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

I can't beat bf, but here are a couple more languages:

MzScheme (md already did scheme, but this is a bit different than his code)

This is basically a scheme version of what I would write in any imperative language, I know it could be done in many ways and this is probably one of the worse ones.

scheme:

(let x ((y 1))
    (if (= (modulo y 15) 0)
        (display "FizzBuzz")
        (if (= (modulo y 5) 0)
            (display "Buzz")
            (if (= (modulo y 3) 0)
                (display "Fizz")
                (display y))))
    (newline)
    (if (< y 100)
        (x (+ y 1))))


And in Groovy

Again, Groovy probably has some cool shortcuts I could have used, but I don't yet have the in-depth knowledge to know what those are.

code:

(1..100).step(1) {
        if (it % 15 == 0)
                println "FizzBuzz"
        else if (it % 3 == 0)
                println "Fizz"
        else if (it % 5 == 0)
                println "Buzz"
        else
                println it
}

Author:  Cervantes [ Tue Jul 10, 2007 5:20 pm ]
Post subject:  Re: RE:Fizz-Buzz: The Multi-Language Challenge

zylum @ Thu Apr 05, 2007 3:07 pm wrote:
BrainFuck:
++++++++++[>+++++++>++++++++++>++++++++++++>+++++++>++++++++++
++>++++++++++<<<<<<-]++++++++++>>+++++>++>---->--->[>+[>+>+<<-
]>>[<<+>>-]<>                                 +++<[>[->+>+<<]>
[-<<-[>]>>>[<                                 [>>>-<<<[-]]>>]<
<]>>>+<<[-<<+>>]<<<]>[-]>>>>[-<<<             <<+>>>>>]<<<<<[>
+>+<<-]>>[<<+>>-]<<[-]>[<+++>-             ]<[>+<-]><<[>+>>+<<
<-]>>>[<<<+>>>-]<[<->-]<>>+             <<[>]>>[<<<<<<<<<.>.>.
.>>>>>>>->>>>+<<<]<[-]<[             -]<[-]<[>+>+<<-]>>[<<+>>-
]<>+++++<[>[->+>+<<]>             [-<<-[>]>>>[<[>>>-<<<[-]]>>]
<<]>>>+<<[-<<+>>]<             <<]>[-]>>>>[-<<<<<+>>>>>]<<<<<[
>+>+<<-]>>[<<+>             >-]<<[-]>[<+++++>-]<[>+<-]><<[>+>>
+<<<-]>>>[<<             <+>>>-]<[<->-]<>>+<<[>]>>[<<<<<<.>.<<
..>>>>>>>             ->>>>+<<<]<[-]<[-]<[-]<>>>>>>>>>+<<[>]>>
[<<<<<             <<<<[>+>+<<-]>>[<<+>>-]<[>+>+<<-]>>[<<+>>-]
<>+                                                     ++++++
+++                                                     <[>[->
+>+                                                     <<]>[-
<<-[>]>>>[<[>>>-<<<[-]]>>]<<]>>>+<<[-<<+>>]<<<]>[-]>>>>[-<<<<<
+>>>>>]<<<<<>>>+<<<[>]>>[-<<++++++[<++++++++>-]<.>++++++[<----
---->-]>]>[-]<<<[<---------->-]++++++[<++++++++>-]<.[-]<>>>>>>
                                  >>>->]<[-]<<[-]<<<<<<<<<<<<<
                                                      <.[>]<<-
                                                             ]

I'm assuming whitespace is disregarded in bf and you did that on your own. I know you probably want the "z" to be for "zylum", but I first thought of "zoro". Sorry, but the picture of Zoro hacking computers is pretty awesome.

Author:  wtd [ Tue Jul 10, 2007 5:31 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

It'd be hard to type with a sword.

Author:  Martin [ Thu Jul 12, 2007 11:04 am ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Lua!

Lua:

for i=1,100 do
    if (i % 3) == 0 then
        print( "Fizz" )
    end
    if (i % 5) == 0 then
        print( "Buzz" )
    end
    if (i % 3) ~= 0 and (i%5) ~= 0 then
        print( i )
    end
end   


Also, zylum, you are my hero. That is truly awesome.

Author:  Aziz [ Thu Jul 12, 2007 1:27 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

How about pseudo-code?

pseudo:
for numbers 1 to 100
  if number modulo 3 = 0 then
    output "Fizz"
  else
    if number modulo 5 = 0 then
      output "Buzz"
    else
      output number
    endif
  endif
endfor

Author:  Martin [ Thu Jul 12, 2007 2:17 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

Careful, your algorithm has a bug in it.

Author:  Aziz [ Thu Jul 12, 2007 2:59 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

I see the bug. That first else isn't there. But then it screws up the rest of the logic so nvm it all.

Author:  zylum [ Thu Jul 12, 2007 6:44 pm ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

your algorithm never outputs "FizzBuzz"

Author:  Aziz [ Fri Jul 13, 2007 7:50 am ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

I know. I thought I had something neat, but of course effed up a simpler part.

Author:  Martin [ Fri Jul 13, 2007 8:35 am ]
Post subject:  Re: RE:Fizz-Buzz: The Multi-Language Challenge

Aziz @ Fri 13 Jul, 21:50 wrote:
I know. I thought I had something neat, but of course effed up a simpler part.


No excuses, fix it Wink

Author:  Aziz [ Fri Jul 13, 2007 8:42 am ]
Post subject:  RE:Fizz-Buzz: The Multi-Language Challenge

fine

code:
for numbers 1 to 100
  if number modulo 3 = 0 then
    output "Fizz"
  end if

  if number modulo 5 = 0 then
    output "Buzz"
  else
    if number modulo 3 != 0 then
       output number
    endif
  endif
endfor


Though number modulo 3 should be stored in a variable for effeciency, this is the logic


: