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.
>>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?