Here's my one in Python 3:
[(str(i) if (i%3 and i%5) else "")+("Fizz" if not i%3 else "")+("Buzz" if not i%5 else "") for i in range(1, 100)]
[(str(i) if (i%3 and i%5) else "")+("Fizz" if not i%3 else "")+("Buzz" if not i%5 else "") for i in range(1, 100)]
Wouldn't you have to put –snip–
print
Depends on how you run it.Wouldn't you have to put –snip–in the beginning of your code for it to output the test though?
Or is outputting not really necessary, just the calculation?
["Fizz"*(1-x%3)+"Buzz"*(1-x%5)or str(x)for x in range(1,100)]
setMy 'Output' ''
for i 100 {
if ((i % 3) == 0) {
setMy 'Output' (join 'Fizz' (join ',' (newline)) (toString (my 'Output')))
} ((i % 5) == 0) {
setMy 'Output' (join 'Buzz' (join ',' (newline)) (toString (my 'Output')))
} else {
setMy 'Output' (join (toString i) (join ',' (newline)) (toString (my 'Output')))
}
}
new Array(100).fill('').map((v,i)=>(++i%3?v:'Fizz')+(i%5?v:'Buzz')||i)
#include <stdio.h> int main(boop) { int i; for(i = 1; i <= 100; ++i) { if (i % 3 == 0) printf("Fizz"); if (i % 5 == 0) printf("Buzz"); if ((i % 3 != 0) && (i % 5 != 0)) printf("%d", i); printf("\n"); } return 0; }
#include <iostream> int main() { for (int i = 1; i <= 100; i++) { if (i%5==0) std::cout << "Buzz" << std::endl; else if (i%3==0) std::cout << "Fizz" << std::endl; else std::cout << i << std::endl; } return 0; }
printf is slow cout is better. C:#include <stdio.h> int main(boop) { int i; for(i = 1; i <= 100; ++i) { if (i % 3 == 0) printf("Fizz"); if (i % 5 == 0) printf("Buzz"); if ((i % 3 != 0) && (i % 5 != 0)) printf("%d", i); printf("\n"); } return 0; }
#include <iostream>
using namespace std;
int main() {
for (int i=1;i<100;i++) {
if (i%3==0)
cout << "Fizz";
if (i%5==0)
cout << "Buzz";
if (i%3&&i%5)
cout << i;
cout << "\n";
}
return 0;
}
That fizzbuzz isn't correct since it will never output “FizzBuzz” on one line and also std::endl causes a delay just use \n in the string C:C++:#include <stdio.h> int main(boop) { int i; for(i = 1; i <= 100; ++i) { if (i % 3 == 0) printf("Fizz"); if (i % 5 == 0) printf("Buzz"); if ((i % 3 != 0) && (i % 5 != 0)) printf("%d", i); printf("\n"); } return 0; }#include <iostream> int main() { for (int i = 1; i <= 100; i++) { if (i%5==0) std::cout << "Buzz" << std::endl; else if (i%3==0) std::cout << "Fizz" << std::endl; else std::cout << i << std::endl; } return 0; }
“a delay” also std::endl causes a delay
https://stackoverflow.com/a/35581029“a delay” also std::endl causes a delay
Sorry, I assumed you didn't actually know what endl was actually doing when you said it was just “a delay” so I was commenting on that. Looks like you do know what you're talking about thoughsnip“a delay” also std::endl causes a delay
I first discovered it had some sort of delay when i was making a C++ program I could call from within a batch file to print coloured text within Windows, any text printed without the newline argument passed to my program would complete and print the next bit of text instantly, but when the newline flag was passed it had a delay, I did some research and learnt about how it was the equivalent of a newline and a buffer flush, rather than just a newline.Sorry, I assumed you didn't actually know what endl was actually doing when you said it was just “a delay” so I was commenting on that. Looks like you do know what you're talking about thoughsnip“a delay” also std::endl causes a delay
you can remove a fair bit of whitespace from that…[(str(i) if (i%3 and i%5) else "")+("Fizz" if not i%3 else "")+("Buzz" if not i%5 else "") for i in range(1, 100)]
Transcript show.1to:100do:[:i|Transcript show:(i\\3=0ifTrue:['Fizz'])displayString;show:(i\\5=0ifTrue:['Buzz'])displayString;show:(((i\\3>0)and:[i\\5>0])ifTrue:[i])displayString;cr]
Transcript show. 1 to: 100 do: [:i | Transcript show: (i \\ 3 = 0 ifTrue: ['Fizz']) displayString; show: (i \\ 5 = 0 ifTrue: ['Buzz']) displayString; show: (((i \\ 3 > 0) and: [i \\ 5 > 0]) ifTrue: [i]) displayString; cr ]
1to:100do:[:i|Transcript show:(i\\3=0ifTrue:['Fizz'])displayString;show:(i\\5=0ifTrue:['Buzz'])displayString;show:(((i\\3>0)and:[i\\5>0])ifTrue:[i])displayString]
Transcript show.1to:100do:[:i|Transcript show:(i\\15=0ifTrue:['FizzBuzz']ifFalse:[i\\5=0ifTrue:['Buzz']ifFalse:[i\\3=0ifTrue:['Fizz']ifFalse:[i displayString]]]);cr]
It's C not C++ lolprintf is slow cout is better. C:#include <stdio.h> int main(boop) { int i; for(i = 1; i <= 100; ++i) { if (i % 3 == 0) printf("Fizz"); if (i % 5 == 0) printf("Buzz"); if ((i % 3 != 0) && (i % 5 != 0)) printf("%d", i); printf("\n"); } return 0; }#include <iostream>
using namespace std;
int main() {
for (int i=1;i<100;i++) {
if (i%3==0)
cout << "Fizz";
if (i%5==0)
cout << "Buzz";
if (i%3&&i%5)
cout << i;
cout << "\n";
}
return 0;
}
@echo off
goto start
:modulo
set /a return=%1
set /a divide=%2
:loop_2
if %return% gtr 0 (
set /a return=%return%-%divide%
goto loop_2
)
exit /b
:start
set /a i=1
set /a return=0
:loop_1
set "fb="
set setted=0
call :modulo %i% 3
if %return% equ 0 (
set fb=%fb%Fizz
set setted=1
)
call :modulo %i% 5
if %return% equ 0 (
set fb=%fb%Buzz
set setted=1
)
if %setted% neq 1 set fb=%i%
echo %fb%
set /a i=%i%+1
if %i% equ 101 goto eol_1
goto loop_1
:eol_1
exit /b
Just Windows Things™ I wanted to do it in Batch but I didn't realise Batch actually had a modulo operator… Oh well.
#!/bin/bash for i in {1..100}; do case "$((i % 3))$((i % 5))" in 00) echo FizzBuzz;; 0*) echo Fizz;; *0) echo Buzz;; *) echo $i esac done
You can make this shorter by replacing `using namespace std` with `using std::cout`.printf is slow cout is better. C:#include <stdio.h> int main(boop) { int i; for(i = 1; i <= 100; ++i) { if (i % 3 == 0) printf("Fizz"); if (i % 5 == 0) printf("Buzz"); if ((i % 3 != 0) && (i % 5 != 0)) printf("%d", i); printf("\n"); } return 0; }#include <iostream>
using namespace std;
int main() {
for (int i=1;i<100;i++) {
if (i%3==0)
cout << "Fizz";
if (i%5==0)
cout << "Buzz";
if (i%3&&i%5)
cout << i;
cout << "\n";
}
return 0;
}
you can also make this shorter by not using 8 HECKING SPACES to indentYou can make this shorter by replacing `using namespace std` with `using std::cout`.printf is slow cout is better. C:#include <stdio.h> int main(boop) { int i; for(i = 1; i <= 100; ++i) { if (i % 3 == 0) printf("Fizz"); if (i % 5 == 0) printf("Buzz"); if ((i % 3 != 0) && (i % 5 != 0)) printf("%d", i); printf("\n"); } return 0; }#include <iostream>
using namespace std;
int main() {
for (int i=1;i<100;i++) {
if (i%3==0)
cout << "Fizz";
if (i%5==0)
cout << "Buzz";
if (i%3&&i%5)
cout << i;
cout << "\n";
}
return 0;
}
Those are tab characters, not sets of 8 spaces.you can also make this shorter by not using 8 HECKING SPACES to indent snip