[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
Do people who can't fizzbuzz, yet apply for programming
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: 255
Thread images: 19
File: fizzbuzz.png (32 KB, 481x358) Image search: [Google]
fizzbuzz.png
32 KB, 481x358
Do people who can't fizzbuzz, yet apply for programming jobs, actually exist in real life, /g/? Have you witnessed it? Or is this just a meme?

Also, post your fizzbuzz code in whatever language you like.
>>
Let me guess. You just read a blog post about how x% of job applicants can't program FizzBuzz. You realised that you could program FizzBuzz and became immensely proud of this fact, and decided to show off on /g/.

>Hey /sci/, post your 2+2 calculations in whatever notation you like.
>>
>>54818276

Not immensely proud, the execution of my code is actually kinda ugly, I'm more baffled that people who can't program actually apply for programming jobs. I posted my own code because I didn't find much other than code when looking up "Fizzbuzz" in google images.

2 + 2 calculations can be made to look pretty extensive by the way.
>>
python masterrace

print ("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")
>>
if you have applied for programming jobs, then yes, those people clearly exist in real life, since your fizzbuzz is incorrect.
>>
>>54818424
Is it? How?
>>
I failed FizzBuzz during my job interview. I still got the job though.

I still laugh about it.
>>
>>54818442
Nice
>>
>>54818205
did you write this op? cuz the new lines are so wrong
>>
>>54818464

Yeah, I did, I know it does print it messy, I just tried to make it so the "Fizz" didn't newline, so doing an if for 3 and one for 5 would print FizzBuzz.
>>
>>54818440
I thought the FizzBuzz problem said to replace i with FizzBuzz when it's divisible by 3 and 5.

In this program I is still showing.
>>
>>54818440
it's wrong because it stops at 99.
>>
>>54818556
Oh fuck, it's true. My bad, this should get me off my high horse, I'm too used to loop from 0 to n-1 in arrays.
>>
>>54818540
You really only need the newline at the end of every iteration.
>>
>>54818540

just put one new line after the ifs and remove the rest
>>
>>54818614
Oh, that's true as well, thanks for the tip
>>
The FizzBuzz test isn't to show if you can do it. That's easy. The test is to show how efficient you can do it. Putting in unnecessary lines and making it so it only goes up to 99 is two ways that most fail.
>>
File: fizzbuzz-correct.png (28 KB, 359x346) Image search: [Google]
fizzbuzz-correct.png
28 KB, 359x346
Thanks for helping me not be an arrogant asshole, /g/
>>
>i % 3 && i % 5
>not i % 15
Gets me every time.
>>
>>54818541
First the program prints a newline char
Next the program checks if i is a multiple of 3, if true it prints Fizz
Then the program checks if i is a multiple of 5, if true it prints Buzz
Finally, the program checks if i is neither a multiple of 3 or 5, if true it prints i

In this case, a multiple of 3 would pass the first if, not the second, and not the third. A multiple of 5 would fail the first if, pass the second, and fail the third. A multiple of both would pass the first 2 ifs, and fail the third. A multiple of neither would fail the first 2 and pass the third.
>>
>>54818787
why i % 15?
>>
i % 15 is far more readable than printing fizz+buzz

#include <stdio.h>

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

return 0;
}
>>
>>54818822
Because 3 * 5 is 15 fucking hell
>>
>>54818419
technically this is correct
>>
>>54818850
> i < 101
>>
>>54818858
so if i asked you to fizz at 4 and buzz at 8 you would i % 32 for fizzbuzz?
>>
>>54818880
exactly the same as <= 100
>>
>>54818205
Yeah ive got a buddy who just had a bunch of interviews (one w ibm) and he totally butchered the technical questions he said, they grilled him alive. They didnt ask fizz buzz but he didnt know it when i asked him on the phone
>>
>>54818772

good, now ditch std and you're golden.
>>
>>54818919
How do you get interviewed at IBM and not know fizzbuzz, holy shit...

Then again, I guess IBM only hires poo in the loos now
>>
Well sometimes they are devs who have been programming for years that fail fizzbuzz. I am not exactly sure why these people fail.
>>
>>54818889
I want to see how many FizzBuzzers could handle the (4,8) occasion.
>>
>>54818858
>because 3*5 is 15

15 only works since 3 and 5 are prime, and thus 15 is their gcd. i've asked this before during interviews and few people have gotten it right.
>>
>>54818787
>>54818858

i % 3 && i % 5 is not equivalent to i % 15. Learn basic logic.
>>
I interviewed a girl who couldn't do it, among other questions

She wasn't hired
>>
    for(int i=1;i<=100;i++)
if(i%3==0){
if(i%5==0)printf("\nFizzBuzz");
else printf("\nFizz");
}
else if(i%5==0){
printf("\nBuzz");
}
else printf("\n%d",i);
>>
>>54818948
Because it is a stupid problem. The same reason that mathematicians find it easier speaking of n-dimensional manifolds than figuring out how much they have to pay at a shop.
>>
#include <stdio.h>
int main(void) {

for(int i=1; i<101; ++i)
printf("%d\r%s%s\n", i, "Fizz"+4*!!(i%3), "Buzz"+4*!!(i%5));
return 0;
}
>>
>>54819004
but that's wrong
>>
If you rephrase the question as "do people who can't program at all apply for programming jobs" then the answer is yes.

My uncle took an online paid javascript course and was sent some kind of certificate of completion at the end, afterword he tried applying for a couple jobs for java programming positions failing miserably.

Also I work with a guy that after finding out I dabble in game dev as a hobby said he does too and we should team up and make a game, he said he knew how to use photoshop and ue4. After he builds a new development computer he finally admits that this is his first computer ever and that he was hoping I would teach him how to use these tools... and how to use a computer.

Some people really believe they can bullshit their way through life.
>>
>>54818985
How do you build up a resume worthy of an interview if you can't even FizzBuzz? Or do you just interview anyone?
>>
>>54819040
why
>>
File: 1438056526027.png (125 KB, 694x801) Image search: [Google]
1438056526027.png
125 KB, 694x801
>>54818205

>talking about people who can't fizzbuzz
>posted program will not fizzbuzz

2/10 made me reply
>>
File: 1464592801149.png (17 KB, 347x102) Image search: [Google]
1464592801149.png
17 KB, 347x102
>>54818419
The most computationally efficient way of doing a fizzbuzz.
>>
>>54818440
if {...}else if{...}else{...} structure does exist for a reason. Yes, in the fizzbuzz it does not change much
but producing quality code should be in your top 3 priorities at all time.
>>
fb = fn
(0, 0, _) -> "fizzbuzz"
(0, _, _) -> "fizz"
(_, 0, _) -> "buzz"
(_, _, n) -> n
end

