|
Post by Rod on Jan 18, 2019 9:05:36 GMT
It would seem that applicants for programming positions face a barrage of testing prior to and during interview. I'm not a fan of such challenges. But be prepared 'Apparently the FizzBuzz challenge is something programmers may 'face at job interviews.
'"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”."
t=time$("ms")
while counter<100 counter=counter+1 if counter/3=int(counter/3)then if counter/5=int(counter/5) then print "FizzBuzz" else print "Fizz" end if else if counter/5=int(counter/5) then print "Buzz" else print counter end if end if wend
print time$("ms")-t
I'm sure it could be slicker, one point, you get five minutes to code a solution!
|
|
|
Post by Rod on Jan 18, 2019 9:22:53 GMT
Our rosetta code solution.
for i = 1 to 100 select case case i mod 15 = 0 print "FizzBuzz" case i mod 3 = 0 print "Fizz" case i mod 5 = 0 print "Buzz" case else print i end select next i
|
|
|
Post by tsh73 on Jan 18, 2019 11:07:54 GMT
for i= 1 to 100 printed =0 if (i mod 3)=0 then printed = 1: print "Fizz"; if (i mod 5)=0 then printed = 1: print "Buzz"; if not(printed) then print i; print next
I did't measure time (read program description and started coding - didn't got to the end of post).
But it took some debug to run right.
|
|
|
Post by Rod on Jan 18, 2019 12:10:17 GMT
Very slick way to join the words.
|
|
|
Post by tsh73 on Jan 18, 2019 17:43:12 GMT
About "slick way to join words". I end using flag variable - I need something done on (i mod 3 =0) AND something (i mod 3 =0) and something on ELSE. Nicely lies on SELECT CASE, yes? But there is a case of ((i mod 3 =0) AND (i mod 3 =0)) (actually to write (i mod 15 =0) just not happened to me) and C have BREAK on SWITCH statement so we kind of can have print Fizz on 3 - break print Fizz on 3 - NO break print Buzz on 5 - break print number on DEFAULT (actually now I pretty sure I am wrong) … The only problem that we can't do that in C. SWITCH in C is on constants only SWITCH in C# has BREAK on each CASE and SELECT CASE in VB NET does not have BREAK. So pseudo-C pseudo-code: /*fizzBuzz task*/ //oops impossible as thought - in C #include <stdio.h> int main(void) { int i; for(i=1;i<=100;i++) { switch() //not in C { case i%3==0: //not in C printf("Fizz"); //strategically NOT placed BREAK case i%5==0: //not in C printf("Buzz"); break; default: printf("%d",i); } printf("\n"); } return 0 }
And I'll stick to BASIC
EDIT actually I have working C code along these lines. But it ends somewhat complex.But it ends somewhat completely different
|
|
|
Post by B+ on May 7, 2019 13:14:18 GMT
I had this written up some time ago, forgot to post it here: "BizzFizzBuzzFuzzWow" check$ = "0203050711": say$ = "BizzFizzBuzzFuzzWow" FOR i = 1 TO 100 Flag = 1 FOR j = 0 TO 4 IF i MOD VAL(MID$(check$, j * 2 + 1, 2)) = 0 THEN PRINT MID$(say$, j * 4 + 1, 4);: Flag = 0 NEXT IF Flag THEN PRINT i ELSE PRINT NEXT
|
|
|
Post by zzz000abc on May 13, 2019 9:54:24 GMT
here is one more way...
insert code here for i=1 to 100 f$="":b$="" if i mod 3 =0 then f$="FIZZ" if i mod 5 =0 then b$="BUZZ" if f$+b$="" then print i else print f$+b$ next
|
|
|
Post by B+ on May 13, 2019 13:13:46 GMT
Using JB word$:
FOR i = 1 TO 100 b$ = "" FOR w = 1 TO 5 IF i mod val(word$("2 3 5 7 11", w)) = 0 THEN b$ = b$ + word$("Bizz Fizz Buzz Fuzz Wow", w) NEXT IF b$ = "" THEN PRINT i ELSE PRINT b$ NEXT
|
|
|
Post by tsh73 on May 13, 2019 13:30:59 GMT
Using output as flag, clever.
|
|