People who code come from all walks of life and programming isn't always part of their profession. Some people receive proper training at a school, yet others learn on their own, and sometimes even a little bit of both. This sort of variety allows people to approach the same problem in a myriad different ways.
So then, let us all try this popular FizzBuzz exercise:
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
The purpose of this exercise is not to get the problem right or wrong (it was not chosen for its difficulty), but to demonstrate our different approaches to the problem.
## When posting your solution please tell us a little about yourself and your background in programming. ##
>>2
Reading comprehension not your strong suit, then?
I don't really think FizzBuzz is complex enough to get huge difference in style, but alright.
I started out with PHP on my own, then spent a few years at a Java school, and finally ended up learning languages on my own because it became apparent I couldn't count on my professors.
C is one of my favorites, and I initially picked it up from K&R. At first I used Java indentation style because that's what I was used to, but eventually I moved to full K&R, because it's just more beautiful.
There are fancier ways to write FizzBuzz, but I like clarity.
#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i <= 100; ++i) {
if (i % 15 == 0)
printf("FizzBuzz\n");
else if (i % 3 == 0)
printf("Fizz\n");
else if (i % 5 == 0)
printf("Buzz\n");
else
printf("%d\n", i);
}
return 0;
}
Name:
Anonymous2010-06-08 14:05
>>2
This is not a FizzBuzz thread. This is a thread to compare and contrast our different approaches to a problem. That problem just happens to be FizzBuzz.
Name:
Anonymous2010-06-08 14:06
showar x | m3 && m5 = "FizzBuzz"
| m3 = "Fizz"
| m5 = "Buzz"
| otherwise = show x
where [m3,m5] = map ((==0).mod x) [3,5]
i am a 24yo year old psychology bachelor's working in retail. i am self taught in programming.
#!/usr/bin/python3000
for j in range(1,100):
if j%5==0 and j%3!=0:
print "Bizz"
elif j%3==0 and j%5!=0:
print "Fizz"
elif j%3==0 and j%5==0:
print "FizzBizz"
else:
print str(j)
I am not a classically trained programmer. I started out by editing CGI web scripts. At first I only made small changes, then bigger changes, and eventually I started writing my own web scripts. My personal rule of programming: Write the least amount of code as possible, so long as it is consistent in style and is readable.
As for a little bit about myself, I was a psych major at first (wanted to be an industrial psychologist), but then I decided I wanted to be a pharmacist instead, so now I'm biochem major. Not sure how that influences my coding.
As for the background; I've been programming for a year and a half, started with SICP, then learned Haskell and C to write fun programs for myself and C# to code for money.
int main(void)
{ for(uint_fast8_t i = 1; i <= 100; ++i)
switch(i % 15)
{ case 0:
puts("FizzBuzz"); break;
case 3: case 6: case 9: case 12:
puts("Fizz"); break;
case 5: case 10:
puts("Buzz"); break;
default:
printf(PRIuFAST8 "\n", i); }
return 0; }
Name:
Anonymous2010-06-08 15:30
int i, t, f;
for (i = t = f = 0; i < 100; i++, t++ %= 3, f++ %= 5) {
if (!t)
printf ("Fizz");
if (!f)
printf ("Buzz");
if (t && f)
printf ("%d", i);
printf ("\n");
}
Background: I am an EXPERT since birth
>>1
People say im insane, but they just say that because im smarter then them. I am constantly drunk and like to trip on acid. I make money by making obscure paintings of anuses.
and here is my solution to your problem:
#!/usr/bin/perl
my $dick = '=';
sub disks {
$dick x= 2; #I wish it could do better
print '8'. $dick. 'D'; #i hope you have much memory
fork(); #Prints Fizz
disks(); #Prints Buzz
}
>>26
Basically Anal Cunt's logo. He got about 78 cents.
Name:
Anonymous2010-06-08 19:55
They don't have to printed in order, right?
Junior undergrad CS fag, start programming so I could bot on runescape, then realized it was pretty interesting.
#include <pthread.h>
#include <stdio.h>
void* multiples_of_three(void* pause)
{
int* p = pause; /* Don't want to deal with TWO mutexes */
for(int i=0; i <= 100; i += 3)
{
if(i % 5 == 0)
{
while(*p == 0);
printf("Fizz", i);
*p = 2;
while(*p == 2);
}
else
printf("Fizz\n", i);
>>24
I dont know why everyone always thinks im trolling.
Experience: took an intro programming class and 1 higher lvl programming class. Trying to independently study this summer, hence the poor scheme coding i learned from reading a few pages of SICP (Recommended to be by /g/)
Prelude> take 20 $ flip fmap [0..] floop
[1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800,87178291200,1307674368000,20922789888000,355687428096000,6402373705728000,121645100408832000]
U MENA FLOOPTORIAL