Make a program(in the language of your choice), that goes like this:
1)Prints all numbers from one to one hundred
2)For every number that can be divided with 3, it writes "fizz" next to the number.
3)For every number that can be divided with 5, it writes "buzz".
This a common problem employers give to seperate the Expert programers from the Enterprise Qulity Programmers. Surprisingly, not many programmers can. I made one in BASIC in 5 minutes.
Not tested, but should be good. Written in 7 minutes.
Name:
Anonymous2007-09-01 20:34 ID:qPfamYiZ
####
# This is according to the problem set, but the example
# had the words "Fizz" and "Buzz" switched.
# Less than 3 minutes.
def fizzbuzz():
for num in range(1, 101):
word = " "
if not num % 3:
word += "Fizz"
if not num % 5:
word += "Buzz"
int main ()
{
for (int i = 1; i < 101; i++)
{
cout << i << " ";
if (i %3 == 0)
cout << "Fizz";
if (i%5 == 0)
cout << "Bizz";
cout << endl;
}
return 1;
}
[pre]let f x = (if x `mod` 3 == 0 then "Fizz" else []) ++ (if x `mod` 5 == 0 then "Buzz" else []) in mapM_ (\x -> putStrLn (show x ++ " " ++ f x)) [1 .. 100][/pre]
Name:
Anonymous2007-09-02 0:17 ID:FAq2f+pY
It seems /prog/ is doing fairly well... Another challenge will come soon...
factor: 100 [ 1+ dup 15 mod zero? [ drop "FizzBuzz" ] [ dup 3 mod zero? [ drop "Fizz" ] [ dup 5 mod zero? [ drop "Buzz" ] [ number>string ] if ] if ] if print ] each
Name:
Anonymous2007-09-02 7:46 ID:2Kos+EeY
print '\n'.join((lambda o=('','Fail')[not n%3]+('','Sage')[not n%5]:(o,`n`)[not o])()for n in xrange(1,101))
Untested, but should work.
Name:
Anonymous2007-09-02 7:50 ID:TNwnL0cy
so this is like 4chan but with cranky programmers instead of pictures huh
Name:
Anonymous2007-09-02 8:01 ID:yXa5pFup
>>36 so this is like 4chan
Look at your address bar, cockfuck, this is 4chan.
>>42
True. It will probably work as a first screening test to weed out the ENTERPRISE fuckwits who have an impressive list of certificates and no programming skills whatsoever, though.
>>42
Well, if your employer gives you this problem, he's probably crap.
Name:
Anonymous2007-09-02 9:53 ID:yXa5pFup
>>45
or he reads digg all day to check out WHATZ NEW IN DA BLOGOSFEAR
Name:
Anonymous2007-09-02 10:02 ID:dQk8FlwG
;FIZZBUZZ - DOES STUFF ABOVE
CHROUT EQU $FFD2 ;COMMODORE 64 ROUTINE THAT PRINTS CHARACTER IN .A TO STDOUT; CHANGE ACCORDINGLY FOR OTHER ARCHITECTURES
WHICH .DB 0
POINT3 .DB 0
POINT5 .DB 0
FZBZ LDA #$00
STA WHICH
NEXT INC WHICH
LDA WHICH
JSR PRINTA
LDA #32 ;PRINT A SPACE
JSR CHROUT
LDA WHICH
CMP #101
BEQ GTFO
INC POINT3
LDA POINT3
CMP #3
BNE SKIP1
JSR BUZZ
LDA #0
STA POINT3
SKIP1 INC POINT5
LDA POINT5
CMP #5
BNE SKIP2
JSR FIZZ
LDA #0
STA POINT5
SKIP2 LDA #13 ;PRINT A CR
JSR CHROUT
JMP NEXT
;I'M TOO TIRED RIGHT NOW TO ACTUALLY WRITE OUT THESE ROUTINES
;REST ASSURED THAT DUE TO MY EXPERT PROGRAMMER ABILITY THAT I CAN
FIZZ ;PRINTS FIZZ
BUZZ ;PRINTS BUZZ
PRINTA ;CONVERT NUMBER IN .A TO INTEGER AND PRINT IT, NO NEWLINE
Name:
Anonymous2007-09-02 10:30 ID:G85jbkOo
Python, 1.5 minutes:
def fizzbuzz():
for num in range(1, 101):
out = ""
if num % 3 == 0: out = "Fizz"
if num % 5 == 0: out += "Buzz"
print num, out
Factor, roughly 5 minutes:
: check ( str div num -- ) swap mod 0 = [ write ] [ drop ] if ;
: output ( num -- num ) dup number>string write " " write ;
: fizz ( num -- num ) dup "Fizz" 3 rot check ;
: buzz ( num -- num ) dup "Buzz" 5 rot check ;
: fizzbuzz 1 100 [ output fizz buzz "" print 1 + ] times drop ;
>>61 has a bug, but fixed :)
%a = ('fizz', '$i % 3', 'buzz', '$i % 5');
for $i (1..100) {
eval $b and $c .= $a while ($a, $b) = each %a;
print "$i$c\n" and $c = q{}}
int main(void)
{
int i;
int r = 0;
char buff[] = "FizzBuzz";
for (i = 1; i <= 100; i++) {
sprintf(buff, "%d", i);
if (! (i % 3))
r = sprintf(buff + r, "%s", "Fizz");
if (! (i % 5))
r = sprintf(buff + r, "%s", "Buzz");
puts(buff);
r = 0;
}
Both my posts :)
I just really enjoy writing prolog. It was previously said about another language, but I do think programs written in prolog take longer to think about than to type.
Still you wouldnt want to implement an operating system with it.....
Or would you?
Name:
Anonymous2007-09-03 8:41 ID:KJvW0vyq
So is anyone going to attempt to solve this in constant time using a template function?
Name:
Anonymous2007-09-03 8:49 ID:KJvW0vyq
public class FizzBuzz
{
public static void main ( String [] argv )
{
for( int i=0,j=0,k=0; i <= 100; i++ )
{
System.out.print(i+" ");
if( j == 3 )
{ System.out.print("fizz"); j = 0; }
if( k == 5 )
{ System.out.print("buzz"); k = 0; }
j++;
k++;
System.out.println();
}
}
}
>>82
This doesn't proactively create synergies or maximize profits by following best practices. Make it more ENTERPRISE.
Name:
Anonymous2007-09-03 8:59 ID:KJvW0vyq
/**
* Autor: Anonymous
* Date: 2007-09-03
* Class: FizzBuzz
* Description: Outputs the numbers 1 to 100 on each line
* Whilst writing fizz or buzz if the linenumber is
* divisible by 3 or 5 respectivley.
*/
public class FizzBuzz
{
/* main entry point */
public static void main ( String [] argv )
{
/* For loop from 1 to 100 inclusive */
for( int i=0,j=0,k=0; i <= 100; i++ )
{
System.out.print(i+" ");
if( j == 3 )
{
//Prints fizz when required
System.out.print("fizz"); j = 0; }
if( k == 5 )
{
//Prints buzz when required
System.out.print("buzz"); k = 0; }
//Increment
j++;
k++;
//Print a newline character
System.out.println();
}//EndFor
}//End main
}//End Class: FizzBuzz
>>98
Which is basically what I wrote yesterday, only using more forced indentation of code.
Name:
Anonymous2007-09-03 12:31 ID:KJvW0vyq
>>96
Is this the difference between a Webmonkey and a Codemonkey?
A webmonkey is concerned with how it looks,
Whereas a codemonkey is only concerned with how it works?
Maybe the challenge was not to produce code, but to challenge the requirements. That is what any software engineer, no any self respecting IT professional should do.