Multi
Multi
Fizz Buzz Code Golf; A bit of fun competition eh?
Topic Started: Tuesday, 8. January 2013, 20:49 (275 Views)
Andrew
Member Avatar
ぼくたちがすべてはばか。
This doesn't really fit into the battles forum so I decided to post it here. So lately I've been obsessed over something called code golf. Like in golf you try to get the lowest score possible. In code golf you try to solve the problem with a twist. The winner is the person whose program takes up the least amount of space in terms of bytes. For example, my entry takes up 59 bytes at the moment and uses 56 characters.

The challenge will be to fizz buzz (I love this question). The fizz buzz question is a question usually asked to weed out programmers. Programmers are asked to create a program on a piece of paper that prints out every number from 1-100. For every multiple of 3 print out "Fizz" instead of the number and for every multiple of 5 print out "Buzz" instead of the number. For multiples of 15 print out "FizzBuzz".

Prize: This isn't in the graphics battle section but I guess the prize could be 300 tokens?

Entry Fee: None just have fun.

My Entry




By the way...you can use any programming/scripting language you want.
Edited by Andrew, Tuesday, 8. January 2013, 20:50.
Posted Image

Professional web design/development services.http://wildandrewlee.com/
Off
Profile
Quote
Top
 
Sith
No Avatar
Fblthp
Longer than yours, but thought I'd write something that I could test. :P

Java:
Code:
 
public class FizzBuzz
{
public static void main(String args[])
{
for(int i = 1; i <= 100; i++)
{
if(i%15 == 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);
}
}
}
Posted Image

Last.fm
Off
Profile
Quote
Top
 
Andrew
Member Avatar
ぼくたちがすべてはばか。
Looks great :D Love Java :3

Here are my attempts with it.

Code: Java
 
//Pretty good for a first attempt.
class FizzBuzz{
public static void main(String[]args){
for(int n=0;n++<100;System.out.println(n%15==0?"FizzBuzz":n%3==0?"Fizz":n%5==0?"Buzz":n));
}
}

//Second attempt.
enum q{
g;{
for(int n=0;n++<100;System.out.println(n%15==0?"FizzBuzz":n%3==0?"Fizz":n%5==0?"Buzz":n));
}
}

//Let's see how short I can make this.
enum l{
o;{
for(int l=0;l++<100;System.out.println((l%3==0?"Fizz":"")+(l%5==0?"Buzz":l)));
}
}

//Pretty sure I can do better than that.
enum m{
n;{
for(int p=0;p++<100;System.out.println((p%3>0?"Fizz":"")+(p%5==0?"Buzz":p)));
}
}

//Compressed
enum j{k;{for(int z=0;z++<100;System.out.println((z%3>0?"Fizz":"")+(z%5==0?"Buzz":z)));}}
Posted Image

Professional web design/development services.http://wildandrewlee.com/
Off
Profile
Quote
Top
 
RedBldSandman
Member Avatar
Madness!
Code:
 
100,{):a;{{a 3%!}~"Fizz"*{a 5%!}~"Buzz"*+}~ . a if print}/
Pretty fun, could probably do better if I was more familiar with GolfScript but it's a bit tedious :P Code Golf with any language allowed normally means GolfScript will win from what I've seen XD
Posted Image
Off
Profile
Quote
Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Media & Technology · Next Topic »

Welcome Guest [Log In] [Register]
Outline Live
Loading..
Loading..