FizzBuzz Solution Dumping Ground

Doing it in php, the other way

<?php for($i=1;$i<=100;$i++){ switch($i){ case($i%3===0 && ($i%5)!==0): echo "Fizz"."
"; break; case($i%5===0 && ($i%3)!==0): echo "Buzz"."
"; break; case($i%5===0 && $i%3===0): echo "FizzBuzz"."
"; break; default: echo $i."
"; } } ?>

string strTemp = “”;
for (int i = 1; i <= 100; ++i, strTemp = “”)
{
strTemp = ((((i % 3) == 0) ? “Fizz” : “”) + (((i % 5) == 0) ? “Buzz” : “”));
Console.WriteLine(((strTemp.Length == 0) ? i.ToString() : strTemp));
}
Console.ReadKey();

No love at all for Brainfuck here?

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

1 Like

Only 162 bytes assembled!

;

This is my version (the batch file for XP cmd):
::===================FizzBuzz.cmd========================
@echo off
for /l %%i in (1,1,100) do call :output %%i
goto :end

:output
set OUT=%1
set /A T=%1%%3
if [%T%]==[0] set OUT=Fizz
set /A T=%1%%5
if not [%T%]==[0] goto :out2
if not [%OUT%]==[Fizz] set OUT=
set OUT=%OUT%Buzz
:out2
echo %OUT%
:end
::==============================================

Mathematica:

GCD[#, 15] /. {3 -> Fizz, 5 -> Buzz, 15 -> FizzBuzz, _ -> #} & /@ Range[100]

I am a 10th grader from pakistan and my answer to the FizzBuzz question is following:
For A=1 to 100
B=A/3
B=B+1
Repeat
B=B-1
Until B<=1 and B>0
C=A/5
C=C+1
Repeat
C=C-1
Until C<=1 and C>0
If B=1 and C=1 then
Write [“FizzBuzz”]
End If
If B=1 and C<1 then
Write [“Fizz”]
End If
If C=1 and B<1 then
Write [“Buzz”]
End If
If B<1 and C<1 then
Output A
End If
Next A

I guess I was brought up learning to program on Sinclairs - amazing how you can learn BASIC as a simple language and then move onto other languages, such as Perl, PHP and even 68000 machine code…

Fizzbuzz:
Sinclair QL SuperBASIC

10 FOR i=1 TO 100
20 PRINT i;’ ';
30 IF (i mod 3)=0:PRINT "FIZZ"
40 IF (i mod 5)=0:PRINT "BUZZ"
50 PRINT
60 END FOR i

68000 Assembly Language (on the QL):
start MOVEQ #-1,D1 ;Open a screen channel
LEA screen,A0
MOVEQ #2,D3
MOVEQ #1,D0
TRAP #3 ;Uses built in ROM routine to open screen
BNE.S end
MOVEQ #1,D6 ;Initial Loop value
loop MOVE.L (A6),A1
LEA 2(A1),A0
MOVE.W D6,0(A6.A1.L) ;store value on stack

       MOVE.L D6,D7
       DIVU  #3,D7
       SWAP  D7
       CMPI.W #0,D7
       BEQ.S testbuzz
       LEA fizz,A1
       MOVE.W $D0,A2
       JSR (A2)

testbuzz MOVE.L D6,D7
DIVU #5,D7
SWAP D7
CMPI.W #0,D7
BEQ.S nwline
LEA buzz,A1
MOVE.W $D0,A2
JSR (A2)
nwline MOVEQ #10,D1 ;Print a new line
BSR.S printchr
CMPI.B #100,D6
BEQ.S end
ADDQ.B #1,D6
BRA.S loop
end MOVEQ #0,D0
RTS
printchr MOVEQ #-1,D3
MOVEQ #5,D0
TRAP #3
MOVEQ #0,D0
RTS
digits ds.b 6
screen DC.W 17
DC.B ‘con_448x200a32x16’,0
fizz DC.W #4
DC.B 'FIZZ’
buzz DC.W #4
DC.B ‘BUZZ’

Sorry - made an error when typing the 68000 assembly language in - I hit a key which submitted the form!

start MOVEQ #-1,D1 ;Open a screen channel
LEA screen,A0
MOVEQ #2,D3
MOVEQ #1,D0
TRAP #3 ;Uses built in ROM routine to open screen
BNE.S end
MOVEQ #6,D1
MOVE.L A1,$58(A6) ; make room on maths stack for 6 bytes
MOVE.W $11A,A2
JSR (A2)
MOVE.L $58(A6),A1
MOVEQ #1,D6 ;Initial Loop value
loop MOVE.L (A6),A1
LEA 2(A1),A0
MOVE.W D6,0(A6.A1.L) ;store value on stack
MOVE.W $F2,A2
JSR (A2) ;convert number to ASCII
MOVE.W D1,D2 ; grab length of number
MOVEQ #7,D0
MOVEQ #-1,D3
TRAP #3
MOVE.L D6,D7
DIVU #3,D7
SWAP D7
CMPI.W #0,D7
BEQ.S testbuzz
LEA fizz,A1
MOVE.W $D0,A2 ; print string
JSR (A2)
testbuzz MOVE.L D6,D7
DIVU #5,D7
SWAP D7
CMPI.W #0,D7
BEQ.S nwline
LEA buzz,A1
MOVE.W $D0,A2
JSR (A2)
nwline MOVEQ #10,D1 ;Print a new line
BSR.S printchr
CMPI.B #100,D6
BEQ.S end
ADDQ.B #1,D6
BRA.S loop
end MOVEQ #0,D0
RTS
printchr MOVEQ #-1,D3
MOVEQ #5,D0
TRAP #3
MOVEQ #0,D0
RTS
screen DC.W 17
DC.B ‘con_448x200a32x16’,0
fizz DC.W #4
DC.B 'FIZZ’
buzz DC.W #4
DC.B ‘BUZZ’

Rich Mellor
http://www.sellmyretro.com

I failed my intro to computer science course where they taught me java. It’s been over six months. I dont have java installed any more but here’s what I did in my text editor in 5 minutes.

public class NewClass{
public static void main(String[] args){
int i = 1;
while (i <= 100){
if (i % 15 == 0){
System.out.println(“FizzBuzz”);
}else if (1 % 5 == 0){
System.out.println(“Buzz”);
}else if (1 % 3 == 0){
System.out.println(“Fizz”);
}else{
System.out.println(i + “”);
}
}
}
}

I dont have java so I cant test it but im pretty sure i have it or am close. This is just to prove that that 199/200 thing is serious bullshit.

HI guys.
As a student, I feel that the teachers spend a lot of time giving us long long pages of things to put together rather than spending enough time on getting concrete sets of knowledge together-I’ll work on that this year.
My solution uses java-bugger using C and pointers and all that.
Now, I am intending to code for the following:
-print out numbers from 1 to 100 inclusive
-however, numbers that are divisible by 3, get repalced by Fizz, those with 5 get replaced by Buzz, and those that are divisible by both 3 and 5 (i.e by 15) get replaced by FizzBuzz.
I hope my code does what is required:
public class Main {

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

}

}

In 4 lines, with PHP

for ($i = 1; $i <= 100; $i++) {
$fizzbuzz = ($i % 3 == 0 ? “Fizz” : “”).($i % 5 == 0 ? “Buzz” : “”);
echo strlen($fizzbuzz) ? $fizzbuzz : $i;
}

Java? Java.

for (int i = 1; i <= 100; i ++)
{
String Mult3 = i % 3 == 0 ? “Fizz” : “”;
String Mult5 = i % 5 == 0 ? “Buzz” : “”;

System.out.println(i + " " + M3 + M5);
}

I like Java…

for(i=1;i<=100;i++){
console.log((i%5 == 0 && i%3 == 0 && “FizzBuzz”) || (i%5 == 0 && “Buzz”) || (i%3 == 0 && “Fizz”) || i);
}

This is how I’d do it in JS

I don’t think this article can be completely correct more so the comments being thrown around. I’m currently in college as a Computer Science major and I had to learn recursion way back in beginning programming class. It was just the hey this is what it is and how you can do it. Since I’ve taken the more advanced classes now. We have to use it in some of the solutions such as Traversing Tree’s or graphs usually. I also learned Hexadecimal and Binary conversions and the operations on them.

Also I would say that my University not the best at all as far University go. It’s one of the cheapest in the state.
Java -
Console run by -
javac FizzBuzz.java
java FizzBuzz
public class FizzBuzz
{
public FizzBuzz()
{
}
public static void main(String[] args)
{
for(int i = 1; i<= 100; i++)
{
if( (i % 3) == 0 && (i % 5) == 0 )
System.out.println(“FizzBuzz”);
else if(i % 5 == 0)
System.out.println(“Buzz”);
else if(i % 3 == 0)
System.out.println(“Fizz”);
else
System.out.println(i);
}
}
}

In C :
#include <stdio.h>

int main()
{
int i=1;
for(i; i<=100;i++)
{
if(i%3==0)
{printf(“FIZZ”);
}if(i%5==0)
{printf(“BUZZ”);
}if(i%3!=0 && i%5!=0)
{printf("%d\n", i);
}else{printf("\n");
}
}
return 0;
}

perl -le’print$%15?$%5?$%3?$:fizz:buzz:fizzbuzz for 1…100’

C# LinqPad Program:
void Main()
{
IEnumerable nums = Enumerable.Range(1, 100);
foreach( int i in nums)
{
string result = (i % 3 == 0) ? “Fizz” : (i % 5 == 0) ? “Buzz” : i.ToString();
result.Dump();
}
}

in C# i can write it in just 2 lines

for (int i = 1; i <= 100; i++)
Console.WriteLine(i.ToString() + " : " + (((i % 3 == 0) && (i % 5 == 0)) ? “FizzBuzz” : (i % 3 == 0 ? “Fizz” : (i % 5 == 0 ? “Buzz”:i.ToString()))));

My C# version

foreach(var i in Enumerable.Range(1,100).Select(i => (i % 15 == 0) ? “FizzBuzz” : (i % 3) == 0 ? “Fizz” : (i % 5) == 0 ? “Buzz” : i.ToString()))
{
Console.Write(i);
}
Console.WriteLine();

Or LINQ

var s = from i in Enumerable.Range(1, 100)
select new
{
value = (i % 15 == 0) ? “FizzBuzz” : (i % 3) == 0 ? “Fizz” : (i % 5) == 0 ? “Buzz” : i.ToString()
};
foreach(var i in s) System.Console.Write(i.value);
Console.WriteLine();