[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/fbg/ FizzBuzz General
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 107
Thread images: 19
File: code_artisan.webm (2 MB, 292x304) Image search: [Google]
code_artisan.webm
2 MB, 292x304
let's see yours
>>
That seems rather impractical, how did you do it?
>>
>Font in OP's webm isn't fixed width
>>
>>55582763
this physically hurts me to watch it..
>>
>atom
>>
File: 1356460807685.jpg (15 KB, 553x351) Image search: [Google]
1356460807685.jpg
15 KB, 553x351
>>55582763
>being this disgusting
why even live?
>>
>>55582763
this was physically painful to watch.
>>
>>55582763
>var
>not let
>>
Non-strict equality sign used. Disqualified from teh job interview.
>>
>>55582763
Is that fucking Comic Sans?
>>
        for (int i = 1; i <= 100; ++i)
{
if (i % 3 == 0)
printf("Fizz");
else if (i % 5 == 0)
printf("Buzz");
else if (i % 15 == 0)
printf("FizzBuzz");
else
printf("%d", i);

printf("\n");
}
>>
>>55585454
Let's see how many times it reaches i%15
>>
>>55585454
> i % 15 at the end
nice desu
>>
>>55585454
bruh...
>>
for (int i = 1; i <= 100; ++i) {
std::cout << i % 15 == 0? "fizzbuzz" : i % 3 == 0 ? "fizz" : i % 5 == 0 ? "buzz" : i;
}
>>
>>55582763
kill yourself
>>
>>55585497
maybe he only likes fizz
>>
>>55582763
Damn I could hear the thumps on every keystroke
>>
File: a.webm (2 MB, 912x748) Image search: [Google]
a.webm
2 MB, 912x748
>>
>>55585545
What a clusterfuck
>>
Why does it have that faggy animation? Why is he using comic sans?
>>
def fizzbuzz(n):
out = ""
for i in range(0, n):
if i % 3 == 0:
out += "Fizz"
if i % 5 == 0:
out += "Buzz"
if out =="":
print (i)
else:
print(out)
out = ""

fizzbuzz(100)


Meh I don't like checking equality with a string but I also don't want to use else-if
>>
>>
>>55585589
because op barely learned to program and is still fascinated by letters, parens, and braces
>>
>>55585454
Dat indentation tho
>>
>>55585597
>re
>tard
>ed
Just give up
>>
for i in range(1, 101):
print "FizzBuzz"[i * i % 3 * 4:8 - -i ** 4 % 5] or i
>>
>>55582763
>being this retarded

You know that if something is divisible by 3 and 5 it is divisible by 15 right?
>>
>>55585597
print ' '.join(['fizzbuzz' if not i%15 else 'fizz' if not i%3 else 'buzz' if not i%3 else str(i) for i in range(1,101)])

Python wins again gents, game over you can go home.
>>
DON'T STAB ME BIRD!
NUMBERS = 100

def getFizzBuzz(number):
if number % 15 == 0:
return "'fizzbuzz'"
elif number % 3 == 0:
return "'fizz'"
elif number % 5 == 0:
return "'buzz'"
else:
return "i"


print("for i in range(1,%i):" % NUMBERS)
for i in range(1,NUMBERS+1):
if i == 1:
print(" if i == %i:\n print(%s)" % (i,getFizzBuzz(i)))
else:
print(" elif i == %i:\n print(%s)" % (i,getFizzBuzz(i)))

>>
>>55585655
First 3 is obvioulsy a 5, inb4 typo I'll fucking cut you niggers
>>
>>55585598
why not i = 0; i < 100?
Also can you explain the bit manipulation? I'm about to collapse.
>>
>>55585655
How can snakes even compete?
for(n=0;++n<101;)console.log((n%3?'':'Fizz')+(n%5?'':'Buzz')||n)
>>
File: 1467886382026.png (180 KB, 379x551) Image search: [Google]
1467886382026.png
180 KB, 379x551
>>55585661
>>
>>55585583
>i cant read trinary operators
>>
File: python.png (80 KB, 1000x1000) Image search: [Google]
python.png
80 KB, 1000x1000
>>55585649
people like OP only have heard of fizzbuzz because of /g/ and never actually had an enriching childhood

the whole point of this children's game is to teach you that things that are divisible by 3 and 5 are exactly things that are divisible by 15

fucking dumb as fuck
>>
>>55585712
>people like OP only have heard of fizzbuzz because of /g/ and never actually had an enriching childhood
Or maybe he lives in a country where we use different methods to teach division?
>>
I wrote this a long time ago:
(defun fizzbuzz ()
(interactive)
(let ((fizz nil)
(buzz nil))
(dotimes (counter 101)
(when (not (= counter 0))
(insert (format "%s%s%s\n"
(if (setq fizz (= (mod counter 3) 0))
"Fizz" "")
(if (setq buzz (= (mod counter 5) 0))
"Buzz" "")
(if (not (or fizz buzz))
(number-to-string counter) "")))))))
>>
>>55585583
You're an idiot. What is your reasoning? You don't understand it therefore it must be stupid, right? It's not even complicated, you are just retarded
>>
>>55585717
>teach division
In any place that fucking matters, you don't get "taught" division until way later. Fizzbuzz is kindergarten shit.
>>
File: 1467493199108.png (408 KB, 502x498) Image search: [Google]
1467493199108.png
408 KB, 502x498
>>55585722
Whta the fuck is that shit?
>>
>>55585750
It's Emacs Lisp.
>>
>>55585742
In any case atleast in my european country we never did fizzbuzz in kindergarten
>>
>>55585693
>>55585598

i, i, fizz, i, buzz, fizz, i, i... can be written as:
00, 00, 01, 00, 10, 01, 00, 00...

Make it go from right to left and you get:
110000010010010000011000010000

which is the magic number 810092048


Each loop mods and shifts i to figure out the offset within the sequence m to extract, then shifts m right that far and masks it with 3 (0b11). The 00, 01, 10, or 11 then just pulls out the string from the array to print directly.
>>
#include <stdio.h>

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\n83\nFizz\nBuzz\n86\nFizz\n88\n89\nFizzBuzz\n91\n92\nFizz\n94\nBuzz\nFizz\n97\n98\nFizz\nBuzz");
}
>>
int main(void)
{
int i;
for(i=1;i<=100;i++)
{
if(!(i%15))
puts("FizzBuzz");
else if(!(i%3))
puts("Fizz");
else if(!(i%5))
puts("Buzz");
else
printf("%d\n",i);
}
return 0;
}
>>
>>55585447
yes :)
>>
#include "Display.h"

