ITT: We critique each others fizzbuzzes

public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
System.out.println("FizzBuzz");
}
if (i % 3 == 0) {
System.out.println("Fizz");
}
if (i % 5 == 0) {
System.out.println("Buzz");
}
else {
System.out.println(i);
}
}
}
}

Attached: terry.gif (429x592, 2.4M)

Other urls found in this thread:

github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition
raw.githubusercontent.com/Keith-S-Thompson/fizzbuzz-polyglot/master/expected-output.txt
themonadreader.files.wordpress.com/2014/04/fizzbuzz.pdf
pastebin.com/VxwNdRqL
twitter.com/NSFWRedditVideo

public static void main(const String.. args) {


noob

Not modular enough. I want the system to support any string at any index without rewrites.

public static void main(const String.. args => {
return new Promise(success: () => { return args; });
});

Elaborate?

github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

Hi OP, guess what?
Today you get to learn that you can write
if (i % 3 == 0 && i % 5 == 0) {
System.out.println("FizzBuzz");
}

as
if (i % 15 == 0) {
System.out.println("FizzBuzz");
}

What about i=10?

You know I figured I could do that but I wasn't 100% sure. Thanks

Brainlet

What about it?

class FizzBuzz{
constructor(fizz, end, start){
this.start = start || 0
this.end = end || 100
this.fizz = fizz
this.i = 0
}
static Fizz(n, obj){
let item = ''
for(let p in obj)
if(!(n % p))
item += obj[p]
return item || n
}
* generator(){
while(this.i++ < this.end)
yield this.constructor.Fizz(this.i, this.fizz)
}
}
var FB = new FizzBuzz({3: 'Fizz', 5: 'Buzz'}, 100)
var FBGen = FB.generator()
for(i of FBGen)
console.log(i)

This won't even work correctly. It will print out too much on i % 15

>You know I figured I could do that but I wasn't 100% sure.
gcc fizzbuzz.c && ./a.out
What's so hard about that?

I know right? My formatting is all fucked up.

>t. brainlet

for(int i = 0; i < 100; i++) {
boolean flip = true;
if( i % 3 == 0) {
System.out.print("Fizz");
flip = false;
}
if( i % 5 == 0) {
System.out.print("Buzz");
flip = false;
}
if(flip) {
System.out.print(i);
}
System.out.print("\n");
}

1
2
Fizz
3
4
Buzz
Fizz
6
7
8
Fizz
9
Buzz
11
Fizz
12
13
14
FizzBuzz
Fizz
Buzz

Compilers is smart enough to reuse already computed values, but in your case you computing additional modulo, which is relatively expensive.

You did something wrong then.
My code works fine.
#include

int main(){

for(int i = 1; i

p{counter-increment: item}p:not(:nth-of-type(5n)):before{content: counter(item)}p:nth-of-type(3n):before{content: "Fizz"}p:nth-of-type(5n):after{content: "Buzz"}

And here is my output
1
2
buzz
4
fizz
buzz
7
8
buzz
fizz
11
buzz
13
14
fizzbuzz
16
17
buzz
19
...

Your code is not the same as OP's code. you have an else if's and OP's does not. Thus it prints out too much.

I was going to ask you why you did it this way, but I now realise it probably makes the most sense.

Nice.

Declaring and initializing a var inside a for loop, YOU MAD MAN

Because I was never responding to you. I replied to OP. l2read

Nice

Should be able to run with arguments
"fizz", "buzz", 3, 5

Should be able to run with arguments
"bob", "john", "astrid", 3, 5, 7

Should be able to run with arguments
"frog", 3, "bog", "hog", 5, 7

Ah, I misunderstood, while I saw you were replying to OP, I thought you were referring to the i%15 not working in a general sense.
Please be a little clearer in your communication next time.

Attached: 1519236051519.jpg (720x960, 52K)

Here is my latest fizzbuzz shitpost, thanks again
to the user for the help with the ternary operators.
#include
// Usage: >fizzbuzz2 val
int main(int argc, char* argv[]){
int i=1;
int val;
val=atoi(argv[1]);
while(i

if I was replying to you I would have used your post number, fuck off

NO. U.

Attached: 1519236051519d.jpg (644x750, 82K)

>ternary operator

Attached: FC50F726-A288-44E4-A0C6-FEB47B070C8B.jpg (299x169, 12K)

That doesn't even work idiot. Whenever i is divisible by 15 it prints fizzbuzz twice and whenever it is divisible only by 3 it prints fizz and i.

Attached: brainlet.jpg (645x729, 48K)

get rid of the first if statement or change them to if else

here's my stab at forth looking for feedback


: fizzbuzz ( n -- )
1 + 1 do cr i dup 15 mod 0= if ." fizzbuzz" drop else
dup 5 mod 0= if ." buzz" drop else
dup 3 mod 0= if ." fizz" drop else
.
then then then loop ;

Attached: NEIN.png (133x157, 47K)

> if (i % 3 == 0 && i % 5 == 0)
not
>if(i % 15 == 0)

Attached: 1.png (192x150, 33K)

>no return statement

Attached: https_%2F%2Fblueprint-api-production.s3.amazonaws.com%2Fuploads%2Fcard%2Fimage%2F460114%2Fca97e763-1 (950x534, 94K)

int main() {
for(int i=0; i

fuck I forgot a bracket after the for loop initializer. oh well

Still runs on my machine.
My guess is the compiler is smart enough to
default to return 0 if none is present.

Haters gonna hate.

print('\n'.join([('fizz' * (i%3==0) + 'buzz' * (i%5==0)) or str(i) for i in range(100)]))


But seriously, find me a solution that would get more points in an interview.

wget raw.githubusercontent.com/Keith-S-Thompson/fizzbuzz-polyglot/master/expected-output.txt
cat "expected output.txt"

for i in range(1, 101):
if i % 3 == 0 and i % 5 == 0:
print "FizzBuzz"
elif i % 3 == 0:
print "Fizz"
elif i % 5 == 0:
print "Buzz"
else:
print i

Attached: 1509023297696.png (592x412, 178K)

themonadreader.files.wordpress.com/2014/04/fizzbuzz.pdf

jesus christ, is this java?

no, mayb C#

>5:11: error: '::main' must return 'int'
you can't run a void main()

this is one of my favorite reads, seriously everyone should read that

lol nice

doesnt compile 0/10 would not hire

def fizzbuzz(end):
for n in range(end):
if (n+1)%15 == 0: print('fizzbuzz')
elif (n+1)%5 == 0: print('buzz')
elif (n+1)%3 == 0: print('fizz')
else: print(n+1)

#include
int main() {
using std::cout;
constexpr size_t num_factors = 2;
constexpr int factors[num_factors] = {3, 5};
constexpr size_t max_str_length = 5;
constexpr char factor_str[num_factors][max_str_length] = {"fizz","buzz"};
auto check_for_no_factor = [&factors](int i) constexpr { for (auto num : factors) if (i%num == 0) return false; return true; };
auto print_factor = [&factors, &factor_str, num_factors](int j) {for (size_t i = 0; i

It's not C#

new challenge: implement strstr in C without any libraries or stdlib.

what is it ?

can you teach me c++?

#include
#include
#include

int main(int argc, char *argv[]){
if (argc == 1) {
printf("Usage: fizzbuzz number\n");
exit(1);
}
int input = atoi(argv[1]);
int i;
for (i = 1; i

>not using void main to save 1 loc

Looks like javascript. Kooky.

I cleaned up a bit, but I believe both solutions satisfy the article's requirements.

print('\n'.join(['fizz' * (not i%3) + 'buzz' * (not i%5) or str(i) for i in range(100)]))

Javascript. Fucking awful language

I wasn't aware javascript had an "of" operator..?

for (var i=1; i

>Fucking awful language
This meme needs to die.

it's really messy user

Attached: Screenshot_20180120_150037.png (296x349, 103K)

>not using [++i]

That was fun. Here's what I came up with, it seems to cover all the cases I tried:
#define NULL 0

static const char *strstr(const char *haystack, const char *needle)
{
int forward = -1;
for(; *haystack != '\0'; haystack++) {
if(*(needle + (++forward)) == '\0') {
if(forward > 0)
return haystack - forward;
else
forward = 0;
}
if(*(needle + forward) != *haystack)
forward = -1;
}
if(forward > 0 && *haystack == '\0')
return haystack - (forward + 1);
return NULL;
}

>#define NULL 0
That's fucking blasphemy, for several reasons.

Well the challenge was to not use any libraries

r8
#!/bin/ruby

(1..100).each do |i|
x = ''
x = "Fizz" if i % 3 == 0
x += "Buzz" if i % 5 == 0
puts x.empty? ? i : x
end

There are actually two distinct sets of headers defined by the C standard.
There are the ones defined for free-standing implementations, and the ones defined for hosted implementations.
So even without the standard library, you still have access to , , , , , , , , and . They all contain typedefs or macros that help with porability, but do not contain any functions in them.
contains NULL, so you can use that.

The other reason it's blasphemous is that you've defined NULL in the pleb non-POSIX-compatible way.
It should be (void*)0.

I see. Anyways I failed the challenge because an empty string is supposed to return the full string rather than returning null. But it's 3am so I can't be bothered to rewrite it outside of a lazy if statement.

FizzBuzz from 1-100

1

2

Fizz

4

Buzz

Fizz

7

8

Fizz

Buzz

11

Fizz

13

14

FizzBuzz

16

17

Fizz

19

Buzz

Fizz

22

23

Fizz

Buzz

26

Fizz

28

29

FizzBuzz

31

32

Fizz

34

Buzz

Fizz

37

38

Fizz

Buzz

41

Fizz

43

44

FizzBuzz

46

47

Fizz

49

Buzz

extern crate fizzbuzz;

fn main() {
fizzbuzz::fizzbuzz();
}

not that user, but i made this, output with modularFizzBuzz('Fizz', 3, 'Buzz', 5):
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22

Attached: fucking js.png (927x918, 99K)

var a = 'fizz'
var b = 'buzz'

function fizzBuzzFunc() {
for (var i = 0); i < 100; i++)
if (i % 3 = 0) {
console.log(a);
} else if (i % 5 = 0){
console.log(b);
} else {
console.log(i);
}
}

Phoneposting is hard, does it work?

for i in range(1,100):
print ('fizz'*(not i%3) + 'buzz'*(not i%5)) or i

Nvm I misunderstood what the fuck I'm meant to be doing

void main() is not valid c++

Reminder that fizz buzz is supposed to be not only efficient, but easily modifiable, and clearly readable. I feel this solution I made today strikes a decent balance of everything fizzbuzz tries to achieve. Certainly the most elegant solution I have so far. Feedback appreciated. Also thanks to the user from the last thread that inspired this. I decided to use a single counter for clarity in mine though, to increment through the loop. If someone has a good way to improve this further, feel free to one up me and let me know.

...also get wrecked: pastebin.com/VxwNdRqL

Attached: 40d2fd0bb7164791af55f19463215f864e11a29ad7932cd486c631aa9a9853b4.jpg (600x604, 94K)

Also, before someone points this out, I know this can be made more efficient by using a bitmask and combining the trackers used for 15 & 5, but this seemed more straightforward and modifiable.

I also know some people would opt for const over #define. My goal here was to keep the program's memory footprint down. I didn't want to just assume that the compiler was smart enough to make that optimization by default and in a program as short and contained as fizzbuzz #define is not a bad choice.

for(let i=1;i

int fizz;
unsigned int buzz;
std::cout

Whitespace can be a good thing you know. Tou shouldn't always just stick everything on one line even if you can. Also, that's a lot of %

It was just an attempt at a short solution, wasn't going for a clean one.

You can't change the capitalization with this code though. Suppose we want:
ex.
1
2
Fizz!
4
Buzz!
Fizz!
7
8
Fizz!
Buzz!
11
Fizz!
13
14
Fizzbuzz!
16
17
...

My favorite fizzbuzz is this one.

Attached: best-fizzbuzz.png (543x81, 6K)

so why are you so ben't on taking the percentage of i by 15?

I'm not sure what you mean by bent, it was a quick attempt at solving the problem in a short way, it's far from perfect. Would you have any suggestions on how to shorten it further? I'm sure it could be done better. (preferably without resorting to global variables and other such stuff).

mine
import "fmt"

func main() {
for i := 0; i < 100; i++ {
if ((i % 3) == 0) || ((i % 5) == 0) {
if (i % 3) == 0 {
fmt.Print("Fizz")
}
if (i % 5) == 0 {
fmt.Print("Buzz")
}
} else {
fmt.Print(i)
}
fmt.Println()
}
}

really like that

That's bad, you are doing the calculations multiple times

Also I just realized I interpreted this post as criticizing me for using i%15 instead of a shorter method, but you may of just been asking why I used 15 at all.

If that's the case it's simply because i%15 is basically the same as ((i%3) && (i%5)) except shorter.

problem being, in Go, switches aren't the same as switches in, say, C. also, Go doesn't allow you to assign and compare in a single statement...
anyway, here's a version that won't do the calculations multiple times :) (but it will compare their result multiple times, though)
package main

import "fmt"

func main() {
var a, b bool
for i := 0; i

What's up, faggots? All those moduli make me SICK.
#include

using namespace std;

int gcd(int a, int b)
{
if (a == b)
return a;
if (a>b)
return gcd(a-b, b);
return (gcd(a, b-a));
}

int main()
{
int fizz{};
int buzz{};
string fizzs{};
string buzzs{};
string nig[100];

for (string* i = nig; i-nig fizzs;
cout > fizz;
cout > buzzs;
cout > buzz;
for (int i = fizz-1; i < 100; i += fizz)
{
nig[i] = fizzs;
}
for (int i = buzz-1; i < 100; i += buzz)
{
nig[i] = buzzs;
}
int lcm = fizz * buzz / gcd(fizz, buzz);
for (int i = lcm-1; i < 100; i += lcm)
{
nig[i] = fizzs + buzzs;
}
for (string* i = nig; i-nig

for (i = 1:100) {
superswitch (j =15|3|5 in i%j == 0) {
case 15: print("Fizzbuzz"); break;
case 3: print("Fizz"); break;
case 5: print("Buzz"); break;
default: print(i);
}
}

fuck you ternary operators are cool alright

Read constants from, say, a json file.

DIVISORS = {3: "Fizz", 5: "Buzz"}
NUM_RNG = (0, 100, 1)

for n in range(NUM_RNG[0], NUM_RNG[1], NUM_RNG[2]):
result = ""
for d in DIVISORS:
if n % d == 0:
result += DIVISORS[d]
if result == "":
result = n
print(result)

Whats with all the pajeet langs ITT?
>(:i.100)(]`[@.(0:=#@>@]))"0 0(100$(2$a:),(100$(4$a:),