fizzbuzz = fn n -> fb.(rem(n, 3), rem(n, 5), n) end

Enum.map(1..100, fizzbuzz)
>>
#include <stdio.h>

int main(void)
{
int i, fizz, buzz;
for(i=0; i<100;++i) {
fizz = i % 3;
buzz = i % 5;

if (!fizz || !buzz) {
if (!fizz) printf ("Fizz");
if (!buzz) printf ("Buzz");
printf ("\n");
} else printf ("%d\n", i);
}
return 0;
}
>>
>>54818419
This needs to go on one of those CS graduate pics.
>>
>>54818205
Fizzbuzz is a fucking meme designed to impress non-programmers. You don't ask for it in an interview because someone who can't do it simply wouldn't graduate in the first place.
>>
>>54818981

Yes it is.

>>54818889

That case you could just write FizzBuzz at 8.
>>
>>54818787

Line 12 in >>54818772 is where I test the case "i is not a multiple of either 3 or 5". I don't test 15 for "FizzBuzz" since that's already done by appending the 3 and the 5 cases if i happens to be a multiple of both.
>>
>he cant multiply two numbers recursively
>>
>>54818924
>ditch std
He shouldn't.
>>
>>54819118
If not fizz; print Fizz
>>
File: webdevs cant fizzbuzz.png (229 KB, 537x783) Image search: [Google]
webdevs cant fizzbuzz.png
229 KB, 537x783
>>54818205
>>
>>54818924
I prefer using the std:: over using a whole namespace or polluting my code with a local
using std
.
>>
>>54819154

>recursion

enjoy your mile long stack call, buddy
>>
>>54819120
Why? It work just fine?

Typical CS faggot, thinks he is great for coming up with some unnecessarily complicated way of doing something using superfluous functions like modulo arithmetic.
>>
>>54819078
I think it has to do with possibly printing stuff twice, but I'm not sure
>>
>>54818205
clever on the i%3 && i%5 but it's hard to read if you don't know C
>>
>>54819139
No it isn't.

>>> def f1(i): return i % 3 and i % 5
...
>>> def f2(i): return i % 15
...
>>> f1(3) == f2(3)
False
>>
>>54819204

For you special, make your fizzbuzz go up to even 1000, and you're going to need to do 10 times the work of someone who wrote efficient code
>>
>>54819172
whats wrong babby
>>
>>54819139
i%3 isn't the same as i%3==0. i%3 is an integer. he's doing (integer && integer) so it's checking whether either of the integers are 0, which would mean they divide evenly by either 3 or 5
>>
>>54819085
In pic there is no loop, so main will print "1\n" and exit (assuming the rest of main follows the same structure until k == 99 and returns after that). Remove the all of the "else"s and you've got yourself a fizzbuzz.

#include <cstdio>

int main()
{
int i = 0, j;
const char *buzzer[] = {NULL, "fizz", "buzz", "fizzbuzz"};

while(i++ < 100)
if(j = !(i%3)*1 + !(i%5)*2)
printf("%s\n", buzzer[j]);
else
printf("%i\n", i);

return 0;
}
>>
Maybe they never heard about Fizzbuzz? I didn't have that sort of a division game taught to us when I was a kid for example.

Now that I know it I don't think that there would be programmers who aren't capable of coding it desu.
>>
>>54819220

it works fine except \n should be put at the end. test it.
>>
>>54819228
Thanks
>>
>>54819189
>>54819162

i don't mean using std, i mean don't use std in the first place because it's crap.
>>
>>54818772
Dont initialize the variables in a for loop either.
>>
>>54819281
Yeah, someone pointed it out, here's a corrected version >>54818772
>>
>>54819311

why would you not initialize a variable in a for loop, then use it as a sentinel variable? It makes complete sense to do that

for (int i = 0; i < 100; i++)
{
//code increments i until exit
}
>>
I went to a top CS university and I doubt that more than 40% of my peers could write a fizzbuzz from scratch.
>>
I went to a top CS university and doubt more than 40% of my peers can do fizzbuzz.
>>
>>54819232
>implement an actual, non-"le funny smart xD" FizzBuzz
>print it into a source file's print statement/function call as if it were le funny smart
>>
I went to a top CS university and doubt more than 40% of students can fizzbuzz.
>>
>>54818889
It's not about multiplication, it's about their gcd (greatest common divisor). Since both 3 and 5 are prime their gcd is 3*5
>>
>>54819339
>>54819406
>>54819428
u ok dude?
>>
File: 1464395377969.jpg (31 KB, 287x325) Image search: [Google]
1464395377969.jpg
31 KB, 287x325
>>54819232
He think I type it by hand. This is why vim and copy & paste were invented.

Kill yourself and your unnecessary CS obfuscation. Intellectual masturbation that is useless in the real world. Fucking autist.
>>
I was asked to write, in paper, what the python code "range(3)" meant... I had used range() many times, but didn't remember what it did, so I first thought it would be [1, 2, 3]. then I remembered it also included 0... this confused me even more, and ended writing [0, 1, 2, 3].
of course, I could have replied by analyzing it logically: range(n) is usually used to get n numbers, starting from 0... ie, up to n-1

the tl;dr is: distractions and nervousness can fuck you, which is why fizzbuzz is not only about code.
>>
some people might not known about/use/give importance to the modulus operator (%). Try doing it without it.
>>
what is a fizzbuzz
>>
>>54819504
lots of things work like that. like in most languages if they have a random(x) function it returns something from 0 to x-1
>>
>>54819490
Oh boy, here comes the self-taught programmer who tried to reinvent the wheel until a CS grad came in and said "oh, this is a use case for <algorithm>!" in O(1) time
>>
>>54819231
>>54819258

If we are talking about integers (and we are) then (i % 3 && i % 5) is not equivalent to (i % 15).

Do I really need to prove this point?
The modulo operator defines a ring, so let's look at the residue class of "mod 15":
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14

Now for each of that numbers let's look at the residue classes of "mod 3" and "mod 5", written in parenthesis:
0 (0,0)
1 (1,1)
2 (2,2)
3 (0,3)
4 (1,4)
5 (2,0)
6 (0,1)
7 (1,2)
8 (2,3)
9 (0,4)
10 (1,0)
11 (2,1)
12 (0,2)
13 (1,3)
14 (2,4)


