[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

rate my fizzbuzz /g/

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 78
Thread images: 5

File: devenv_2016-10-24_00-56-01.png (39KB, 1473x792px) Image search: [Google]
devenv_2016-10-24_00-56-01.png
39KB, 1473x792px
rate my fizzbuzz /g/
>>
>>57214548
It's shit.
>>
>>57214552
:(
>>
>>57214552
out of 10 tho?
>>
>>57214593
shit/10
>>
>>57214548
>stdafx
>including both iostream and cstdio
>using namespace std
>starting from zero and checking if the number is not zero
>main without return
>main without arguments
>char arrays not static
>using cout with \n (just use fprintf)
>>
>>57214548
>i != 101;
wew
>>
>>57214616
kek desu senpai
>>
>>57214548
>C in my C++
This is why c++ is shit
>>
>>57214548
>const char []
Why not use string? or even better, write it where you need it in your code.
You are using c++.

anyway, if you cleaned it up a bit, it would look like this
#include <iostream>
using std::cout;
int main(){
cout << 0 << '\n';
for(int i = 1; i <= 100; ++i){
cout << i << '\t';
if(i % 3 == 0){
cout << "FIZZ";
}
if(i % 5 == 0){
cout << "BUZZ";
}
cout << '\n';
}
return 0;
}
>>
>>57214548
3/10
>>
>>57215065
I'd give this a 8/10
>>
r8

#include <stdio.h>
int main(void) {
for (int i = 0; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
printf("%d FIZZBUZZ\n", i);
} else if (i % 3 == 0) {
printf("%d FIZZ\n", i);
} else if (i % 5 == 0) {
printf("%d BUZZ\n", i);
} else {
printf("%d\n", i);
}
}
return 0;
}
>>
>>57217627
wtf this is exactly what I wrote yesterday.
>>
say "Fizz"x$_%%3~"Buzz"x$_%%5||$_ for ^101

rate

>>57217627
You realize that you don't have to define a special case for 3 and 5

Correct way to do it is:
Print number (you do it anyways).
Print FIZZ if % three
Print BUZZ if % five

So it would look something like that if you want to keep the numbers (I don't think you should):
#include <stdio.h>
int main(void) {
for (int i = 0; i <= 100; i++) {
printf("%d ", i);
if (i % 3 == 0)
printf("FIZZ");
if (i % 5 == 0)
printf("BUZZ");
puts("");
}

return 0;
}
>>
greatest fizzbuzz coming through
if 0 % 15 == 0:
print(FIZZBUZZ)
elif 0 % 5 == 0:
print(BUZZ)
elif 0 % 3 == 0:
print(BUZZ)
else:
print(0)
if 1 % 15 == 0:
print(FIZZBUZZ)
elif 1 % 5 == 0:
print(BUZZ)
elif 1 % 3 == 0:
print(BUZZ)
else:
print(1)
if 2 % 15 == 0:
print(FIZZBUZZ)
elif 2 % 5 == 0:
print(BUZZ)
elif 2 % 3 == 0:
print(BUZZ)
else:
print(2)
if 3 % 15 == 0:
print(FIZZBUZZ)
elif 3 % 5 == 0:
print(BUZZ)
elif 3 % 3 == 0:
print(BUZZ)
else:
print(3)
if 4 % 15 == 0:
print(FIZZBUZZ)
elif 4 % 5 == 0:
print(BUZZ)
elif 4 % 3 == 0:
print(BUZZ)
else:
print(4)
if 5 % 15 == 0:
print(FIZZBUZZ)
elif 5 % 5 == 0:
print(BUZZ)
elif 5 % 3 == 0:
print(BUZZ)
else:
print(5)
if 6 % 15 == 0:
print(FIZZBUZZ)
elif 6 % 5 == 0:
print(BUZZ)
elif 6 % 3 == 0:
print(BUZZ)
else:
print(6)
if 7 % 15 == 0:
print(FIZZBUZZ)
elif 7 % 5 == 0:
print(BUZZ)
elif 7 % 3 == 0:
print(BUZZ)
else:
print(7)
if 8 % 15 == 0:
print(FIZZBUZZ)
elif 8 % 5 == 0:
print(BUZZ)
elif 8 % 3 == 0:
print(BUZZ)
else:
print(8)
if 9 % 15 == 0:
print(FIZZBUZZ)
elif 9 % 5 == 0:
print(BUZZ)
elif 9 % 3 == 0:
print(BUZZ)
else:
print(9)
if 10 % 15 == 0:
print(FIZZBUZZ)
elif 10 % 5 == 0:
print(BUZZ)
elif 10 % 3 == 0:
print(BUZZ)
else:
print(10)
>>
>>57218164
if 11 % 15 == 0:
print(FIZZBUZZ)
elif 11 % 5 == 0:
print(BUZZ)
elif 11 % 3 == 0:
print(BUZZ)
else:
print(11)
if 12 % 15 == 0:
print(FIZZBUZZ)
elif 12 % 5 == 0:
print(BUZZ)
elif 12 % 3 == 0:
print(BUZZ)
else:
print(12)
if 13 % 15 == 0:
print(FIZZBUZZ)
elif 13 % 5 == 0:
print(BUZZ)
elif 13 % 3 == 0:
print(BUZZ)
else:
print(13)
if 14 % 15 == 0:
print(FIZZBUZZ)
elif 14 % 5 == 0:
print(BUZZ)
elif 14 % 3 == 0:
print(BUZZ)
else:
print(14)
if 15 % 15 == 0:
print(FIZZBUZZ)
elif 15 % 5 == 0:
print(BUZZ)
elif 15 % 3 == 0:
print(BUZZ)
else:
print(15)
if 16 % 15 == 0:
print(FIZZBUZZ)
elif 16 % 5 == 0:
print(BUZZ)
elif 16 % 3 == 0:
print(BUZZ)
else:
print(16)
if 17 % 15 == 0:
print(FIZZBUZZ)
elif 17 % 5 == 0:
print(BUZZ)
elif 17 % 3 == 0:
print(BUZZ)
else:
print(17)
if 18 % 15 == 0:
print(FIZZBUZZ)
elif 18 % 5 == 0:
print(BUZZ)
elif 18 % 3 == 0:
print(BUZZ)
else:
print(18)
if 19 % 15 == 0:
print(FIZZBUZZ)
elif 19 % 5 == 0:
print(BUZZ)
elif 19 % 3 == 0:
print(BUZZ)
else:
print(19)
if 20 % 15 == 0:
print(FIZZBUZZ)
elif 20 % 5 == 0:
print(BUZZ)
elif 20 % 3 == 0:
print(BUZZ)
else:
print(20)
>>
>>57218164
oops i fugged up

if 1 % 15 == 0:
print('FIZZBUZZ')
elif 1 % 5 == 0:
print('BUZZ')
elif 1 % 3 == 0:
print('FIZZ')
else:
print(1)
if 2 % 15 == 0:
print('FIZZBUZZ')
elif 2 % 5 == 0:
print('BUZZ')
elif 2 % 3 == 0:
print('FIZZ')
else:
print(2)
if 3 % 15 == 0:
print('FIZZBUZZ')
elif 3 % 5 == 0:
print('BUZZ')
elif 3 % 3 == 0:
print('FIZZ')
else:
print(3)
if 4 % 15 == 0:
print('FIZZBUZZ')
elif 4 % 5 == 0:
print('BUZZ')
elif 4 % 3 == 0:
print('FIZZ')
else:
print(4)
if 5 % 15 == 0:
print('FIZZBUZZ')
elif 5 % 5 == 0:
print('BUZZ')
elif 5 % 3 == 0:
print('FIZZ')
else:
print(5)
if 6 % 15 == 0:
print('FIZZBUZZ')
elif 6 % 5 == 0:
print('BUZZ')
elif 6 % 3 == 0:
print('FIZZ')
else:
print(6)
if 7 % 15 == 0:
print('FIZZBUZZ')
elif 7 % 5 == 0:
print('BUZZ')
elif 7 % 3 == 0:
print('FIZZ')
else:
print(7)
if 8 % 15 == 0:
print('FIZZBUZZ')
elif 8 % 5 == 0:
print('BUZZ')
elif 8 % 3 == 0:
print('FIZZ')
else:
print(8)
if 9 % 15 == 0:
print('FIZZBUZZ')
elif 9 % 5 == 0:
print('BUZZ')
elif 9 % 3 == 0:
print('FIZZ')
else:
print(9)
if 10 % 15 == 0:
print('FIZZBUZZ')
elif 10 % 5 == 0:
print('BUZZ')
elif 10 % 3 == 0:
print('FIZZ')
else:
print(10)
>>
>>57218220

if 11 % 15 == 0:
print('FIZZBUZZ')
elif 11 % 5 == 0:
print('BUZZ')
elif 11 % 3 == 0:
print('FIZZ')
else:
print(11)
if 12 % 15 == 0:
print('FIZZBUZZ')
elif 12 % 5 == 0:
print('BUZZ')
elif 12 % 3 == 0:
print('FIZZ')
else:
print(12)
if 13 % 15 == 0:
print('FIZZBUZZ')
elif 13 % 5 == 0:
print('BUZZ')
elif 13 % 3 == 0:
print('FIZZ')
else:
print(13)
if 14 % 15 == 0:
print('FIZZBUZZ')
elif 14 % 5 == 0:
print('BUZZ')
elif 14 % 3 == 0:
print('FIZZ')
else:
print(14)
if 15 % 15 == 0:
print('FIZZBUZZ')
elif 15 % 5 == 0:
print('BUZZ')
elif 15 % 3 == 0:
print('FIZZ')
else:
print(15)
if 16 % 15 == 0:
print('FIZZBUZZ')
elif 16 % 5 == 0:
print('BUZZ')
elif 16 % 3 == 0:
print('FIZZ')
else:
print(16)
if 17 % 15 == 0:
print('FIZZBUZZ')
elif 17 % 5 == 0:
print('BUZZ')
elif 17 % 3 == 0:
print('FIZZ')
else:
print(17)
if 18 % 15 == 0:
print('FIZZBUZZ')
elif 18 % 5 == 0:
print('BUZZ')
elif 18 % 3 == 0:
print('FIZZ')
else:
print(18)
if 19 % 15 == 0:
print('FIZZBUZZ')
elif 19 % 5 == 0:
print('BUZZ')
elif 19 % 3 == 0:
print('FIZZ')
else:
print(19)
if 20 % 15 == 0:
print('FIZZBUZZ')
elif 20 % 5 == 0:
print('BUZZ')
elif 20 % 3 == 0:
print('FIZZ')
else:
print(20)
>>
>>57218230

if 21 % 15 == 0:
print('FIZZBUZZ')
elif 21 % 5 == 0:
print('BUZZ')
elif 21 % 3 == 0:
print('FIZZ')
else:
print(21)
if 22 % 15 == 0:
print('FIZZBUZZ')
elif 22 % 5 == 0:
print('BUZZ')
elif 22 % 3 == 0:
print('FIZZ')
else:
print(22)
if 23 % 15 == 0:
print('FIZZBUZZ')
elif 23 % 5 == 0:
print('BUZZ')
elif 23 % 3 == 0:
print('FIZZ')
else:
print(23)
if 24 % 15 == 0:
print('FIZZBUZZ')
elif 24 % 5 == 0:
print('BUZZ')
elif 24 % 3 == 0:
print('FIZZ')
else:
print(24)
if 25 % 15 == 0:
print('FIZZBUZZ')
elif 25 % 5 == 0:
print('BUZZ')
elif 25 % 3 == 0:
print('FIZZ')
else:
print(25)
if 26 % 15 == 0:
print('FIZZBUZZ')
elif 26 % 5 == 0:
print('BUZZ')
elif 26 % 3 == 0:
print('FIZZ')
else:
print(26)
if 27 % 15 == 0:
print('FIZZBUZZ')
elif 27 % 5 == 0:
print('BUZZ')
elif 27 % 3 == 0:
print('FIZZ')
else:
print(27)
if 28 % 15 == 0:
print('FIZZBUZZ')
elif 28 % 5 == 0:
print('BUZZ')
elif 28 % 3 == 0:
print('FIZZ')
else:
print(28)
if 29 % 15 == 0:
print('FIZZBUZZ')
elif 29 % 5 == 0:
print('BUZZ')
elif 29 % 3 == 0:
print('FIZZ')
else:
print(29)
if 30 % 15 == 0:
print('FIZZBUZZ')
elif 30 % 5 == 0:
print('BUZZ')
elif 30 % 3 == 0:
print('FIZZ')
else:
print(30)
>>
File: fizzbuzz.png (16KB, 771x446px) Image search: [Google]
fizzbuzz.png
16KB, 771x446px
Not bad, rate mine.
>>
/r/ing an HTML fizzbuzz

It's for class
thnx
>>
>>57218238

if 31 % 15 == 0:
print('FIZZBUZZ')
elif 31 % 5 == 0:
print('BUZZ')
elif 31 % 3 == 0:
print('FIZZ')
else:
print(31)
if 32 % 15 == 0:
print('FIZZBUZZ')
elif 32 % 5 == 0:
print('BUZZ')
elif 32 % 3 == 0:
print('FIZZ')
else:
print(32)
if 33 % 15 == 0:
print('FIZZBUZZ')
elif 33 % 5 == 0:
print('BUZZ')
elif 33 % 3 == 0:
print('FIZZ')
else:
print(33)
if 34 % 15 == 0:
print('FIZZBUZZ')
elif 34 % 5 == 0:
print('BUZZ')
elif 34 % 3 == 0:
print('FIZZ')
else:
print(34)
if 35 % 15 == 0:
print('FIZZBUZZ')
elif 35 % 5 == 0:
print('BUZZ')
elif 35 % 3 == 0:
print('FIZZ')
else:
print(35)
if 36 % 15 == 0:
print('FIZZBUZZ')
elif 36 % 5 == 0:
print('BUZZ')
elif 36 % 3 == 0:
print('FIZZ')
else:
print(36)
if 37 % 15 == 0:
print('FIZZBUZZ')
elif 37 % 5 == 0:
print('BUZZ')
elif 37 % 3 == 0:
print('FIZZ')
else:
print(37)
if 38 % 15 == 0:
print('FIZZBUZZ')
elif 38 % 5 == 0:
print('BUZZ')
elif 38 % 3 == 0:
print('FIZZ')
else:
print(38)
if 39 % 15 == 0:
print('FIZZBUZZ')
elif 39 % 5 == 0:
print('BUZZ')
elif 39 % 3 == 0:
print('FIZZ')
else:
print(39)
if 40 % 15 == 0:
print('FIZZBUZZ')
elif 40 % 5 == 0:
print('BUZZ')
elif 40 % 3 == 0:
print('FIZZ')
else:
print(40)
>>
>>57218246


if 41 % 15 == 0:
print('FIZZBUZZ')
elif 41 % 5 == 0:
print('BUZZ')
elif 41 % 3 == 0:
print('FIZZ')
else:
print(41)
if 42 % 15 == 0:
print('FIZZBUZZ')
elif 42 % 5 == 0:
print('BUZZ')
elif 42 % 3 == 0:
print('FIZZ')
else:
print(42)
if 43 % 15 == 0:
print('FIZZBUZZ')
elif 43 % 5 == 0:
print('BUZZ')
elif 43 % 3 == 0:
print('FIZZ')
else:
print(43)
if 44 % 15 == 0:
print('FIZZBUZZ')
elif 44 % 5 == 0:
print('BUZZ')
elif 44 % 3 == 0:
print('FIZZ')
else:
print(44)
if 45 % 15 == 0:
print('FIZZBUZZ')
elif 45 % 5 == 0:
print('BUZZ')
elif 45 % 3 == 0:
print('FIZZ')
else:
print(45)
if 46 % 15 == 0:
print('FIZZBUZZ')
elif 46 % 5 == 0:
print('BUZZ')
elif 46 % 3 == 0:
print('FIZZ')
else:
print(46)
if 47 % 15 == 0:
print('FIZZBUZZ')
elif 47 % 5 == 0:
print('BUZZ')
elif 47 % 3 == 0:
print('FIZZ')
else:
print(47)
if 48 % 15 == 0:
print('FIZZBUZZ')
elif 48 % 5 == 0:
print('BUZZ')
elif 48 % 3 == 0:
print('FIZZ')
else:
print(48)
if 49 % 15 == 0:
print('FIZZBUZZ')
elif 49 % 5 == 0:
print('BUZZ')
elif 49 % 3 == 0:
print('FIZZ')
else:
print(49)
if 50 % 15 == 0:
print('FIZZBUZZ')
elif 50 % 5 == 0:
print('BUZZ')
elif 50 % 3 == 0:
print('FIZZ')
else:
print(50)
>>
>>57218260
stahp
>>
>>57215065
>no flushing
You lose.
>>
In all seriousness, this is the perfect FizzBuzz. Never sacrifice readability for cleverness.

 
for(int i=1; i!=101; ++i)
{
std::string str;
if(i%3==0) str+="Fizz";
if(i%5==0) str+="Buzz";
str.empty() ? std::cout<< i <<"\n" : std::cout<< str <<"\n";
}
>>
print('1')
print('2')
print('3 Fizz')
print('4')
print('5 Buzz')
print('6 Fizz')
print('7')
print('8')
print('9 Fizz')
print('10 Buzz')
print('11')
print('12 Fizz')
print('13')
print('14')
print('15 Fizz Buzz')
print('16')
print('17')
print('18 Fizz')
print('19')
print('20 Buzz')
print('21 Fizz')
print('22')
print('23')
print('24 Fizz')
print('25 Buzz')
print('26')
print('27 Fizz')
print('28')
print('29')
print('30 Fizz Buzz')
print('31')
print('32')
print('33 Fizz')
print('34')
print('35 Buzz')
print('36 Fizz')
print('37')
print('38')
print('39 Fizz')
print('40 Buzz')
print('41')
print('42 Fizz')
print('43')
print('44')
print('45 Fizz Buzz')
print('46')
print('47')
print('48 Fizz')
print('49')
print('50 Buzz')
>>
>>57218332
>allocating everytime
>when it's a constant time problem
>making code that probably cannot even be optimized
I'm all for readability, but don't sacrifice good design for it.

Anyhow, the best c++ fizz buzz is constexpr.
>>
r8h8
++++++++++[>++++++++++<-]>>++++++++++>->>>>>>>>>>>>>>>>-->+++++++[->++
++++++++<]>[->+>+>+>+<<<<]+++>>+++>>>++++++++[-<++++<++++<++++>>>]++++
+[-<++++<++++>>]>>-->++++++[->+++++++++++<]>[->+>+>+>+<<<<]+++++>>+>++
++++>++++++>++++++++[-<++++<++++<++++>>>]++++++[-<+++<+++<+++>>>]>>-->
---+[-<+]-<[+[->+]-<<->>>+>[-]++[-->++]-->+++[---++[--<++]---->>-<+>[+
+++[----<++++]--[>]++[-->++]--<]>++[--+[-<+]->>[-]+++++[---->++++]-->[
->+<]>>[.>]++[-->++]]-->+++]---+[-<+]->>-[+>>>+[-<+]->>>++++++++++<<[-
>+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>
+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->+++
+++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]+[-<+]->>]+[-]<<<.>>>+[
-<+]-<<]
>>
#include <stdio.h>
#include <ncurses.h>

int main(void) {
int i = 0;
char c;
initscr();
noecho();
scrollok(stdscr, TRUE);
while (1) {
first:
printw("Is %d divisible by 3? (y/n)\n", i);
refresh();
c = getch();
switch (c) {
case 'y' :
printw("Fizz\n");
refresh();
i++;
goto first;
case 'n' :
goto second;
}
printw("invalid input\n");
refresh();
}

while (1) {
second:
printw("Is %d divisible by 5? (y/n)\n", i);
refresh();
c = getch();
switch (c) {
case 'y':
printw("Buzz\n");
refresh();
i++;
goto first;
case 'n':
i++;
goto first;
}
printw("invalid input\n");
refresh();
}
endwin();
return 0;
}


don't forget to add the -lncurses flag to the compiler
>>
>>57219019
If it is divisible by 3 you do not check for 5.
and since you use ncurses, why not have the questions static on the button of the screen?
>>
>>57219132
whoops, change the first goto to go to second instead of first
>>
>>57219163
wait

fuck it
>>
>>57219163
>>57219172
yea... This is why it is bad code.
>>
File: Untitled.jpg (41KB, 677x462px) Image search: [Google]
Untitled.jpg
41KB, 677x462px
with Ada.Text_IO; use Ada.Text_IO;

procedure fizzbuzz is
begin
for I in 1..100 loop
if ((I mod 3 = 0) and (I mod 5 = 0)) then
Put_Line(Integer'Image(I) & " FizzBuzz");
elsif (I mod 3 = 0) then
Put_Line(Integer'Image(I) & " Fizz");
elsif (I mod 5 = 0) then
Put_Line(Integer'Image(I) & " Buzz");
else
Put_Line(Integer'Image(I));
end if;
end loop;
end fizzbuzz;
>>
>>57219195
Not enough dynamic predicates. 2005/12
>>
>>57219387
explain
im still stuck in 95
>>
>>57214548
>Have C variables, not using C to display data
>Do a while
>Start from 1,delete all i != 0 nonsense
>Remove else if and delete first if statement.

Thank me later.
>>
Why doent anyone write a fizzbuzz language?

It could optimize heavily and impress the interviewer
>>
>>57219425
You can do
type Fizz is Integer with Dynamic_Predicate => Fizz mod 3 = 0;

Then your if statement can look like
if I in Fizz then
Put_Line("Fizz");
end if;

It just makes it cleaner.
>>
>>57219488
touché
that is extremely neat, thanks
>>
>>57215065
Doesn't produce required output. Eg line four should be
Fizz
Not
3Fizz
>>
>>57219455
Because fizzbuzz isn't meant to impress. It's a quick way of filtering out incompetents / time-wasters.

#include <stdio.h>
#include <string.h>

int main() {
int i;
char output[9];

for (i = 1; i < 101; i++) {
memset(&output, '\0', sizeof(output));

if ((i % 3) == 0) {
strcat(output, "fizz");
}
if ((i % 5) == 0) {
strcat(output, "buzz");
}

if (output[0] == '\0') {
printf("%d\n", i);
}
else {
printf("%s\n", output);
}
}
getchar();
return 0;
}
>>
>>57219557
It is "3\tFIZZ", same as in OP
>>
>>57219488
>>57219505
Typo, it should be a subtype, not a type for this example.
>>
for i in (1..100)
div_3 = (i % 3 == 0)
div_5 = (i % 5 == 0)
div_3_and_5 = div_3 && div_5

if div_3_and_5
puts "FizzBuzz"
elsif div_3
puts "Fizz"
elsif div_5
puts "Buzz"
else
puts i
end
end
>>
>>57214548
>for (i = 0; i != 101; ++i){
>i != 101
what the fuck
just use a < operand
>>
>>57218240

My fucking sides. This is amazing.
>>
>>57218428
how would you handle the 51-100 case?
>>
>>57218587
it's not constant time. the range could be anything
>>
>>57219664
with Ada.Text_IO; use Ada.Text_IO;

procedure lefizz is
subtype Fizz is Integer with Dynamic_Predicate => Fizz mod 3 = 0;
subtype Buzz is Integer with Dynamic_Predicate => Buzz mod 5 = 0;
begin
for I in 1..100 loop
Put(Integer'Image(I));
if I in Fizz then
Put("Fizz");
end if;
if I in Buzz then
Put("Buzz");
end if;
New_Line;
end loop;
end lefizz;

fantastic
>>
r8

#include <stdio.h>
#include <stdlib.h>

#define FIZZBUZZ_CASE(term) case term: printf("FizzBuzz"); break
#define FIZZ_CASE(term) case term: printf("Fizz"); break
#define BUZZ_CASE(term) case term: printf("Buzz"); break
#define EMPTY_CASE(term) case term:
#define NORMAL_CASE(term) case term: printf("%d", i); break

int main(void)
{
int i;
for (i = 1; i <= 100; i++)
{
int j = i;
while (j - 15 >= 0) j = j - 15;

switch (j)
{
FIZZBUZZ_CASE(0);
EMPTY_CASE(1);
NORMAL_CASE(2);
FIZZ_CASE(3);
NORMAL_CASE(4);
BUZZ_CASE(5);
FIZZ_CASE(6);
EMPTY_CASE(7);
NORMAL_CASE(8);
FIZZ_CASE(9);
BUZZ_CASE(10);
NORMAL_CASE(11);
FIZZ_CASE(12);
EMPTY_CASE(13);
NORMAL_CASE(14);
}
printf("\n");
}

return 0;
}
>>

int main(){
int i;
for(i=1; i<=100; i++){
if ( !(i%3) || !(i%5) ){
if ( !(i%3) ) printf("Fizz");
if ( !(i%5) ) printf("Buzz");
printf("\n");
} else printf("%d\n", i);
}
return 0;
}
>>
for i in range(1,101):
print("{} {}{}".format(i, "FIZZ" if i%3==0 else "", "BUZZ" if i%5==0 else ""))
>>
I just don't know anymore.
#include <stdio.h>
int main(void) {
int i;
char x;
for(i=1;i<=100;i++) {
x = i%15==0 ? printf("fizzbuzz\n") : (i%5==0 ? printf("buzz\n") : (i%3==0 ? printf("fizz\n") : printf("%d",i)));
}
return(0);
}
>>
>>57220128

with Ada.Text_IO;

procedure Fizz is
package Integer_IO is new Ada.Text_IO.Integer_IO(Integer);
use Integer_IO;
use Ada.Text_IO;

task Print is
entry Put_String(Item : in String);
entry Put_Num(Item : in Integer);
end;
task body Print is
begin
loop
select
accept Put_String(Item : in String) do
Put_Line(Item=>Item);
end Put_String;
or
accept Put_Num(Item : in Integer) do
Put(Item=>Item, Width=>0);
New_Line(1);
end Put_Num;
or
terminate;
end select;
end loop;
end Print;

Fizz : constant String := "Fizz";
Buzz : constant String := "Buzz";
Fizzbuzz : constant String := "Fizzbuzz";

subtype Fizz_Type is Integer
with Dynamic_Predicate => Fizz_Type rem 3 = 0;
subtype Buzz_Type is Integer
with Dynamic_Predicate => Buzz_Type rem 5 = 0;
subtype Fizzbuzz_Type is Integer
with Dynamic_Predicate => Fizzbuzz_Type rem 15 = 0;
subtype Fizzbuzz_Range is Integer range 1..100;

begin -- Fizz
for I in Fizzbuzz_Range loop
if I in Fizzbuzz_Type then
Print.Put_String(Item=>Fizzbuzz);
elsif I in Fizz_Type then
Print.Put_String(Item=>Fizz);
elsif I in Buzz_Type then
Print.Put_String(Item=>Buzz);
else
Print.Put_Num(Item=>I);
end if;
end loop;

end Fizz;
>>
>>57220490
Why do you need to check for Fizzbuzz? Check for FIZZ, print. Check for BUZZ, print.
>>
>>57220721
I dunno, I'm a fucking programming noob who tried to learn C years ago.

I only came to /g/ for the pen/watch/coffee threads.
>>
for i in range(1, 101): print((not i % 3 and not i % 5) and 'fizzbuzz' or not i % 3 and 'fizz' or not i % 5 and 'buzz' or i)

r8
>>
>>57220747
at least you're honest. Instagram might be more your thing, though
>>
>>57220747
in C you have the ability to do
if(!(fizz%3))

instead of checking equal to 0
>>
>>57221025
Ah that's interesting.
Thanks for the heads up, it's been way too long but I should really try to pick it up again.
>>
You could have saved like 30sh instructions if you used in line assembly instead of c or saved run time if you had the complier compute the program before hand other then that it's just baby's first fizz buzz
>>
>>57220747
I just said that so you can rethink your code with spelling it out for you! Never too late to learn.
>>
>>57221330
Sorry anon, you are right.
After your comment and that other anon I have been playing around with the code a bit, trying different things.

It's really interesting how you can approach a single problem in so many ways.
>>
>>57220665
Over-engineered / 10
>>
>>57221430
use Ada to avoid that problem
very few ways of doing it correctly, all three of which are already posted here
>>
File: fizzbuzz.jpg (112KB, 1232x387px) Image search: [Google]
fizzbuzz.jpg
112KB, 1232x387px
Trying something different than op. Pls don't kill me desu senpai
Only learned doing some easy calculations in c++ like 7/8 years ago and only started messing with it yesterday.
>>
>>57220301
>>57221752
You hardcode an array of length 16 and iterate through it? wut.
If the rules change to "FIZZ is now all multiples of 4", you need to change the whole array... If you calculate every time like on the other solution above, you only need to change 3 to 4.
>>
>>57214548
#include <stdio.h>

void fizzbuzz(int);

int main(void)
{
fizzbuzz(50);
return 0;
}

void fizzbuzz(int i)
{
int fizz = i % 3;
int buzz = i % 5;
if(i==0)
printf("%d\n", i);
else if (fizz+buzz==0) {
printf("FizzBuzz\n");
fizzbuzz(i-1);
} else if (fizz == 0) {
printf("Fizz\n");
fizzbuzz(i-1);
} else if (buzz == 0) {
printf("Buzz\n");
fizzbuzz(i-1);
} else {
printf("%d\n", i);
fizzbuzz(i-1);
}
}
>>
>>57222155
>if you change what the programm is supposed to do, you have to change things
fo real lad
As I said, I was simply trying a different, not a better, approach than OP. Since I'm a fucking uber boon, I want to try and do stuff myself, not just replicate solutions I just saw. So Ofc hardcoding an array is about as useful as just printfing the thing all together and ofc calculating it is the way to go and I would have done just that if I hadn't seen everyone here doing it.
>>
>>57222398
It's k, but you should stick to your first attempt (considering you're op). It's more flexible/dynamic. That last one is FizzBuzzEnterprise level.
>>
>>57222463
Not Op, just some fag with bare minimum kinda-autodidactic c++ knowledge. Just saw Ops solution and tried producing the same result with a different approach.
Wasn't posting it to show muh skills, was more of a 'ok, this is my shitty alternative way of doing this, but is this shitty way atleast kinda correct?'
>>
>>57222463
Which one is the enterprise version?
>>
main :: IO ()
main = mapM_ (putStrLn . fizzbuzz) [1..100]

fizzbuzz :: Int -> String
fizzbuzz n
| n `rem` 15 == 0 = "FizzBuzz"
| n `rem` 5 == 0 = "Buzz"
| n `rem` 3 == 0 = "Fizz"
| otherwise = show n
>>
#!/bin/bash

for i in {1..100}
do
(( $i % 3 )) || printf "Fizz"
(( $i % 5 )) || printf "Buzz"
(( $i % 5 && $i % 3 )) && printf "$i"
printf "\n"
done
Thread posts: 78
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.