My friends and I were feeling smug about https://css-tricks.com/tales-of-a-non-unicorn-a-story-about-the-trouble-with-job-titles-and-descriptions/ .
Then we thought a more interesting question would be, how would you implement fizzbuzz /without/ using the modulo operator?
We came up with a few ideas and ranked them. Tell me anon, how would you do it?
>>53935916
Use divisibility tests for 3 and 5 instead.
Though, that's what a good compiler will simplify the modulo operator to anyway.
by treating 1-100 as real numbers and dividing by the 3, 5, or whatever and checking if the result is anything other than an integer (integer in the mathematical sense not the variable type you spergs)
int modulo(int a, int b)
{
while (b <= a)
{
a -= b;
}
return a;
}
int main(int argc, char *argv[])
{
int ii;
for (ii = 0; ii <= 99; ii++)
{
if (!modulo(ii + 1, 3) && modulo(ii + 1, 5) )
{
#include <stdio.h>
printf("Fizz");
}
else
{
if (!modulo(ii + 1, 5) && modulo(ii + 1, 3) )
{
#include <stdio.h>
printf("Buzz");
}
else
{
if (!modulo(ii + 1, 3) && !modulo(ii + 1, 5) )
{
#include <stdio.h>
printf("FizzBuzz");
}
else
{
#include <stdio.h>
printf("%d", (int) ii + 1);
}
}
}
#include <stdio.h>
printf("%c", (char) ' ');
}
#include <stdio.h>
printf("%c", (char) '\n');
return 1;
}
>>53935916
>naming your company after your full name
Only a women
>>53935916
Even if you know fuckall about math you should be able to keep two counters and reset them when they reach 5 or 3.
>>53935916
Fizz buzz is only common questions at startups and other shit companies.
These people would be I need for a rude awakening if they got the same questions you'd get at MS,amazon, facebook,etc.
>>53936488
dude
what the fuck
>>53936638
Did I miss something? I had to correct it after my first attempt...
that doesn't hardc3:=1
c5:=1
c15:=1
for i := 1,100 do
if c15 = 15 then
print FizzBuzz
c3, c5, c15 := 1
elseif c3 = 3 then
print Fizz
c3 := 1
elseif c5 = 5 then
print Buzz
c5 := 1
else
print i
end
c3++
c5++
c15++
end
>>53936663
your curly brackets are all over the place
>>53936721
I double checked, they're all the right length they're supposed to be.
>>53936761
kek
does it compile?
>>53935916npm install fizzbuzz
>>53936721
You mean braces...right?
>>53936865
Right
Not native English m9
>>53936775
Why wouldn't his retarded indent style compile?
The compiler doesn't care.
Not sure about his retarded includes though
>>53936775
Try it yourself, anon-kun
>>53936488
I dont know why but this post made me laugh
>>53936875
No prob, the more you know,. :D
Here's one in Clojure:(let [f "Fizz" b "Buzz" n nil s [n n f n b f n n f b n f n n (str f b)]]
(map #(or %1 %2) (cycle s) (range 1 101)))
>>53935916
>abstract algebra
Gets me every time
Without Modulo operator, just keep two counters. One resets every time it's equal to 3, the other, every time it's equal to 5. The value of these counters represents divisibility by 3 or 5.
Thus, to do FizzBuzz, you need only use basic addition, assignment, if statements, a for loop, and of course, I/O.
Program FizzBuzz;
Uses sysutils;
Var
FBArr : Array[1..100] Of String;
Count : Integer;
Begin
Count := 3;
While Count <= 100 Do
Begin
FBArr[Count] := 'Fizz';
Count := Count + 3;
End;
Count := 5;
While Count <= 100 Do
Begin
If FBArr[Count] = 'Fizz' Then
FBArr[Count] := 'Fizz Buzz'
Else
FBArr[Count] := 'Buzz';
Count := Count + 5;
End;
For Count := 1 To 100 Do
Begin
If FBArr[Count] = '' Then
Write(IntToStr(Count))
Else
Write(FBArr[Count]);
Write(', ');
End;
WriteLn('...');
End.
>>53936879
That's what i meant
I would just use the definition of modulo and implement it normally.int modulo(int a, int b)
{
return a - (b * (a/b));
}
[/code[
Just replace modulo with this:# n and m are integers
def is_mult(n, m):
return m * (n // m) == n
int mod(int m, int n)
{
while (n > m)
n -= m;
return n;
}
:3
>>53938609
if (mod(5, 5) == 5) printf("no\n");
>fizzbuzz
... really, America?
How do you expect to compete with the billions of Pajeets out there if your entry-level programmer test is fizzbuzz?
Come on, I literally solved that on my first day in tech school!
>>53935916
I once used two counters which count to 3 and 5 respectively
>>53936879
I don't know anon, maybe he's onto something there. Doing it that way ensures that you're only including what you need to when you need to, so you won't waste any cycles before it's needed.
Literally just subtracting a number by 3 in a loop. If the resulting number is positive, continue the loop. If it's negative, move on to the next loop (for subtracting the original number by 5). If it's zero, mark the number as a fizz and then move on.
Same thing with the 5 loop but marking as a buzz.
If by the end of the two loops the number has been marked with a fizz and a buzz, guess what?
[spoiler]It's a fizzbuzz[/spoiler]
I'm not even a programmer and I can do that