As you see, there is no value x between 0 and "0 + n*15" with the property of being 0 for "x mod 3" and "x mod 5".
>>
>>54819428
I'm pretty sure you're lying.
>>
>>54819179
Webdevs really are trash, fuck.
>>
File: 1464109194488.jpg (54 KB, 600x867) Image search: [Google]
1464109194488.jpg
54 KB, 600x867
>>54819548
OBFUSCATION

When is the last time that has happened in real day to day code?

I train CS grads all the time and the first thing we have to teach them is to stop trying to overcomplicate everything. Just fucking solve the problem and move on.
>>
I heard of a dude who got a job programming, like so:
>So, applicant, do you know how to program?
>Eh... y-yes...
>What lanugage?
> Uh, C++?
>You're hired!
Applicant then went to a technical bookstore and bought a "learning C++" book
>>
>>54819619
spotted the pythonista
>>
>>54819647
Sounds like the story of how Bill Gates supposedly sold DOS to, what, IBM, without having a single line of code for it actually written
>>
>>54819595

Ah well, now I see your point:

OP did a check so each number that isn't a fizz or a buzz remains..

I stand corrected.

But nevertheless this is a sub-par way of doing it, since you double check. A simple boolean which gets TRUE for i%3 or i%5 would halve the nr. or modulo comparisons (and mod is expensive)..
>>
>>54819673
Or some other OS that he was supposed to make, of course he didn't sell DOS lel
>>
>>54819659
Distilled autism
>>
>>54819619
Oh I see
>>
File: 1464623600038.jpg (98 KB, 960x638) Image search: [Google]
1464623600038.jpg
98 KB, 960x638
>>
>>54819738
Goddamn it, you caught the Brazilian in the thread, my fucking sides
>>
A[I]←1+I←(0⍷A)/⍳⍴A←('FIZZBUZZ' 'FIZZ’ 'BUZZ' 0)[2⊥¨×(⊂3 5)|¨1+⍳100]
>>
get on my level scrubs

++++++++++[>++++++++++<-]>>++++++++++>->>>>>>>>>>>>>>>>-->+++++++[->++
++++++++<]>[->+>+>+>+<<<<]+++>>+++>>>++++++++[-<++++<++++<++++>>>]++++
+[-<++++<++++>>]>>-->++++++[->+++++++++++<]>[->+>+>+>+<<<<]+++++>>+>++
++++>++++++>++++++++[-<++++<++++<++++>>>]++++++[-<+++<+++<+++>>>]>>-->
---+[-<+]-<[+[->+]-<<->>>+>[-]++[-->++]-->+++[---++[--<++]---->>-<+>[+
+++[----<++++]--[>]++[-->++]--<]>++[--+[-<+]->>[-]+++++[---->++++]-->[
->+<]>>[.>]++[-->++]]-->+++]---+[-<+]->>-[+>>>+[-<+]->>>++++++++++<<[-
>+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>
+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->+++
+++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]+[-<+]->>]+[-]<<<.>>>+[
-<+]-<<]
>>
>>54819951
Was about to say, someone should make fizzbuzz in brainfuck, beat me to it.
>>
>>54819738
>World
>>
>>54818772
I'm learning C at the moment. Can someone tell me the meaning of

++i

and

std::cout

or is that just c++ shit?
>>
>>54818979
crap meant lcm
>>
>>54818205
Definitly not a meme\
>CV in .docx
>10 years experience in php
>has classes named half in english, half in other language
>obviouse copy pasta, pieces could be googled
yeah they do
>>
>>54820039
>I'm learning C at the moment. Can someone tell me the meaning of
>++i
http://www.c4learn.com/c-programming/c-increment-operator/

>std::cout
C++
>>
>>54820087
Thank you. I'm sure the ++i thing is far ahead of where I am in my learning, but maybe it'll stick better if I learn it twice.
>>
>>54819338
he is just a c fag afraid of new things in C++
>>
>>54820108
i++ you learn it like in the first week or whenever they teach you for loops.
>>
>>54820108
++i literally just means increment a value and return the result.
>>
>>54820244
++i means add the value of variable "i" to itself, but yes what you said is pretty much close
>>
>>54820294
>add the value of variable "i" to itself

the fuck.
>>
>>54818205
for 1..100 { if $_ %% 3 { if $_ %% 5 { say "FizzBuzz"; } else { say "Fizz"; } } elsif $_ %% 5 { say "Buzz"; } else { .say; } }
>>
>>54820294
no it doesn't. that would be i += i
>>
>>54820352
Are you sure? I've used "var = var++" in a while loop and it incremented just fine.
>>
>>54819820
>>54819951
Fucking hell. What the actual fuck is going on here?
>>
>>54818205
This is why you only hire competitive programmers.
>already work in team
>know their shit
Experience comes naturally, only brains matter.
>>
>>54820294
>++i means add the value of variable "i" to itself

absolutely not, ++i means increment the value of i by 1, and i++ means the same thing, but it does any comparison first before incrementing. So ++i will increase by 1 and then compare, i++ will compare, then increase by 1
>>
>>54820039
++i increments i before the operation, i++ increments it after, normally it doesn't matter which order you do it in unless you assign it to something

int i = 0;
i++; /* i is 1 */
int j = 0;
++j; /* j is 1 */

int k, l = 0;
int z = 10;
z = k++; /* z = 0, k = 1 */
z = ++l /* z = 1, l = 1 */


Hope that makes sense
>>
>>54820440
missed a semi colon at the end, sorry
>>
>>54820390
"add the value of variable "i" to itself" would mean i = i + i. That is achieved with the += operator, not with the ++ operator which adds 1 to i.

>var = var++

redundant code
var++ alone does the thing
>>
>>54820390
"Increment X" means ADD ONE TO X, not ADD X TO X.
>>
File: 1461386922706.png (321 KB, 480x650) Image search: [Google]
1461386922706.png
321 KB, 480x650
>>54819190
>he can't make his functions strict
>>
>>54818914
>limiting your fizzbuzz to 100 when nobody asked you that
>>
>>54820556
Now you're just being silly
>>
>>54820075
As a french dev, I mix English and French all the time in my code because some concepts like design patterns are inherently English while business objects are French.
It's a bit shcizophrenic.
>>
>>54820039

std::cout is C++ shit.

++i is the same as i++ in the sense that both are shorthand for
i = i + 1;
, i.e., i is incremented by 1. If you aren't familiar with i++, that's probably the way you're going to be taught first.

The difference, assuming i equals 5, comes when you try to do

a = ++i;
or
a = i++;

The former will increment i and then return its new value, meaning a gets assigned 6, while the latter will copy i's value somewhere else, increment i, then return the old value, meaning a will be assigned 5.

This doesn't make much of a difference now, but in C++ you will loop over stuff bigger than a mere 4 byte int, meaning ++i will avoid a potentially large copy and thus improve performance (though this may be automatically optimized by your compiler anyway).

>inb4 C++11 ranged for loops, please guys
>>
>>54820440
this is right.
A more usefuls example would be like (ignore fucked printf use) :

int i = 0;
printf (i++); // will print "0" and increment i to 1
printf (i); // will print "1"
printf (++i); // will increment i to 2 and print "2"
>>
>>54819619
Is it even possible to summon that card. Don't you need one synchro receiver + non receiver monster which would put the minimum level at 2 instead of 1.
>>
>>54820592
I'm from Brazil and I have everything in English, from OS display language to keyboard, so I can name my variables purely in English when I code without having to switch the language I'm thinking in.

Sometimes I wonder if my professors won't think my code is copy-pasted from the Internet, though, since my usage of English in programming includes my school assignments. Luckily they have tools to verify that.
>>
>>54819172
Its because false is a zero or less.
>>
>>54818205
Without looking up the answer, i'll try the test now.

[spoiler]i have my final programing exam this semester tomorrow[spoiler]
>>
>>54820796
If you try to understand OP's code, be aware that one isn't completely correct, it doesn't print 100, and the newlining is a bit fucked.

This one is correct. >>54818772
>>
>>54819125
This. I've never encountered Fizzbuzz during my interviews.
>>
>>54820748
It might be correct but your code should say what it's doing/have helpful variable names, saying if not fizz and then printing fizz is a bit illogical
>>
>>54818772
Why don't you use "void main()" instead of using "int main()" and "return 0;"? Is that just common practice?
>>
>>54820415
This.
>>
>>54819125
>wouldn't graduate in the first place.
You can't even imagine how many people pay for graduation/ask other people to do their tasks.
>>
>>54820954
It is in C, not sure about C++, because you can return other numbers for error codes
>>
>>54819118

>!

wtf?
>>
>>54821056
You don't know what the ! operator does?
>>
>>54818205
>complains about fizz buzz
>fails at fizz buzz
never disappoint /g/
>>
>>54820954
Proper deceleration for main returns an int type
>>
>>54820748
false is 0 anon, not negative
>>
>>54820839
>it doesn't print 100
by 100 you mean "Buzz", right?
>>
>>54820954
Returning 0 in main in c++ means the program exited normally, if i recall correctly.
>>
File: fizzbuzzfire.jpg (103 KB, 1000x930) Image search: [Google]
fizzbuzzfire.jpg
103 KB, 1000x930
>He wasn't here
https://css-tricks.com/tales-of-a-non-unicorn-a-story-about-the-trouble-with-job-titles-and-descriptions/
>>
>>54820954

When the OS starts your program it expects a return number upon termination to indicate that it executed correctly, 0 is the "correct execution" number...

...Or so I heard, I never really thought about why making main() return void would be better.

Word has it that the language standards (both C and C++) require that main() returns an int, and that it is some compilers that allow it to be void. I guess it looks more didactic not having to worry about a return value when one's just trying to make sense out of Hello World code.
>>
>>54821300
someone post it's an abstract kind of fizzbuzz please
>>
File: ss+(2016-05-30+at+11.17.30).png (33 KB, 968x903) Image search: [Google]
ss+(2016-05-30+at+11.17.30).png
33 KB, 968x903
send help my computer started beeping
program evan fizzbuzz [
declare i real;
declare fizzcount real;
declare buzzcount real;
declare b real;

let i = 0;
let fizzcount = 0;
let buzzcount = 0;

while i < 100
[
let i = i + 1;
let b = 0;
if fizzcount > 2 [
print "fizz";
let fizzcount = 0;
let b = 3;
]

if buzzcount > 4 [
print "buzz";
let buzzcount = 0;
let b = 5;
]

if b < 1 [
print i;
let fizzcount = fizzcount + 1;
let buzzcount = buzzcount + 1;
]
print "\n";
]
]
>>
>>54821223
Yes, sorry
>>
>>54821315

Don't know what language that is, but try using integer instead of real
>>
File: daily programming thread.png (137 KB, 590x610) Image search: [Google]
daily programming thread.png
137 KB, 590x610
>>54820995
>>54821254
>>54821310
Neo /g/, everyone
>>
#include <iostream>
#include <map>

using namespace std;

void fizzbuzz(uint64_t start, uint64_t end, const map<uint64_t, string>&& fizzes)
{
uint64_t& i = start;
std::string result;
while (i <= end)
{
result.clear();
for(auto pair : fizzes)
{
if (i % pair.first == 0)
{
result.append(pair.second);
}
}

if (result.empty())
cout << i << endl;
else
{
result[0] = toupper(result[0]);
cout << result << endl;
}
++i;
}

}
int main(int argc, const char * argv[])
{
fizzbuzz(1, 100, { {3, "fizz" }, {5, "buzz" } } );
return 0;
}
>>
>>54821358
language doesn't have integers
>>
>>54821310
C++ always return int. In C, in non-OS environments you can have implementation defined main s
>>
>>54818424
Moron witnessed.
>>
>>54818981

lolololol
>>
>>54819125
you dont even know how many cs or software engineer grads cant program for shit.
fizzbuzzs is a very valid question to ask.
even simple things like calculating the fibonacci sequence, which is baby tier 5th grade math is way above many peoples heads.
>>
#include <iostream>
#include <thread>
#include <memory>
#include <future>
#include <vector>
#include <string>

std::vector<std::string> doFizzBuzz(uint64_t start, uint64_t end)
{
std::vector<std::string> result;
result.reserve(end - start + 1);

for (; start <= end; ++start)
{
std::string str;
if (start % 3 == 0)
str += "fizz";
if (start % 5 == 0)
str += "buzz";

if (str.empty())
str = std::to_string(start);
else
str[0] = toupper(str[0]);

result.push_back(std::move(str));
}
return result;
}

void parallelFizzbuzz(uint64_t start, uint64_t end)
{
auto threadNum = std::thread::hardware_concurrency();
std::vector<std::future<std::vector<std::string>>> futures;

uint64_t numsPerThread = (end - start) / threadNum;
auto remainder = (end - start) % threadNum;
auto lastEnding = start;

for(auto i = 0; i < threadNum; ++i)
{
auto begin = lastEnding;
auto ending = begin + numsPerThread;

if (remainder)
{
++ending;
--remainder;
}
lastEnding = ending;

futures.push_back(std::async(std::launch::async, doFizzBuzz, begin, ending));
}

for(auto&& future : futures)
{
auto&& vec = future.get();
for (auto&& string : vec)
puts(string.c_str());
}
}

int main(int argc, const char * argv[])
{
parallelFizzbuzz(1, 1000000);
}


Do a stupider implementation, I dare you.
>>
>>54821396
Oooh, thanks, didn't know that
>>
>>54821500

>auto&&

Fuck rvalue references, still trying to wrap my head around them
>>
>>54818419
kek
>>
>>54818205
So to summarize, yes. I'm almost amazed you managed to make yourself above all those other engineers, then failed so spectacularly.
0. You start off by printing a newline before any numbers
1. Newlines are not printed after fizz
2. 2 newlines are printed in the case of FizzBuzz (for which you print i instead) or Buzz
2. Only goes up to 99
3. You print the number when you should print FizzBuzz
4. You should probably return 1 because your code is garbage and will always fail
>>
>>54821524
I understood them perfectly about a year ago.

Now I have a webdev job.
The brain rot is real. I can feel myself becoming much, much dumber and it terrifies me.
>>
>>54821530
>can't count to 5
>>
>>54821530
>4. You should probably return 1 because your code is garbage and will always fail

kek
>>
I work at a company that almost exclusively uses java but I'm planning on writing a component or two in an old language out of spite.

program myMain

implicit none

integer :: i

i = 0

do while (i < 100)

if ( mod(i, 15) == 0 ) then
print*, 'FizzBuzz'
elseif ( mod(i,3) == 0 ) then
print*, 'Buzz'
elseif ( mod(i,5) == 0 ) then
print*, 'Buzz'
else
print*, i
endif

i = i + 1
end do

END program myMain
>>
>>54821800

Misunderstood the question, I think I got it this time
var fizz;
var buzz;
for (var i=1; i<=100; i++){
if(i % 3 === 0){
fizz = true;
}
else{
fizz = false;
}
if(i % 5 === 0){
buzz = true;
}
else{
buzz = false;
}
if(fizz === true && buzz !== true){
console.log("Fizz");
}
else if(fizz !== true && buzz === true){
console.log("Buzz");
}
else if(fizz === true && buzz === true){
console.log("FizzBuzz");
}
else{
console.log(i);
}
}
>>
>>54821933
kek
>>
>>54821951
Probably should have read through the question more carefully, missed the part about printing numbers that aren't divisible by either 3 or 5
>>
>>54818205
Modulus 15 you retard
>>
>>54821933
wtf is this?
>>
>>54822020
Read the code again, or the earlier part of the rest of the thread
>>

.data
fizz: .asciiz "Fizz"
buzz: .asciiz "Buzz"
endl: .asciiz "\n"
.text
main:
li $s0, 0
li $s1, 100
li $s2, 0
li $s3, 0

li $t0, 3
li $t1, 5


addi $s0, $0, 1

for:
rem $s2, $s0, $t0
bne $s2, $0, if1
li $v0, 4
la $a0, fizz
syscall

if1:
rem $s3, $s0, $t1
bne $s3, $0, if2
li $v0, 4
la $a0, buzz
syscall

if2:
beq $s2, $0, cout
bne $s3, $0, else
cout: li $v0, 4
la $a0, endl
syscall
j end

else:
li $v0, 1
move $a0, $s0
syscall
li $v0, 4
la $a0, endl
syscall

end:
addi $s0, $s0, 1
ble $s0, $s1, for


li $v0, 10
syscall

>>
#include <stdio.h>

int main(){
int number;
for (int i = 1; i <= 100; i++) {
number = 1;
if (!(i%3)) {
printf("fizz");
number = 0;
}
if (!(i%5)) {
printf("buzz");
number = 0;
}
if (number) {
printf("%i", i);
}
printf("\n");
}
return 1;
}
>>
fastest fizzbuzz reporting in

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

int main()
{
int max = 1000;
int b_size = 1024*1024; // what's the length of a fizzbuzz of n length /sci/ ?

char* b = (char*)malloc(b_size);
memset(b, 0, b_size);

for (int i = 1; i < max; i++)
{
if(i % 3 == 0)
sprintf(b + strlen(b), "Fizz");
if(i % 5 == 0)
sprintf(b + strlen(b), "Buzz");
if(i % 3 && i % 5)
sprintf(b + strlen(b), "%d", i);

sprintf(b + strlen(b), "\n");
}

fwrite(b, strlen(b), 1, stdout);
free(b);
return 0;
}


>>
>>54821214
My bad, forgot.
>>
>>54822140
>return 1;
well shit
>>
>>54819179
>convert timestamp into seconds
How mentally retarded are they to not know how to program simple math?
>>
>>54818205
>Also, post your fizzbuzz code in whatever language you like.

Haven't tested, don't have my emulator image handy.

      mov $1, r0 / file number for stdout
mov $1, r5 / initialize counter (r5) to 1
loop: clr r1 / flag for if we printed fizz
mov r5, r3 / copy counter into r2:r3
clr r2
div $3, r2 / r2, r3 = x/3, x%3
tst r3
bnz 0f
sys write; fizz; 4
inc r1
0: mov r5, r3 / as above, test 5 for buzz
clr r2
div $5, r2
tst r4
bnz 0f
sys write; buzz; 4
br skip
0: tst r1
bnz skip
/ print counter as a number. skipped if fizz or buzz was printed.
mov nbuf+6, r1 / pointer to end of nbuf
mov r5, r3 / load counter into r2:r3
prtl: clr r2 / loop for conversion to decimal
div $10., r2 / r2, r3 = x/10, x%10
add r3, 60 / add '0' char to get a digit
mov r3, -(r1) / load digit into buffer
tst r2 / if x/10 is zero
bz endl / exit the loop
mov r2, r3 / load x/10 into r2:r3
br prtl
endl:
mov nbuf+6, r2 / pointer to end of buffer
mov r1, 0f / load number into write pointer
sub r2, r1 / number of chars to write
mov r2, 1f / load number of chars into write argument
sys write; 0:..; 1:..
skip:
sys write; lf; 1
inc r5
br start
nbuf: ......
fizz: <Fizz>
buzz: <Buzz>
lf: <\n>
>>
Not a programmer but why do you need the "FizzBuzz" clause? If mod 3 = 0 then it writes Fizz, if mod 5 = 0 then it writes Buzz, but for example 15, it should write both Fizz and Buzz, thus making FizzBuzz. Yeah I know about new lines and such, but still.
>>
>>54818205
Fucking retards can't even FizzBuzz with a neural network

http://joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/
>>
>>54822180
That's true, real programmers don't use a separate if-then for fizzbuzz.
>>
>>54818205
>>54822155

Just realized that I need to reset r0 every time because it gets set to the write return status. Also added a proper exit once it passes 65535.

      mov $1, r5 / initialize counter (r5) to 1
loop: clr r1 / flag for if we printed fizz
mov r5, r3 / copy counter into r2:r3
clr r2
div $3, r2 / r2, r3 = x/3, x%3
tst r3
bnz 0f
mov $1, r0 / file number for stdout
sys write; fizz; 4
inc r1
0: mov r5, r3 / as above, test 5 for buzz
clr r2
div $5, r2
tst r4
bnz 0f
mov $1, r0 / file number for stdout
sys write; buzz; 4
br skip
0: tst r1
bnz skip
/ print counter as a number. skipped if fizz or buzz was printed.
mov nbuf+6, r1 / pointer to end of nbuf
mov r5, r3 / load counter into r2:r3
prtl: clr r2 / loop for conversion to decimal
div $10., r2 / r2, r3 = x/10, x%10
add r3, 60 / add '0' char to get a digit
mov r3, -(r1) / load digit into buffer
tst r2 / if x/10 is zero
bz endl / exit the loop
mov r2, r3 / load x/10 into r2:r3
br prtl
endl:
mov nbuf+6, r2 / pointer to end of buffer
mov r1, 0f / load number into write pointer
sub r2, r1 / number of chars to write
mov r2, 1f / load number of chars into write argument
mov $1, r0 / file number for stdout
sys write; 0:..; 1:..
skip:
mov $1, r0 / file number for stdout
sys write; lf; 1
inc r5
bnc start / if we haven't overflowed 65535, do loop, otherwise...
clr r0
sys exit
nbuf: ......
fizz: <Fizz>
buzz: <Buzz>
lf: <\n>
>>
>>54821690
77 or 90?
>>
     #include <stdio.h>

#define BUZZZ int
#define FIZZZ printf
#define FIZZ for
#define BUZZ if
#define BZZ "\n"
#define FUZZ return
#define FIZZBUZZZ main
#define FIZZZBUZZ "%d"
#define FIZZBUZZ else
#define BUZZFIZZ 3
#define FIZZFIZZ 5
#define BUZZBUZZ 100

BUZZZ FIZZBUZZZ(){BUZZZ fizzbuzz;FIZZ(fizzbuzz=BUZZFIZZ/BUZZFIZZ;fizzbuzz<=BUZZBUZZ;++fizzbuzz){BUZZ(fizzbuzz%(BUZZFIZZ*FIZZFIZZ)==BUZZBUZZ-BUZZBUZZ)FIZZZ("FIZZBUZZ");FIZZBUZZ BUZZ(fizzbuzz%BUZZFIZZ==FIZZFIZZ-FIZZFIZZ)FIZZZ("FIZZ");FIZZBUZZ BUZZ(fizzbuzz%FIZZFIZZ==BUZZFIZZ-BUZZFIZZ)FIZZZ("BUZZ");FIZZBUZZ FIZZZ(FIZZZBUZZ,fizzbuzz);FIZZZ(BZZ);}FUZZ BUZZBUZZ-fizzbuzz;}
>>
>>54822180
This anon knows his shit.

>b-but muh readability
>>
>>54822237

I'd prefer 77 because it's cooler, but 90 has more features.
>>
>>54822270
"Cooler" as in? Code looks cooler?
>>
>>54822295
Less hot.
>>
#include <cstdlib>
#include <iostream>

using namespace std;

void fizzbuzz(int n) {

if (n > 100) {
return;
}

if (n % 3 == 0) { cout << "Fizz" << endl; }
else if (n % 5 == 0) { cout << "Buzz" << endl; }
else if (n % 15 == 0) { cout << "FizzBuzz" << endl; }
else { cout << n << endl; }

fizzbuzz(n + 1);
}

int main() {

fizzbuzz(1);

return 0;
}
>>
(define fizzbuzz
(lambda (max)
(define fb
(lambda (n)
(let ([m3 (zero? (modulo n 3))]
[m5 (zero? (modulo n 5))])
(cond [(and m3 m5) "fizzbuzz"]
[m3 "fizz"]
[m5 "buzz"]
[else n]))))
(let loop ([n 1])
(when (<= n max)
(display (fb n))
(newline)
(loop (add1 n))))))
>>
>>54822295

Cooler as in "If I'm going to use a language known for being a dinosaur I may as well use Triassic over Cretaceous"

Also, it was a lot nicer than I'd expected. I could get used to it definitely. I have no idea why everyone hates it so much.
>>
>>54822257
kek
>>
public class FizzBuzz {
public static void main(String[] args) {

for (int i = 1; i < 101; i++){
if (i % 15 == 0) System.out.println("FizzBuzz");
else if (i % 3 == 0) System.out.println("Fizz");
else if (i % 5 == 0) System.out.println("Buzz");
else System.out.println(i);
}
}
}


anything to improve? Other than >java
>>
File: 1444671604389.jpg (24 KB, 292x219) Image search: [Google]
1444671604389.jpg
24 KB, 292x219
>>54822325
>>
>>54821563
>The brain rot is real. I can feel myself becoming much, much dumber and it terrifies me.
Are you over 30?
>>
Very easy to do with Python.

_ = list(map(lambda x: print(x), ('fizz' if 3 in x else 'buzz' if 6 in x else 'fizzbuzz' if 8 in x else i + 1 for i, x in enumerate([list(map(lambda x: x[1] + 5 if (x[0] + 1) % 5 is 0 else x[1], enumerate(map(lambda x: x[1] + 2 if (x[0] + 1) % 3 is 0 else x[1], enumerate([0] * i + [1] + [0] * (100 - i)))))) for i in range(100)]))))
>>
>>54822483
23.
It's not about me, it's about the technologies I have to deal with. I used to be pretty good with C++ (ignore the shitty joke program) but not anymore since I had to write PHP.
It's like a different world. In C++, you really optimize the shit out of your code by abiding to rules and giving various low-level hints to the compiler to make sure you copy as little as possible.

And PHP... Oh god. You just say "hurr hurr do the thing" and it takes 150 Milliseconds to run what should take 10 at most.
I hate this.
>>
Here's one in SQL.

SELECT
CASE
WHEN mod(rownum,3)=0
AND mod(rownum,5) =0
THEN 'FizzBuzz'
WHEN mod(rownum,3)=0
THEN 'Fizz'
WHEN mod(rownum,5)=0
THEN 'Buzz'
ELSE TO_CHAR(rownum)
END
FROM dual
CONNECT BY level < 100;
>>
>>54822325
It will never make it to n % 15, Anon.
>>
>>54818419
>putting parenthesis around the string
that's not "proper" python
>>
>>54822541

do some C++ side programming as a hobby you will feel way better.
>>
>>54822618
print is a function, what are you on about?
>>
>>54822618

it's python 3.x in which print is a proper funciton
>>
>>54822577
>>54822471
>>54822325
#include <cstdlib>
#include <iostream>

using namespace std;

void fizzbuzz(int n) {

if (n > 100) {
return;
}

if (n % 15 == 0) { cout << "FizzBuzz" << endl; }
else if (n % 3 == 0) { cout << "Fizz" << endl; }
else if (n % 5 == 0) { cout << "Buzz" << endl; }
else { cout << n << endl; }

fizzbuzz(n + 1);
}

int main() {

fizzbuzz(1);

return 0;
}


oops, missed that
>>
>>54822180
>Yeah I know about new lines and such, but still.

If you going to do that, you need to add newlines retroactively, which adds additional complexity.
>>
>>54822625
I just feel dead when I come home. I can't see programs anymore and I can't enjoy anything else.

I'll find a better job eventually. No more web dev. It will be glorious. It's what I live for.
>>
>>54822659
How'd you get there in the first place? Were you just looking for any job at that point?
>>
>>54818205
Honestly, I'd rather they be unable to fizzbuzz at all than submit some of the solutions I've seen.
>>
>>54822659

good luck man

i had the same problem but this project rekindled my interest and now i try to find some time to do some programming the way i enjoy it, in case you find it interesting as well: https://handmadehero.org/
>>
>>54819056
> JavaScript == Java
Nice. Hope idiocy doesn't run in the family.
>>
File: 1452247223586.jpg (4 KB, 176x100) Image search: [Google]
1452247223586.jpg
4 KB, 176x100
>>54822648
Thanks for coming in, we'll give you a call letting you know our decision
>>
>>54822677
In Germany, we have this fucked up apprenticeship system where nobody will employ you (well, for a fair wage) if you didn't finish an apprenticeship.

The companies are happy with this, of course: Some idiot you can pay wages that even a turkish cleaner woman would deny who can't leave for three years unless he wants to repeat the same cycle in a different slave-house.

And guess what kind of work these companies have? Nothing reasonable. It's basically only webdev, which is ALWAYS PHP + jQuery (nothing else, and no vanilla) + some fucked up homebrew bootstrap fork where you need to include 5 different css files in every new project that all override each other and are bugged as hell because incompetent faggots actually edit the compiled css instead of the scss or less source, since German developers are so incompetent that they can't understand what's wrong with those approaches.

According to classmates at trade school there is also Microsoft dynamics, but I'd rather kill myself than have that show up in my CV.
>>
>>54818205

I used to ask fizzbuzz but now I make people write left-pad

Or I'll give them the alternating iterators problem, people go full retarded with that one
>>
>>54822888
>alternating iterators problem

what is this?
>>
>>54822908

An iterator has two methods, hasNext() and next(). hasNext() tells you whether or not you have any more elements left in your iterator, and next() gives you the next one and moves the cursor over. If you call next() without calling hasNext() first then Donald Knuth himself will kill you and fuck your mother in a futile attempt at a do-over.

Write an implementation of the iterator interface that takes two backing iterators and returns their results from next() in an alternating fashion. So if you have two iterators that contain the following elements:

A: 1, 6, 9, 3
B: 4, 2

Then calling next() repeatedly on the iterator you implement should return

=> 1, 4, 6, 2, 9, 3
>>
>>54822958

sounds simple enough but i can see myself making a retarded mistake at first
>>
>>54822508
Possible with less lambdas:
[
print(x) for x in (
'fizz' if 3 in x else 'buzz' if 6 in x else 'fizzbuzz' if 8 in x else i + 1
for i, x in enumerate(
list(
map(
lambda x: x[1] + 5 * ((x[0] + 1) % 5 == 0) + 2 * ((x[0] + 1) % 3 == 0),
enumerate(
[0] * i + [1] + [0] * (100 - i)
)
)
)
for i in range(100)
)
)
]
>>
>>54819179
>womyn in code
>>
>>54822958
Look how beautiful and elegant it is in the most beautiful language:
def alternating_iter(a, b):
while True:
try:
yield next(a)
a, b = b, a
except StopIteration:
a, b = b, a
yield next(a)

for x in alternating_iter(iter([4, 2]), iter([1, 6, 9, 3])):
print(x)
>>
>>54822888
leftpad is just you're given a length the string has to be and if it's less than that you pad the left side with spaces?

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

char *leftpad(char *string, int length);

int main()
{
char *a = "I hate niggers";
char *new = leftpad(a,30);

char *b = "Testing testing";
char *new2 = leftpad(b,5);

char *c = "MAGA";
char *new3 = leftpad(c,5);

printf("%s\n",new);
printf("%s\n",new2);
printf("%s\n",new3);
return 0;
}

char *leftpad(char *string, int length)
{
int s = strlen(string);

if (s > length)
return string;

char *result = malloc(length);

for (int i = 0; i < length - s; i++)
result[i] = ' ';

strcat(result,string);
return result;
}


How's this? I probably fucked up some null terminators in there but it seems to work
>>
>>54823256
>those memory leaks

we'll call you
>>
>>54823256
>ignores null terminator
>a function that may or may not allocate memory inside
you should stop programming
>>
>>54822888
>left-pad
You mean, you make them write the rjust method that Python strings already have? Barbaric.

>>> 'oice'.rjust(15, 'n')
'nnnnnnnnnnnoice'
>>
>>54819103
i wonder how much slower this is than usual loop
>>
>>54823249

>Look how beautiful and elegant it is in the most beautiful language

You mean Ruby?

A = [1, 6, 9, 3]
B = [4, 2]
A.zip(B).flatten.compact # output: [1, 4, 6, 2, 9, 3 ]
>>
>>54823403

Ah well, might as well do "leftpad" in Ruby:

"something".rjust(20, " ")  # width 20, fill up with blanks
>>
>>54823283
>>54823311
is this better?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char *leftpad(char *string, int length);

int main()
{
char *a = "I hate niggers";
char *new = leftpad(a,30);

char *b = "Testing testing";
char *new2 = leftpad(b,5);

char *c = "MAGA";
char *new3 = leftpad(c,5);

printf("%s\n",new);
printf("%s\n",new2);
printf("%s\n",new3);

free(new);
free(new2);
free(new3);

return 0;
}

char *leftpad(char *string, int length)
{
char *result = malloc(length+1);
int s = strlen(string);

if (s > length)
return strcpy(result,string);

for (int i = 0; i < length - s; i++)
result[i] = ' ';

strcat(result,string);
result[length] = '\0';

return result;
}
>>
>>54823403
Does this work on iterators, too? Like, what if those are not arrays (trivial case) but some functions that retrieve paginated data from some online resource.
>>
>>54823512
no. it is even worse
>>
>>54819738

I like how women.h doesn't include any knowledge or power.
>>
>>54823485

In this case I would ask you to write rjust
>>
I probably couldn't do Fizzbuzz, yet I literally just got a b.s. in computer science 16 days ago. I still can't believe I made it. But now I'm going to be a pilot in the Navy, so life is pretty good atm.

But go ahead, keep pretending knowing how to do Fizzbuzz means your more prepared for the real world.
>>
>>54823512
It's better practise if you return null in case of a failure; source string being longer than the given parameter as in your code. Could also declare string const.
>>
>>54823591
>implying knowing how to pilot makes you more prepared for the real world
BRB making you obsolete with better drone AI.
>>
>>54823548

I'm not sure, actually..

Ruby lets you do a lot of shit, but not everything. Depends on the specific example..
>>
>>54823590

Clever..

But it's hard to fuck up ruby. You relly have to try.
>>
File: 1411583334699.gif (2 MB, 300x300) Image search: [Google]
1411583334699.gif
2 MB, 300x300
>>54818276
>>
>>54818276
OP failed though that's the funny part
>>
>>54819738
kek
>>
>>54822571
fuck SQL
>>
>>54818205
Given that I have never coded before picking up and going through a python book since last week, I'd say that's not a good measurement.

number=0
while number<=100:
if number%3==0 and number%5==0:
print("fizzbuzz")
number=number+1
elif number%3==0:
print("fizz")
number=number+1
elif number%5==0:
print("buzz")
number=number+1
else:
print(number)
number=number+1
>>
>>54823590
Well, in Python it would be as simple as:

lambda string, length, padding: (padding * ((length - len(string)) // len(padding)))[0:length - len(string)] + string


Or, as it would be written by the junior developer, not familiar with supreme one-liners of euphoria:

def left_pad(string, length, padding):
missing_length = length - len(string)
pad = padding * (missing_length // len(padding))
pad = pad[0:missing_length]
return pad + string
>>
>>54823881
or I suppose it would be
number=0
while number<=100:
if number%3==0 and number%5==0:
print("fizzbuzz")
elif number%3==0:
print("fizz")
elif number%5==0:
print("buzz")
else:
print(number)
number=number+1
>>
>>54823881
0%3==0

you've failed
>>
>>54819595
But (i % 3 || i % 5) would be equivalent to (i % 15). Just sayin'.
>>
List<int> fizzy = Enumerable.Range(1, 100).ToList();

fizzy.ForEach(x => { if (x % 15 == 0) { Response.Write("FizzBuzz"); } else if (x % 3 == 0) { Response.Write("Fizz"); } else if (x % 5 == 0) { Response.Write("Buzz"); } else { Response.Write(x); } });
>>
 
fn main() {
for num in 1..101 {
let line = match (num % 3, num % 5) {
(0, 0) => "FizzBuzz".to_string(),
(0, _) => "Fizz".to_string(),
(_, 0) => "Buzz".to_string(),
(_, _) => num.to_string()
};
println!("{}", line);
}
}
>>
>>54823881
1) The initial value of number should be 1
2) "number=number+1" can be simplified to "number+=1" and should only appear once at the bottom of the loop.
>>
https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

>implying this isn't the best FizzBuzz version
>>
>>54818869
doesnt print buzz for 100 though
>>
>>54819338

Don't listen to him, he is a fucking idiot.
>>
>>54821300

http://notlaura.com/

Oh dear lord, this ingrate is TEACHING OTHERS? On fucking what?
>>
Anyone want more puzzles?
>>
let lcm a b =
let rec gcd a = function
| 0 -> a
| b -> gcd b (a mod b) in
let d = gcd a b in
a * (b / d)
let print_string oc s = Printf.fprintf oc "%s" s
let print_endline oc s =
print_string oc s;
print_string oc "\n"
let print_newline oc = print_endline oc ""
let generate oc rads start length =
let lcm = List.fold_left (fun accu (rad, _) -> lcm accu rad) 1 rads in
let last = start + length - 1 in
let print_step i =
if i = 0 then
print_string oc " let rec step_0 n ="
else
Printf.fprintf oc " and step_%d n =" i;
print_newline oc;
let indices = List.filter (fun (r, _) -> i mod r = 0) rads in
begin
match indices with
| [] ->
print_endline oc " Printf.printf \"%d\" n;";
print_endline oc " print_newline ();";
| is ->
let text =
List.fold_left (fun accu (_, text) -> accu ^ text) "" is in
Printf.fprintf oc " print_endline \"%s\";" text;
print_newline oc
end;
if i = last mod lcm then
begin
Printf.fprintf oc " if n <> %d then" last;
print_newline oc;
print_string oc " "
end;
Printf.fprintf oc " step_%d (succ n)" (succ i mod lcm);
if i = pred lcm then
print_string oc " in";
print_newline oc in
let rec loop n =
if n = lcm then
()
else
begin
print_step n;
loop (succ n)
end in
print_endline oc "let main () =";
loop 0;
Printf.fprintf oc " step_%d %d" (start mod lcm) start;
print_newline oc;
print_endline oc ";;";
print_newline oc;
print_endline oc "let () = main ();;"
let exec cmd args =
match Unix.fork () with
| 0 -> Unix.execvp cmd (Array.of_list (cmd :: args))
| pid -> ignore (Unix.waitpid [] pid)
let main () =
let oc = open_out "test.ml" in
generate oc [3, "fizz"; 5, "buzz"; 6, "test"] 3 77;
close_out oc;
exec "ocamlopt.opt" ["-o"; "test"; "test.ml"];
exec "./test" []
let () = main ()
Thread replies: 255
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.