void setup() {
ht1632_setup();
}

void loop() {
for (int i = 1; i < 101; i++) {
if (floatdiv(i, 15) == (i / 15)) {
showText("FizzBuzz");
} else if (floatdiv(i, 3) == (i / 3)) {
showText("Fizz");
} else if (floatdiv(i, 5) == (i / 5)) {
showText("Buzz");
} else {
char c[4];
sprintf(c, "%d", i);
showText(c);
}

delay(500);
}
}

float floatdiv(int a, int b) {
return (float) a / (float) b;
}

void showText(const char str[]) {
char output[10];
memset(output, 0, 10);
strcpy(output, str);
for (int i=0; i < 10; i++) {
ht1632_putchar(0+6*i, 0, output[i], GREEN);
}
}

Mine doesn't use modulus for no apparent reason.
>>
>>55585788
0x1241843 looks better imo
00 00 01 00 10 01 00 00 01 10 00 01 00 00 11
>>
>>55585703
>>55585730
Stacking multiple ternary operators in one line is obvious bad practice. Code like that doesn't get merged into any serious project because it sacrifices readability for being concise while the entire purpose of concise code is readability.
>>
File: paddingtest.png (446 B, 163x109) Image search: [Google]
paddingtest.png
446 B, 163x109
don't mind me
>>
>>55585695
That || operator is the most cringey thing in the whole fucking world.
>falsy values
>>
>>55585921
That only works if you work with mentally-challenged people.
>>
File: paddingtest2.png (595 B, 163x109) Image search: [Google]
paddingtest2.png
595 B, 163x109
>>55585930
>>
File: paddingtest3.png (1 KB, 163x109) Image search: [Google]
paddingtest3.png
1 KB, 163x109
>>55585941
>>
>>55585571
>if 3, if 5
>not if 15

okay
>>
>>55585921
>sacrifices readability
No, it doesnt. it literally took me one second to see through, faggot
>>
File: 1458555999372.png (215 KB, 393x374) Image search: [Google]
1458555999372.png
215 KB, 393x374
>>55585571
>his IDE doesn't have a Graduate button
>>
>>55582763

for num in range(1,100):
fizz = num % 3 == 0;
buzz = num % 5 == 0;

if fizz && buzz:
print ('FizzBuzz')
elif fizz:
print ('Fizz')
elif buzz:
print ('Buzz')
else:
print num



there is probably easier ways to do it, but this is how i'd do it.
>>
>>55585932
Fuck I just found out python does the same

for i in range(1,101):
print ('fizz' if not i%3 else '') + ('buzz' if not i%5 else '') or i
>>
>>55585937
>>55585977
You'd just fail to comply to any code style guide for a reason. Stacking your logic extremely horizontally is pretentious bullshit.

