|
Post by bigbass on Nov 25, 2012 16:54:01 GMT 1
If you have another way post your code extra credit if you comment your code www.globalnerdy.com/2012/11/15/fizzbuzz-still-works/I confess I lost it took me more than five minutes to solve and I had to test the code well at least it works even if I am a bit slow its fun being back on BaCon ' FizzBuzz test
' Write a program that prints out the numbers from 1 through 100, but?
' For numbers that are multiples of 3, print "Fizz" instead of the number. ' For numbers that are multiples of 5, print "Buzz" instead of the number ' For numbers that are multiples of both 3 and 5, print "FizzBuzz" instead of the number. ' http://www.globalnerdy.com/2012/11/15/fizzbuzz-still-works/ ' Solved by Joe Arose for BaCon
y = 3 z = 5
FOR x = 1 TO 100
' checking for division by three AND division by five IF MOD(x,y) = 0 AND MOD(x,z) = 0 THEN PRINT " FizzBuzz", " ";
' checking for division by five ELIF MOD(x,z) = 0 THEN PRINT " Buzz", " ";
' checking for division by three ELIF MOD(x,y) = 0 THEN PRINT " Fizz ", " ";
ELSE PRINT x, " ";
ENDIF
NEXT
|
|
|
Post by vovchik on Nov 25, 2012 17:43:10 GMT 1
Dear Joe, Glad to see you back..... How about this? FOR A = 1 TO 100 IF MOD(A, 15) = 0 THEN PRINT "FizzBuzz", " "; ELIF MOD(A, 3) = 0 THEN PRINT "Fizz", " "; ELIF MOD(A, 5) = 0 THEN PRINT "Buzz", " "; ELSE PRINT A, " "; END IF NEXT A With kind regards, vovchik
|
|
|
Post by vovchik on Nov 25, 2012 18:29:18 GMT 1
and maybe this?
FOR I = 1 TO 100 A = MOD(I, 15) SELECT A CASE 0 PRINT "FizzBuzz", " "; CASE 3; CASE 6; CASE 9; CASE 12 PRINT "Fizz", " "; CASE 5 CASE 10 PRINT "Buzz", " "; DEFAULT PRINT I, " "; END SELECT NEXT I
|
|
|
Post by vovchik on Nov 25, 2012 19:29:15 GMT 1
Not certain my versions are workinng properly...have to do soem checking....
|
|
|
Post by bigbass on Nov 26, 2012 1:44:20 GMT 1
Hey vovchik Nice first example vovchik I realized 3x5 is 15 but I wanted to do an AND example before this test I didn't need to use the MOD command in BaCon so its nice to know we have that command available smaller code wins if its clear yours is perfectly compact so you win just NEXT is all that is needed shave one character I thought it would be fun to do it in BaCon since there was no way you could google it *I want more widgets so we have the same ones gtkdialog has but that's a lot of work but a great goal for the new year I didn't suggest I would do try doing it Joe
|
|