Consider the following problem:

Consider the following problem:

>Write a short program that prints each number from 1 to 100 on a new line

>For each multiple of 3, print "Fizz" instead of the number

>For each multiple of 5, print "Buzz" instead of the number

>For numbers which are multiples of both 3 and 5, print "FizzBuzz" instead of the number

Attached: KZBOLwZ.png (728x800, 79K)

Other urls found in this thread:

github.com/enfiskutensykkel/rmi-fizzbuzz
github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition
twitter.com/NSFWRedditGif

Why would I do that?

you don't have to if you can't do it user

#include
#include

int main(){

uint8_t i;

for(i = 1; i

ez

Attached: fizzbuzz.jpg (412x589, 52K)

Yea no, that sounds stupid

1kb is 8000 bytes
because 1bits = 8bytes

this will be worth trillions $$$$$

Attached: pobrane.jpg (279x181, 14K)

function fb(n, max) {
var output = '';
if(n % 3 == 0) output += 'Fizz';
if(n % 5 == 0) output += 'Buzz';
if(output.length == 0) output += n;
console.log(output);
if(n < max) fb(n+1, max);
}

fb(1, 100);

First time using recursion. Next time will try without modulus.

This sounds like the shit our CS professor gave us as beginners exercise for introduction to Python programming.

using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
public static IEnumerable FizzBuzz
{
get
{
for (var i = 1; ; ++i)
{
string fizzBuzz = (i % 3 == 0 ? "Fizz" : "") + (i % 5 == 0 ? "Buzz" : "");

yield return fizzBuzz.Length >= 1
? fizzBuzz
: i.ToString();
}
}
}

public static void Main()
{
foreach (var item in FizzBuzz.Take(100))
{
Console.WriteLine(item);
}
}
}

It's his homework.

Hope you don't mind my condensed javascript
for (var i = 1; i

>op gets an incredibly well-documented and solved problem for homework that has solutions found everywhere on the internet
>posts his question disguised as a programming exercise thread

makes sense to me

Anoher js solution
for (var i = 1; i

exec("def a(i):\n\tif i%3==0 and i%5==0: print 'fizzbuzz'\n\telif i%3 == 0: print 'fizz'\n\telif i % 5 == 0: print 'buzz'\n\telse: print i\n\t[a(i) for i in range(1,101)]")

console.log(new Array(99).map((_, n) => ++n % 15 == 0 ? "FizzBuzz" : n % 5 == 0 ? "Buzz" : n % 3 ? "Fizz" : n).join(" "));

Dunno if it's working.

```python
def fb(n):
for i in range(1, n + 1):
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)

fb(100)
```

Last thread few anons were saying fizzbuzz is not just to filter fake programmers but they specifically check how adaptable someone is, so a program that is actually acceptable by interviewers would be a program that allows new rules ro easily added for example, multiple of 7s and 11s for instance, but one thing I didn't understand from those anons was that, why adding more if and else statement for new rules would be wrong, which they were most likely implying.
Please some guy with job with interviewer friend, answer

t. discord newfag

well in this case it wouldnt be wrong but in a realworld senario you want something less boilerplate and finicky than 100 else statements strung along eachother.

just like object oriented right.
a lot of problems I solve have a lot of if else stuff but two guys with jobs in this field, always laugh at me, are using if else statement that bad? should they always be left for desperate situations?

hello sir i am good programer
#include

int main() {
printf("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nFizzBuzz\n31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43\n44\nFizzBuzz\n46\n47\nFizz\n49\nBuzz\nFizz\n52\n53\nFizz\nBuzz\n56\nFizz\n58\n59\nFizzBuzz\n61\n62\nFizz\n64\nBuzz\nFizz\n67\n68\nFizz\nBuzz\n71\nFizz\n73\n74\nFizzBuzz\n76\n77\nFizz\n79\nBuzz\nFizz\n82\nn83\nFizz\nBuzz\n86\nFizz\n88\n89\nFizzBuzz\n91\n92\nFizz\n94\nBuzz\nFizz\n97\n98\nFizz\nBuzz\n");
}

You are hired Sir.

(1...100).map { n in
var ret = String()
if n % 3 == 0 { ret += "Fizz" }
if n % 5 == 0 { ret += "Buzz" }
if ret.isEmpty { ret = String(n) }
return ret
}.forEach { print($0) }

Why can't I post my genius MATLAB solution?

Every time I try I get "Connection error".

It's not wrong and FizzBuzz is a stupid way to test how easy or hard it is for a programmer to adapt to change since it's such a trivial problem that takes 1 minute to write out. If you're solving the problem by concatenating strings (which is the way you should do it) there is no other cleaner way to solve it other than having sequential if statements.

If you ever interview and are tasked to write FizzBuzz and they complain that your solution isn't adaptable to change, just tell them bluntly that it's a trivial problem and that designing it to take on any arbitrary amount of conditions would be more work and effort than simply re-writing it every time requirements change.

var a ="fizz"
var b = "buzz"

for (var i = 1; i

I guess I could also assign the numbers to variables so maybe if you're using some sort of input to change when to print fizzbuzz at specific numbers it would automatically changed based on the number variable not just always 3 & 5

Use post a reply at the top in that case.

const cycler = (n, s) => {
let i = 0;
return () => {
if (++i == n) {
i = 0;
return s;
}

return "";
}
}

const [...fizzbuzz] = (function* (n, f, g) {
for (let i = 0; i < n; ++i) {
yield f() + g() || i + 1;
}
})(100, cycler(3, "Fizz"), cycler(5, "Buzz"))

But 1KB is indeed 1000 bytes?
If you want 1024 bytes then it's KiB, not KB.

fuck that's ugly

Noob question but, how do I format my answer in code tags?

Testing if I'm retarded

Test passed, think this time it'll work... lol

#include

int main()
{
for(int i = 1; i < 100; i++)
{
if((i % 3) == 0)
{
printf("Fizz\n");
}
else if((i % 5) == 0)
{
printf("Buzz\n");
}
else if((i % 3) == 0 && (i % 5) == 0)
{
printf("FizzBuzz\n");
}
else
{
printf("%d\n", i);
}
}
}

Well, a kB is 1000 bytes. A KB is a kelvin-byte. A kb, as in the OP, is 1000 bits.

Attached: Screen Shot 2018-03-31 at 13.40.44.png (952x558, 64K)

You need [ code ] [ /code ] tags. Without the spaces.

#include

int main()
{
for(int i = 1; i < 100; i++)
{
if((i % 3) == 0)
{
printf("Fizz\n");
}
else if((i % 5) == 0)
{
printf("Buzz\n");
}
else if((i % 3) == 0 && (i % 5) == 0)
{
printf("FizzBuzz\n");
}
else
{
printf("%d\n", i);
}
}
}

"Your IP or IP range is blocked from accessing Jow Forums."

Yeah thanks, just pasted my code again with them after I saw this

This is incorrect. Move the last if check to the top.

How did you post that?

if you're an unemployable NEET, sure, it's ugly

That is what I get if I try to post my code through the "Post reply" section at the top.

Replying works perfectly fine, if I don't try to post my code.

Have an implementation in a little abortion of a language written for my CS course.
# Fizzbuzz

%:import:(read) |> r.

:do:(_ _ :Xs:X) |> :Xs:X
:do:(_ _ _ _ :Xs:X) |> :Xs:X


:if:(|T :Xa:X :_:_) |> :Xa:X
:if:(|F :_:_ :Ya:Y) |> :Ya:Y

:fizzbuzz:(101) |> ()
:fizzbuzz:(X) |> :do:(
:r.printn:X
:if:(
:==:(:mod:(X 3) 0)
:r.prints:" Fizz"
()
)
:if:(
:==:(:mod:(X 5) 0)
:r.prints:" Buzz"
()
)
:printc:'\n'
:fizzbuzz:(:+:(X 1))
)

:main:() |> :fizzbuzz:(1)

### Functions ###
range = $(if $(filter $1,$(lastword $3)),$3,$(call range,$1,$2,$3 $(words $3)))
make_range = $(foreach i,$(call range,$1),$(call range,$2))
equal = $(if $(filter-out $1,$2),,$1)


### Variables ###
limit := 101
numbers := $(wordlist 2,$(limit),$(call range,$(limit)))

threes := $(wordlist 2,$(limit),$(call make_range,$(limit),2))
fives := $(wordlist 2,$(limit),$(call make_range,$(limit),4))

fizzbuzz := $(foreach v,$(numbers),\
$(if $(and $(call equal,0,$(word $(v),$(threes))),$(call equal,0,$(word $(v),$(fives)))),FizzBuzz,\
$(if $(call equal,0,$(word $(v),$(threes))),Fizz,\
$(if $(call equal,0,$(word $(v),$(fives))),Buzz,$(v)))))


### Target ###
.PHONY: all
all: ; $(info $(fizzbuzz))

a = '';
b = '';
for i = 1:100
if mod(i,3) == 0
a = 'Fizz';
i = a;
end
if mod(i,5) == 0
b = [a 'Buzz'];
i = b;
end
i
end

I know Java is a pajeet language but thought it would be fun to post:

public class FizzBuzz {

public static void main(String args[]) {

for(int i = 0; i < 100; i++) {
if(isMultiple(i, 3)) {
System.out.println("Fizz");
} else if(isMultiple(i, 5)) {
System.out.println("Buzz");
} else if(isMultiple(i, 3) && isMultiple(i, 5)) {
System.out.println("FizzBuzz");
} else {
System.out.println(i);
}
}
}


public static boolean isMultiple(int integer, int multiple) {
return (integer % multiple) == 0;
}
}

>Java
At least do it properly

github.com/enfiskutensykkel/rmi-fizzbuzz

>github.com/enfiskutensykkel/rmi-fizzbuzz
Oh my lord that is hilariously overkill haha

This will NEVER print FizzBuzz.

php

for($i=1; $i

Glad to see you made to the Intro to Computer Science midterm

for i in range (0,100):
if i%15 ==0:
print ('FizzBuzz')
elif i%5 ==0:
print ('Buzz')
elif i%3 ==0:
print ('Fizz')
else:
print (i)

github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

>FizzBuzz is always multiples of 15
Holy shit why didn't I think of this before. I feel dumb now.

Attached: 1488404727233.jpg (337x372, 17K)

type fb =
{
fizz : bool;
buzz : bool;
}
;;

type classified =
{
n : int;
fb : fb;
}
;;

let print_classified = function
| {
n = n;
fb =
{
fizz = fizz;
buzz = buzz;
};
} ->
let s =
match fizz, buzz with
| false, false -> string_of_int n
| false, true -> "buzz"
| true, false -> "fizz"
| true, true -> "fizzbuzz" in
print_endline s
;;

let classify_int n =
let fb =
{
fizz = n mod 3 = 0;
buzz = n mod 5 = 0;
} in
{
n = n;
fb = fb;
}
;;

let classify_ints ints =
let rec loop accu = function
| [] -> List.rev accu
| n :: ns -> loop (classify_int n :: accu) ns in
loop [] ints
;;

let range start length =
let rec loop accu i = function
| 0 -> List.rev accu
| n -> loop (i :: accu) (succ i) (pred n) in
loop [] start length
;;

let () =
let ints = range 1 100 in
let classified_ints = classify_ints ints in
List.iter print_classified classified_ints
;;

>8700 stars and over 700 forks
I don't even...

#include
using namespace std;

int main()
{
string x[12][7] =
{
{" ### ", " # # ", "# #", "# #", "# #", " # # ", " ### "},//0
{" # ", " ## ", " # # ", " # ", " # ", " # ", " ##### "},//1
{" ##### ", "# #", " #", " ##### ", "# ", "# ", "#######"},//2
{" ##### ", "# #", " #", " ##### ", " #", "# #", " ##### "},//3
{" # ", " ## ", " # # ", " # # ", " ######", " # ", " # "},//4
{"#######", "# ", "# ", "###### ", " #", "# #", " ##### "},//5
{" ##### ", "# #", "# ", "###### ", "# #", "# #", " ##### "},//6
{"#######", "# # ", " # ", " # ", " # ", " # ", " # "},//7
{" ##### ", "# #", "# #", " ##### ", "# #", "# #", " ##### "},//8
{" ##### ", "# #", "# #", " ##### ", " #", "# #", " ##### "},//9
{"####### ### ####### ####### ", "# # # # ", "# # # # ", "##### # # # ", "# # # # ", "# # # # ", "# ### ####### ####### "},
{"###### # # ####### #######", "# # # # # # ", "# # # # # # ", "###### # # # # ", "# # # # # # ", "# # # # # # ", "###### ##### ####### #######"}
};

for (int i = 1; i

Haha thanks user! I just assumed I was right and posted without compiling, now I have to own up to writing both of these and repost my corrections:

#include

int main()
{
for(int i = 1; i < 100; i++)
{
if((i % 3) == 0 && (i % 5) == 0)
{
printf("FizzBuzz\n");
}
else if((i % 3) == 0)
{
printf("Fizz\n");
}
else if((i % 5) == 0)
{
printf("Buzz\n");
}
else
{
printf("%d\n", i);
}
}
}

public class FizzBuzz {

public static void main(String args[]) {

for(int i = 1; i < 100; i++) {

if(isMultiple(i, 3) && isMultiple(i, 5)) {
System.out.println("FizzBuzz");
} else if(isMultiple(i, 3)) {
System.out.println("Fizz");
} else if(isMultiple(i, 5)) {
System.out.println("Buzz");
} else {
System.out.println(i);
}
}
}

public static boolean isMultiple(int integer, int multiple) {
return (integer % multiple) == 0;
}
}

oWo what's this

#include
#include
#include

static bool default_map[] = {
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0,
0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0,
1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1,
0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0,
0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0
};


void print_row(bool* map, size_t width, size_t xspc, char symbol)
{
for (size_t col = 0; col < width; ++col)
{
printf("%c", map[col] ? symbol : ' ');

for (size_t x = 0; x < (width - col) && x < xspc; ++x)
{
printf(" ");
}
}
}


void print_rows(bool* map, size_t width, size_t height, size_t xspc, size_t yspc, char symbol)
{
for (size_t row = 0; row < height; ++row)
{
print_row(map + width * row, width, xspc, symbol);

for (size_t y = 0; y < (height - row) && y < yspc; ++y)
{
printf("\n");
}
}
}


int main()
{
print_rows(default_map, 13, 13, 2, 1, '*');
return 0;
}


Rate my FizzBuzz, Jow Forums

Still not correct though, loop will run 1-99, needs to be 1-100.

Go on, defend your shitty solution
How is it superior to any other solution posted here, or even a simple loop with if/else?

Is that a swastika lol

Ah, that's a habit of mine to start i=0. No point reposting again, thanks for letting me know any way user

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

That's because 3*5=15, never occurred to me either though

What language is that?

Brilliant, can't wait for FizzBuzzUltimateEdition

Fizz Buzz as a Service

14/88

No, I don't think desperate is right. Minimal situations, things you know you will not have to expand.
If you're making something that does continually grow and change, object oriented may be right. A lot of times it's good to have a folder of different files treated as "modules", though that will ussualy take some reworking of the logic to impliment perfectly.

FizzBuzz using a service bus

That isn't just for discord, that was markdown syntax. It's definitely NOT only used by discord.

FizzBuzz Enhanced

This is pretty... What language is this?

It's a language I wrote for my 3rd year uni course. It's a bastard child of Prolog and Lisp and works by performing pattern matching and substitution of trees. I called it Fangorn.

Guys, I think I got it.

console.log(1); console.log(2); console.log("Fizz"); console.log(4); console.log("Buzz"); console.log("Fizz"); console.log(7); console.log(8); console.log("Fizz"); console.log("Buzz");
console.log(11); console.log("Fizz"); console.log(13); console.log(14); console.log("FizzBuzz"); console.log(16); console.log(17); console.log("Fizz"); console.log(19); console.log("Buzz");
console.log("Fizz"); console.log(22); console.log(23); console.log("Fizz"); console.log("Buzz"); onsole.log(26); console.log("Fizz"); console.log(28); console.log(29); console.log("FizzBuzz");
console.log(31); console.log(32); console.log("Fizz"); console.log(34); console.log("Buzz"); console.log("Fizz"); console.log(37); console.log(38); console.log("Fizz"); console.log("Buzz");
console.log(41); console.log("Fizz"); console.log(43); console.log(44); console.log("FizzBuzz"); console.log(46); console.log(47); console.log("Fizz"); console.log(49); console.log("Buzz");
console.log("Fizz"); console.log(52); console.log(53); console.log("Fizz"); console.log("Buzz"); console.log(56); console.log("Fizz"); console.log(58); console.log(59); console.log("FizzBuzz");
console.log(61); console.log(62); console.log("Fizz"); console.log(64); console.log("Buzz"); console.log("Fizz"); console.log(67); console.log(68); console.log("Fizz"); console.log("Buzz");
console.log(71); console.log("Fizz"); console.log(73); console.log(74); console.log("FizzBuzz"); console.log(76); console.log(77); console.log("Fizz"); console.log(79); console.log("Buzz");
console.log("Fizz"); console.log(82); console.log(83); console.log("Fizz"); console.log("Buzz"); console.log(86); console.log("Fizz"); console.log(88); console.log(89); console.log("FizzBuzz");
console.log(91); console.log(92); console.log("Fizz"); console.log(94); console.log("Buzz"); console.log("Fizz"); console.log(97); console.log(98); console.log("Fizz"); console.log("Buzz");

What the hell is that star syntax, enlighten me.

You have one mistake, but I won't say where.

I know I know. I'm afraid my logical thinking hindered my mathematical thinking completely.

That's how you make generators in JavaScript

>onsole is not defined
I deserved it for not debugging my code.

You think this is funny but I just know that somewhere some dumbass actually did this.

>1bits = 8bytes

Attached: 1514673020670.png (208x232, 26K)

Boom hired

It's an IEnumerable and can utilize LINQ, which means that the user can do stuff like skipping an arbitrary number of iterations
FizzBuzz.Skip(10).Take(100)
reversing the sequence
FizzBuzz.Take(100).Reverse()
counting the number of Buzzes
FizzBuzz.Take(100).Count(x => x == "Buzz")
etc.

Not bad. Never seen anything quite like it.

[code 01101111 01110010 00100000 01111000 00100000 01101001 01101110 00100000 01110010 01100001 01101110 01100111 01100101 00100000 00101000 00110000 00101100 00100000 00110001 00110000 00110001 00101001 00111010 00001101 00001010 00100000 00100000 00100000 00100000 01101001 01100110 00100000 01111000 00100000 00100101 00100000 00110011 00100000 00111101 00111101 00100000 00110000 00100000 01100001 01101110 01100100 00100000 01111000 00100000 00100101 00100000 00110101 00100000 00100001 00111101 00100000 00110000 00111010 00001101 00001010 00100000 00100000 00100000 00100000 00100000 00100000 00100000 00100000 01110000 01110010 01101001 01101110 01110100 00101000 00100010 01000110 01101001 01111010 01111010 00100010 00101001 00001101 00001010 00100000 00100000 00100000 00100000 01100101 01101100 01101001 01100110 00100000 01111000 00100000 00100101 00100000 00110101 00100000 00111101 00111101 00100000 00110000 00100000 01100001 01101110 01100100 00100000 01111000 00100000 00100101 00100000 00110011 00100000 00100001 00111101 00100000 00110000 00111010 00001101 00001010 00100000 00100000 00100000 00100000 00100000 00100000 00100000 00100000 01110000 01110010 01101001 01101110 01110100 00101000 00100010 01000010 01110101 01111010 01111010 00100010 00101001 00001101 00001010 00100000 00100000 00100000 00100000 01100101 01101100 01101001 01100110 00100000 01111000 00100000 00100101 00100000 00110011 00100000 00111101 00111101 00100000 00110000 00100000 01100001 01101110 01100100 00100000 01111000 00100000 00100101 00100000 00110101 00100000 00111101 00111101 00100000 00110000 00111010 00001101 00001010 00100000 00100000 00100000 00100000 00100000 00100000 00100000 00100000 01110000 01110010 01101001 01101110 01110100 00101000 00100010 01000110 01101001 01111010 01111010 01000010 01110101 01111010 01111010 00100010 00101001 00001101 00001010 00100000 00100000 00100000 00100000 01100101 01101100 01110011 01100101 00111010 00001101 00001010 00100000 00100000[/code]

If only you knew how to properly open and close a code tag. If only...

It's garbage that barely let me pass, but it's definitely more creative than all the 'c--' derivative trash other students were making specifically to tick all the checkboxes.

for (var i = 0; i < 100; i++) {
let output = i

if (i % 3 === 0) {
output = 'Fizz'
}

if (i % 5 === 0) {
!isNaN(output) ? output = 'Buzz' : output += 'Buzz'
}

console.log(output)
}

This is so dirty I like it.

var
i:integer;
begin
for i:=1 to 100 do
if (i mod 3=0) and (i mod 5=0) then
writeln('fizzbuzz')
else if i mod 3=0 then
writeln('fizz')
else if i mod 5=0 then
writeln('buzz')
else
writeln(i);
readln;
end.

this is the only acceptable answer.

def main():
program = ""
program += "def main():\n"
out = ""
for i in range(1, 101):
if i % 3 == 0:
out += "\"Fizz\""
if i % 5 == 0:
out += "\"Buzz\""
if out == "":
out = i
program += "\tprint(" + str(out) + ")\n"
out = ""
program += "\n\n"
program += "if __name__ == \"__main__\":\n"
program += "\tmain()\n"
exec(program)

if __name__ == "__main__":
main()

Except it's wrong.