Reasoning like
>i see it through in 0.3 because I'm great
is great for writing hacky code.
>>
>>55582763
>only space before new line
>no tabs

kys 2bh familia
>>
File: Terminal_2016-07-15_13-36-53.png (11 KB, 462x304) Image search: [Google]
Terminal_2016-07-15_13-36-53.png
11 KB, 462x304
>>
>>55586159
>he uses wubdiws 19
>>
>>55586159
wtf is a %i
>>
>>55586016
Since the loop only has one line, this is okay too:
for i in range(1,101): print ('fizz' if not i%3 else '') + ('buzz' if not i%5 else '') or i
>>
>>55586193
equivalent of %d for use with printf.

>>55586176
i need it for audio stuff. don't like osx, next to no driver support on linux.
>>
>>55586193
One of the many reasons why C should die, like %n.
>>
class FizzBuzzCommandlet extends Commandlet;

event int Main(string Parms)
{
local int i;
local string S;

while(i++ < 100)
{
S = "";
if(i % 3 == 0)
S $= "Fizz";
if(i % 5 == 0)
S $= "Buzz";
Log(Eval(S=="",i,S));
}
return 0;
}
>>
#include <stdio.h>
int main() {
for (int 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;
}

good enough?
>>
What is the obsession with FizzBuzz?
Haven't we discussed this way too many times?
>>
>>55582763
could someone explain me why the interpreter reports an error regarding the heredoc?
<?php //test
echo <<<_END
<html>
<head>
<title> Form Test</title>
</head>
<body>
<form method="post" action="form.php">
Something:
<input type="text" name="name">
<input type="submit">
</form>
</body>
</html>
_END;
?>

>>
fizzbuzz = {5:"buzz",3:"fizz"}
z=0
for x in range(1,100):
print()
for num, fb in enumerate(fizzbuzz):
if x%fb==0:
z+=1
print(fizzbuzz[list(fizzbuzz.keys())[num]], end='')
continue
print()
if z == 0:print(x)
z=0
>>
#include <iostream>
int main(){for(int i=1;i<101;i++){if(!(i%3))std::cout<<"Fizz\n";if(!(i%5))std::cout<<"Buzz\n";if(!(i%15))std::cout<<"FizzBuzz\n";else std::cout<<i<<"\n";}return 0;}
>>
File: csmajors.png (71 KB, 412x433) Image search: [Google]
csmajors.png
71 KB, 412x433
>>55585571
When you push the graduate button, it prints out pic related.
>>
private static void FizzBuzz(string size)
{
int tam = int.Parse(size);
for (int i = 1; i <= tam; i++)
{
if (i % 3 != 0 && i % 5 != 0)
Console.WriteLine(i);
else
{
if (i % 3 == 0)
Console.Write("Fizz");
if (i % 5 == 0)
Console.Write("Buzz");
Console.Write("\n");
}
}
Console.ReadKey();
}
>>
>>55585750
You!
>>
>>55583365
same i actually feel like someone's drilling into my skull whenever atom webms are posted
>>
>>55587432
You fucked up. Try again.
>>
>>55586159
>
void main

why not
int main
?
>>
>>55587475
Explain
>>
File: 1455222166063.png (11 KB, 429x410) Image search: [Google]
1455222166063.png
11 KB, 429x410
>>55585722
fucking wizardry in here
>>
>>55586554
It is because it is the tool braindead HR people use to hire programmers since they know nothing about it themselves and thus is so common during job interviews.
>>
>>55587509
Because there is no return statement.
>>
How shitty is my code?

for n in range(1, 101):
if n % 15 == 0:
print "FizzBuzz"
elif n % 3 == 0:
print "Fizz"
elif n % 5 == 0:
print "Buzz"
else:
print n
raw_input()
>>
>>
File: perfection.png (88 KB, 562x386) Image search: [Google]
perfection.png
88 KB, 562x386
>>55582763
<!DOCTYPE html>
<html>
<body>
<style>body{counter-reset: item}
span{counter-increment: item; font-family: Helvetica; font-weight: 300}
span:before{content: counter(item) ", "}
span:not(:last-of-type):nth-of-type(3n):before{content: "Fizz, "}
span:not(:last-of-type):not(:nth-of-type(3n)):nth-of-type(5n):before{content: "Buzz, "}
span:not(:last-of-type):nth-of-type(15n):before{content: "FizzBuzz, "}
span:nth-of-type(5n):last-of-type:before{content: "Buzz."}
span:nth-of-type(3n):last-of-type:before{content: "Fizz."}
span:nth-of-type(15n):last-of-type:before{content: "FizzBuzz."}
span:last-of-type:before{content: counter(item) "."}</style>
<script>a=i='';for(;i<100;i++){a += '<span></span>'};document.write(a)</script>
</body>
</html>
>>
File: 1454804964198.jpg (20 KB, 292x219) Image search: [Google]
1454804964198.jpg
20 KB, 292x219
>>55587962
>>
File: VWQjtSKtHZBe_tmp.uub1VPMg5k.png (16 KB, 454x177) Image search: [Google]
VWQjtSKtHZBe_tmp.uub1VPMg5k.png
16 KB, 454x177
>>55586639
Read the doc
>>
>>55582763
Which variant sucks less?
  if(i%15==0) benis = "FizzBuzz";
else if(i%3==0) benis = "Fizz";
else if(i%5==0) benis = "Buzz";
else benis = i;
console.log(benis+"\n");

or
  benis = "";
if(i%3==0) benis += "Fizz";
if(i%5==0) benis += "Buzz";
if(benis=="") benis = i;
console.log( benis=="" ? i : benis);

Also if i ever get a job interview with fizzbuzz, should i rather strive for performance or readability?
>>
>>55588631
readability

once a retard from here wrote a 1 line fizzbuzz program in an interview, and they hired the guy who wrote pseudo code
>>
would >>55587962 be better than
console.log(Array.apply(null, Array(100)).map((a,b) => {return (++b%3?'':'Fizz')+(b%5?'':'Buzz')||b;}).join(' '))
>>
>>55587962
I changed up your code a bit and made it shorter:
<!DOCTYPE html>
<html>
<body>
<style>
span {
counter-increment: item;
}
span:before {
content: counter(item);
}
span:nth-of-type(3n):before {
content: "Fizz";
}
span:nth-of-type(5n):after {
content: "Buzz";
}
span:nth-of-type(5n):not(:nth-of-type(3n)):before {
content: "";
}
</style>
<script>
for (i = 1; i < 101; i++)
document.body.innerHTML+= "<span></span><br/>";
</script>
</body>
</html>
>>
>>55588662
Yeah i thought so..
But i like this one-liner nontheless
for(i=0;++i<101;console.log(i%5?x||i:x+'Buzz'))x=i%3?'':'Fizz'
>>
>>55588743
eh
you lost all punctuation
and numbers still show up with fizzbuzz part
and you can just write block elements instead of inline elements + br
this would be better
<!DOCTYPE html>
<html>
<body>
<style>body{counter-reset: item}
div{counter-increment: item; font-family: Helvetica; font-weight: 300; font-size: 0}
div:not(:nth-of-type(3n)):not(:nth-of-type(5n)):before{content: counter(item) ""; font-size: initial}
div:nth-of-type(3n):before{content: "Fizz"; font-size: initial}
div:nth-of-type(5n):after{content: "Buzz"; font-size: initial}</style>
<script>document.write(Array.apply(null, Array(100)).map(() => '<div></div>').join(''))</script>
</body>
</html>
>>
>>55588804
wait fuck i dont need fontsize with those too
<!DOCTYPE html>
<html>
<body>
<style>body{counter-reset: item}
div{counter-increment: item; font-family: Helvetica; font-weight: 300}
div:not(:nth-of-type(3n)):not(:nth-of-type(5n)):before{content: counter(item) ""}
div:nth-of-type(3n):before{content: "Fizz"}
div:nth-of-type(5n):after{content: "Buzz"}</style>
<script>document.write(Array.apply(null, Array(100)).map(() => '<div></div>').join(''))</script>
</body>
</html>
>>
>>55585583
Script kid who can't actually program detected
>>
>>55587940
it's fine, could be a bit more efficient but it works
>>
File: 2016-07-15-18:22:19-scrot.png (82 KB, 1280x800) Image search: [Google]
2016-07-15-18:22:19-scrot.png
82 KB, 1280x800
>>55588804
The punctuation was wrong, every number should be on a separate line.
>>
>>55588855
How would you improve it? Despite the
raw_input()
>>
#!/bin/cat
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
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
>>
>>55588917
Just remove the
if i % 15 == 0:


And make the next two like:
if i % 3 == 0:
print "Fizz"
if i % 5 == 0:
print "Buzz"


But i'm not sure how to print in the same line in python, for that to work properly

I hope you get the ideia
>>
>>55589010
fastest one yet
>>
for i in range(100) :
print "fizzbuzz" if i % 15 == 0 else "fizz" if i % 3 == 0 else "buzz" if i % 5 == 0 else i
>>
>>55589013
Wait, what?
>>
>>55590270
Something like >>55587432
or the second one of >>55588631
>>
>>55589013
Create a string with the line to print, and then print it at the end.
Thread replies: 107
Thread images: 19

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.