Re:Streem – a new programming language from Matz
by boomlinde on Thursday December 11, 2014 @01:26PM
(#8736280)
Whether you print the number, Fizz, Buzz or FizzBuzz you are going output a line break, so I'm not sure what you would be checking for. Output \n unconditionally.
Re:Streem – a new programming language from Matz
by blt on Thursday December 11, 2014 @03:47PM
(#8736981)
Then you call `printf` twice every loop instead of once. `printf` is buffered so you aren't making two system calls, but you are still making two function calls.
Re:Streem – a new programming language from Matz
by boomlinde on Friday December 12, 2014 @11:38AM
(#8741027)
Maybe it's a performance/brevity compromise, but the latter is the issue the I addressed. The least-calls solution would probably be to print the whole output as a single string constant.
Re:Streem – a new programming language from Matz
by zem on Thursday December 11, 2014 @02:03PM
(#8736476)
then you'd get
\n
\n
fizz\n
\n
buzz\n
rather than
fizz\n
buzz\n
Re:Streem – a new programming language from Matz
by dllthomas on Thursday December 11, 2014 @02:13PM
(#8736534)
The canonical FizzBuzz wants
1\n2\nFizz\n4\nBuzz\n...\nFizzBuzz\n
If you did not print anything for some cases, you're right that it could not be unconditional (though it could still be done at the end with a flag).
Re:Streem – a new programming language from Matz
by zem on Thursday December 11, 2014 @02:18PM
(#8736560)
oops, yes, my mistake.
Re:Streem – a new programming language from Matz
by mden on Thursday December 11, 2014 @05:32PM
(#8737434)
In some languages you can hide the extra check:
for i in range(1,100):print("Fizz"(i%3==0) + "Buzz"(i%5==0) or i)
Re:Streem – a new programming language from Matz
by thedufer on Friday December 12, 2014 @12:02PM
(#8741215)
For others who are confused by this syntax, it appears that there are *'s that got eaten and turned into italics.
Re:Streem – a new programming language from Matz
by stonemetal on Thursday December 11, 2014 @02:39PM
(#8736649)
string output = numb.toString();
if(numb % 3 == 0) ouput = "Fizz";
if(numb % 5 == 0) output.Append("Buzz");
write output;
It is possible to use two checks to cover all three fizzbuzz components.
Of course, it can be actually shorter with a goto.