>list all natural numbers from 1 to 100
>if a number is a multiple of 3, print Fizz instead
>if a number is a multiple of 5, print Buzz instead
>if a number is both a multiple of 3 and 5, print FizzBuzz
This is a standardized test all programmers must pass in order to get hired and there are lots of programmers out there who can't pass it (or make huge messes). I don't understand how that is possible.
This is my attempt, took me around 30 seconds and just one failed test before it worked (had to move line 2 to the top of the loop)
Boggles the fucking mind how somebody with 3 years of computer science experience can fail at this
#include <stdio.h>
int main(void) {
for(int i = 1; i < 101; i++)
{
if((i%3 != 0) && (i%5 != 0)) printf("%d",i);
if(i%3 == 0) printf("fizz");
if(i%5 == 0) printf("buzz");
printf("\r\n");
}
return 0;
}
def fizzbuzz(v)
word = ""
word += "fizz" if value % 3 == 0
word += "buzz" if value % 5 == 0
word += value.to_s if word.empty?
word
end
fn main() {
for i in 1..101 {
match (i % 3, i % 5) {
(0, 0) => println!("FizzBuzz"),
(0, _) => println!("Fizz"),
(_, 0) => println!("Buzz"),
_ => println!("{}", i)
}
}
Statistician coming through.sapply(1:100, function(x) ifelse(x%%15==0, "fizzbuzz", ifelse(x%%5==0, "buzz", ifelse(x%%3==0, "fizz", x))))
[1] "1" "2" "fizz" "4" "buzz" "fizz" "7" "8" "fizz" "buzz"
[11] "11" "fizz" "13" "14" "fizzbuzz" "16" "17" "fizz" "19" "buzz"
[21] "fizz" "22" "23" "fizz" "buzz" "26" "fizz" "28" "29" "fizzbuzz"
[31] "31" "32" "fizz" "34" "buzz" "fizz" "37" "38" "fizz" "buzz"
[41] "41" "fizz" "43" "44" "fizzbuzz" "46" "47" "fizz" "49" "buzz"
[51] "fizz" "52" "53" "fizz" "buzz" "56" "fizz" "58" "59" "fizzbuzz"
[61] "61" "62" "fizz" "64" "buzz" "fizz" "67" "68" "fizz" "buzz"
[71] "71" "fizz" "73" "74" "fizzbuzz" "76" "77" "fizz" "79" "buzz"
[81] "fizz" "82" "83" "fizz" "buzz" "86" "fizz" "88" "89" "fizzbuzz"
[91] "91" "92" "fizz" "94" "buzz" "fizz" "97" "98" "fizz" "buzz"
P Y T H O N I C
list(map(lambda x: "fizzbuzz" if x%15==0 else "buzz" if x%5==0 else "fizz" if x%3==0 else x, range(1, 101)))
>>61662810
what language?
>>61661209
brainlet and codelet here, what does the % represent again?
God damn stupid formatting REEEEE. Should be good this time.div5(X) :- 0 is X mod 5.
div3(X) :- 0 is X mod 3.
fizzbuzz(X, Max) :- (div3(X), div5(X), writeln('FizzBuzz');
div5(X), writeln('Buzz');
div3(X), writeln('Fizz');
writeln(X)), !,
X < Max,
X1 is X+1,
fizzbuzz(X1, Max).
fizzbuzz :- fizzbuzz(1, 100).
>>61664348
Look like rust
>>61664367
Modulo, basically the remainder after division
>>61664427
Thank you anon.
Can someone write clean ruby for this solution?
Readable and clean
>>61661209
I don't like your way of doing it, just letting you know :)
# >list all natural numbers from 1 to 100
# >if a number is a multiple of 3, print Fizz instead
# >if a number is a multiple of 5, print Buzz instead
# >if a number is both a multiple of 3 and 5, print FizzBuzz
from __future__ import print_function
def check_number(num):
if num % 3 == 0 and num % 5 == 0:
print("FizzBuzz")
elif num % 3 == 0:
print("Fizz")
elif num % 5 == 0:
print("Buzz")
else:
print(num)
def main():
for i in range(1, 100):
check_number(i)
if __name__ == "__main__":
main()
without division or modulo, pseudo coderesults = [];
for i = 3; i < 100; i+= 3;
results[i] = 'fizz';
for i = 5; i < 100; i+= 5;
if isset(results[i]))
results[i] .= 'buzz';
else
results[i] = 'buzz';
for i = 1; i < 100; i++;
if isset(results[i]))
print results[i];
else
print i;
>>61661180
Not doing your homework pajeet I have real programmings to do, but start off like this. If you are really good you can write some code to print this out for 1 to 100, then copy and paste that into your program.if 1 % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
else if 1 % 3 == 0:
print("Fizz")
else if i % 5 == 0:
print("Buzz")
else if 2 % 3 == 0 and 2 % 5 == 0:
print("FizzBuzz")
else if 2 % 3 == 0:
print("Fizz")
else if 2 % 5 == 0:
print("Buzz")
else if 3 % 3 == 0 and 3 % 5 == 0:
print("FizzBuzz")
else if 3 % 3 == 0:
print("Fizz")
else if 3 % 5 == 0:
print("Buzz")
>>61664845
Haven't wrote python in awhile, those else if should be elif or something.
4chan doesn't support my language of choice's character set, so I had to screencap it.
>>61661180
>abstract algebra
OMG
>>61662966
>Using a language where foreach is faster than for
>>61661180(define (foldbuzz n)
(for-each (lambda (k)
(let ((normal-number? (foldl (lambda (acc x)
(if (= 0 (modulo k (car x)))
(begin (display (cdr x))
#f)
acc))
#t
(list (cons 3 'fizz) (cons 5 'buzz)))))
(if normal-number?
(display k))
(newline)))
(iota n 1)))
>>61665769
Disgusting indentation.
>>61665793
YOUR disgusting
#!/usr/bin/env node --stack-size=8192
with(JSON){f=a=>((a=((f,s=stringify)=>(g=>g(g))(x=>f((...v)=>(k=>k in x?x[k]:x[k]=x(x)(...v))(s(v)))))(s=>(a,b)=>(b)?s(a^b,(a&b)<<1):a)(a,1))==100)?process.exit(0):(console.log(((((f,s=stringify)=>(g=>g(g))(x=>f((...v)=>(k=>k in x?x[k]:x[k]=x(x)(...v))(s(v)))))(d=>(a,b)=>(a==b)?0:(b<a)?d(((f,s=stringify)=>(g=>g(g))(x=>f((...v)=>(k=>k in x?x[k]:x[k]=x(x)(...v))(s(v)))))(s=>(a,b)=>(b)?s(a^b,(a&b)<<1):a)(a,((f,s=stringify)=>(g=>g(g))(x=>f((...v)=>(k=>k in x?x[k]:x[k]=x(x)(...v))(s(v)))))(s=>(a,b)=>(b)?s(a^b,(a&b)<<1):a)(~b,1)),b):a)(a,3)?'':'Fizz')+(((f,s=stringify)=>(g=>g(g))(x=>f((...v)=>(k=>k in x?x[k]:x[k]=x(x)(...v))(s(v)))))(d=>(a,b)=>(a==b)?0:(b<a)?d(((f,s=stringify)=>(g=>g(g))(x=>f((...v)=>(k=>k in x?x[k]:x[k]=x(x)(...v))(s(v)))))(s=>(a,b)=>(b)?s(a^b,(a&b)<<1):a)(a,((f,s=stringify)=>(g=>g(g))(x=>f((...v)=>(k=>k in x?x[k]:x[k]=x(x)(...v))(s(v)))))(s=>(a,b)=>(b)?s(a^b,(a&b)<<1):a)(~b,1)),b):a)(a,5)?'':'Buzz')||a)),f(a))
f(!f)}
>>61666072
My disgusting what?
>>61661180(display (filter non-empty-string?
(map (λ (x) (local [(define s "")]
(begin
(cond [(eq? (modulo x 3) 0)
(set! s (~a s "Fizz"))])
(cond [(eq? (modulo x 5) 0)
(set! s(~a s "Buzz"))])
s)))
(stream->list (in-range 1 100)))))
>>61665769
What fucking lamguage has so much parentheses
>>61664453
For you, anon100.times{|i|i+=1;puts i%15==0?"fizzbuzz":i%5==0?"buzz":i%3==0?"fizz":i.to_s}
>>61666433
hebrew
>>61666494
You don't need the conditional for fizzbuzz. An if for each one and you'll get fizzbuzz where they overlap. In other words, instead of an if/elseif, just do two consecutive ifs.
>>61666135
anus
>>61666706
I suppose it could use a good wax and bleach.
>>61662810
>>61661209
>>61662966
>>61664401
>>61663120
These are shit.
FizzBuzz in C
#include <stdio.h>
int main()
{
int i;
for (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);
}
}
}
>>61666837
FizzBuzz in Python
2 ez
for i in range (1, 101):
if (i % 3 == 0 and i % 5 == 0):
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
Its unbelievable to me that people fail this test.
#include <stdio.h>
int main()
{
for (int i=0;++i<101;puts(""))
{
char f[] = "FizzBuzz%d";
f[8-i%5&12]=0;
printf (f+(-i%3&4+f[8]/8), i);
}
}
>>61661180if 0 % 15 == 0:
print("FizzBuzz")
elif 0 % 3 == 0:
print("Fizz")
elif 0 % 5 == 0:
print("Buzz")
if 1 % 15 == 0:
print("FizzBuzz")
elif 1 % 3 == 0:
print("Fizz")
elif 1 % 5 == 0:
print("Buzz")
if 2 % 15 == 0:
print("FizzBuzz")
elif 2 % 3 == 0:
print("Fizz")
elif 2 % 5 == 0:
print("Buzz")
if 3 % 15 == 0:
print("FizzBuzz")
elif 3 % 3 == 0:
print("Fizz")
elif 3 % 5 == 0:
print("Buzz")
if 4 % 15 == 0:
print("FizzBuzz")
elif 4 % 3 == 0:
print("Fizz")
elif 4 % 5 == 0:
print("Buzz")
if 5 % 15 == 0:
print("FizzBuzz")
elif 5 % 3 == 0:
print("Fizz")
elif 5 % 5 == 0:
print("Buzz")
if 6 % 15 == 0:
print("FizzBuzz")
elif 6 % 3 == 0:
print("Fizz")
elif 6 % 5 == 0:
print("Buzz")
if 7 % 15 == 0:
print("FizzBuzz")
elif 7 % 3 == 0:
print("Fizz")
elif 7 % 5 == 0:
print("Buzz")
if 8 % 15 == 0:
print("FizzBuzz")
elif 8 % 3 == 0:
print("Fizz")
elif 8 % 5 == 0:
print("Buzz")
if 9 % 15 == 0:
print("FizzBuzz")
elif 9 % 3 == 0:
print("Fizz")
elif 9 % 5 == 0:
print("Buzz")
if 10 % 15 == 0:
print("FizzBuzz")
elif 10 % 3 == 0:
print("Fizz")
elif 10 % 5 == 0:
print("Buzz")
if 11 % 15 == 0:
print("FizzBuzz")
elif 11 % 3 == 0:
print("Fizz")
elif 11 % 5 == 0:
print("Buzz")
if 12 % 15 == 0:
print("FizzBuzz")
elif 12 % 3 == 0:
print("Fizz")
elif 12 % 5 == 0:
...
>>61664367
don't call us
we'll call you
>>61661180
>>61661180local p = {[0] = "%d", "fizz", "buzz", "fizzbuzz"}
local a = function (b) if b then return 1 end return 0 end
local f = function (i) return string.format(p[a(i%3 == 0)+a(i%5==0)*2], i) end
for i=0,100 do print(f(i)) end
do any companies actually ask interviewees to do fizzbuzz anymore?
I started learning Go today, this was the first thing I wrotepackage main
import "fmt"
func main(){
for i := 1; i <= 100; i++ {
fmt.Print(i)
if i%3 == 0 {
fmt.Print("fizz")
}
if i%5 == 0 {
fmt.Print("buzz")
}
println()
}
}
>>61666886
Work on modularity nigger
This would be an asspain to maintain
>>61667124
Looks like I forgot how fizzbuzzes are supposed to work, but you get the idea.
>>61661180
Easy.Print("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")
Sent from my iPhone
>>61664841
Even if you did this concurrently I'm pretty sure it'd be slower than just using one for loop
>>61667030
You're our new CEO, anon.
>>61664841
what does .= do
#include <stdio.h>
int main (void)
{
for (int i=1;i<=100;i++)
{
if (i % 15 == 0)
printf ("%3i : FizzBuzz\n", i);
else if (i % 5 == 0)
printf ("%3i : Buzz\n", i);
else if (i % 3 == 0)
printf ("%3i : Fizz\n", i);
else
printf ("%3i\n", i);
}
return 0;
}
for(int i = 1; i <= 100; i++){
int temp = i;
bool fb = false;
while(temp > 0)
temp -= 3;
if(temp == 0){
printf("fizz");
fb = true;
temp = i;
while(temp > 0)
temp -= 5;
if(temp == 0){
printf("buzz");
fb = true;
}
if(!fb)
printf(i);
printf("\n");
}
Who needs % or /?
Hire me pls
All these brainlets using mod 15 when you already have 3 and 5 lmao
>>61667365
Nice
>>61667262
shorthand forvar = 'po';
var = var . 'pcorn';
>>61667184
yeah, you could mash all the logic into one loop and I think it'd actually be faster than the classic modulo operation approach. Try it, especially for bigger inputs. Anyway, I broke it out into three loops so beginners can understand exactly what's going on, to help it 'click' so to speak.
(let [f "fizz"
b "buzz"
fb "fizzbuzz"]
(map #(nth (conj (cycle [% % f % b f % % % b % f % % fb]) %) %)
(range 1 101)))
> brainlet doesn't understand that the mod 15 answer is the most efficient
You save so little time that you can run it without probably a billion times in the time it takes to type out the 15 comparison
>>61667572
It's the
>you don't need math to program xd
math flunkie skiddie posse running /g/.
>>61661209
why the calls to int()?
1[[Fizz]n1sw]sF[[Buzz]n1sw]sB[dn]sN[dd0sw3%0=F5%0=Blw0=N[
]n1+d100!<L]dsLx
from itertools import islice
def fizzbuzz(i):
while True:
if i % 15 == 0:
yield "FizzBuzz"
elif i % 3 == 0:
yield "Fizz"
elif i % 5 == 0:
yield "Buzz"
else:
yield str(i)
i += 1
print('\n'.join(islice(fizzbuzz(1), 100)))
Whenever I have to generate sequences I like to just make an infinite generator and then just take what I need from that.
>>61667818
>import
Failed.
>>61661180
elegantpublic class FizzBuzz
{
public static void main(String[] args)
{
for (int i = 1; i < 101; ++i)
System.out.println(i%15==0?"FizzBuzz": (i%5==0?"Buzz":(i%3==0?"Fizz":i)));
}
}
>>61667847
Nobody said imports weren't allowed.
>>61667879
Nobody said it, but it shows how shit you are.
>>61667855
you get points for actually properly incrementing the for counter, but lose them all for i < 101
>>61667896
I bet brainlet.
>>61667928
>python mongoloid
>can't manage fizzbuzz without importing shit
>calls anyone brainlet
pottery
>>61667938
>>61667896
different from C includes how?
>>61661180
Haskell is just objectively better.
fizzbuzz n | n `mod` 15 == 0 = "fizzbuzz"
| n `mod` 5 == 0 = "fizz"
| n `mod` 3 == 0 = "buzz"
| otherwise = show n
main = mapM_ (print . fizzbuzz) [1..100]
>>61667896
you write what we call on the /tech/ college graduate code, so how the fuck can you even shit talk anyone else?
You're as bad as a cuck.js morons on github
>>61667914
do you use <= 100? I never use <= in a loop.
>>61667965
stay mad pajeet
>>61667963fizzbuzz n = case (rem n 3, rem n 5) of
(0,0) -> "fizzbuzz"
(0,_) -> "fizz"
(_,0) -> "buzz"
_ -> show x
map fizzbuzz [1..100]
can you get more efficient than this with python?
This is actually the state of Node.JS programming right now.
// of course you should use a package to make the code easier, simpler, and faster :^)
var fizzbuzz = import("node-fizzbuzz")
var fb = fizzbuzz.createInstance({min=0,max=100});
fb.loop(function(n, err) {
if(err) {
console.log(err);
process.exit();
}
fb.if(n.fizz, function(err) {
if(err) {
console.log(err);
process.exit();
}
console.log(fb.fizz);
}
fb.if(n.buzz, function(err) {
if(err) {
console.log(err);
process.exit();
}
console.log(fb.buzz);
}
fb.if(n.fizzbuzz, function(err) {
if(err) {
console.log(err);
process.exit();
}
console.log(fb.fizzbuzz);
}
fb.if(n.number, function(err) {
if(err) {
console.log(err);
process.exit();
}
console.log(n.value);
}
});
fb.endInstance();
// see? use packages! they make everything better! don't reinvent the wheel! :^)
>>61668131
yeah, don't use modulo, instead use counters. Try it for 10^19 -> 10^20 and youll see what I mean
>>61668225
Nobody would write it like that.
>>61668244
>instead use counters
u wot?
>>61668272
Node users can't even write their own fucking string padder
https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/
>>61668296
The JavaScript versions would look almost exactly like the Python versions in this thread including the generator version you were sperging out about.
>inb4 "lol secondlife"
>>61668354
>inafter forgot image.
rip
>>61668286
Ignore him. Modulo on small integers is incredibly cheap. The string concatenation is significantly more expensive and can be eliminated easily.
#include <iostream>
using namespace std;
int main() {
cout<<"1"<<"2"<<"buzz"<<"4"<<"fizz"<<"buzz"<<"7"<<"8"<<"buzz"<<"fizz"<<"11"<<"buzz"<<"13"<<"14"<<"fizzbuzz"<<"16"<<"17"<<"buzz"<<"19"<<"fizz"<<"buzz"<<"22"<<"23"<<"buzz"<<"fizz"<<"26"<<"buzz"<<"28"<<"29"<<"fizzbuzz"<<"31"<<"32"<<"buzz"<<"34"<<"fizz"<<"buzz"<<"37"<<
"38"<<"buzz"<<"fizz"<<"41"<<"buzz"<<"43"<<"44"<<"fizzbuzz"<<"46"<<"47"<<"buzz"<<"49"<<"fizz"<<"buzz"<<"52"<<"53"<<"buzz"<<"fizz"<<"56"<<"buzz"<<"58"<<"59"<<"fizzbuzz"<<"61"<<"62"<<"buzz"<<"64"<<"fizz"<<"buzz"<<"67"<<"68"<<"buzz"<<"fizz"<<"71"<<"buzz"<<"73"<<"74"<<"fizz
buzz"<<"76"<<"77"<<"buzz"<<"79"<<"fizz"<<"buzz"<<"82"<<"83"<<"buzz"<<"fizz"<<"86"<<"buzz"<<"88"<<"89"<<"fizzbuzz"<<"91"<<"92"<<"buzz"<<"94"<<"fizz"<<"buzz"<<"97"<<"98"<<"buzz"<<"fizz"<<endl;
}
can't beat this
>>61668244
>>61668286
I think he was talking about starting from zero and incrementing the value by the divisor until it was no longer less than the dividend, and then checking if they have the same value, if true then the modulus is zero.
Isn't that how the modulus function works anyways?
>>61661180
modern programmers have no use for the mod operation. You only learn that math brainteaser stuff in CS
Perlsay "Fizz"x!($_%3)."Buzz"x!($_%5)||$_ for 1..100
C#include "stdio.h"
int main(void)
{
for (int i = 1; i < 101; ++i) {
printf("%d\r", i);
if (i % 3 == 0) { printf("Fizz");
if (i % 5 == 0) { printf("Buzz");
printf("\n");
}
return 0;
}
>>61668407
wouldn't there be an optimal way of doing it by now that everyone could just use?
>>61668407
Welcome to the Big 4
>>61668759
posting a thread on /g/ and using one of the results posted
Haxeclass Main {
static public function main():Void {
for (i in 1...101) {
var line:String = "";
if (i % 3 == 0)
line += "Fizz";
if (i % 5 == 0)
line += "Buzz";
if (line == "")
line += i;
trace(line);
}
}
}
>>61668433
>he actually believes this
>>61668759
yes, see >>61668407
Made in Gopackage main
import (
"fmt"
)
func main() {
fmt.Println("FizzBuzz challenge!")
for i := 1; i <= 100; i++ {
if i%3 == 0 {
fmt.Printf("%d : Fizz\n", i)
}
if i%5 == 0 {
fmt.Printf("%d : Buzz\n", i)
}
if i%3 == 0 && i%5 == 0 {
fmt.Printf("%d : FizzBuzz\n", i)
}
}
}
>>61669138
See, this is why nobody will ever take you seriously as a programmer.
>>61669700
What?
>>61661209
It's 2 lines in python.
>>61670350
>can't see whats wrong with his code
i'll give u a clue programmers rubber duck
>>61670350
You should be using else ifs to reduce unnecessary conditional checks. As it stands, your program will check all 3 conditions for each i. This is inefficient.
>>61664683
>uses a language that relies on whitespace for code structure
>doesn't wrap code tags around it
Javascriptfor (i=1; i <=100; i++){
if (!(i%3)) print("fizz");
if (!(i%5)) print("buzz");
if (i%5 && i%3) print(i);
}
#include <iostream>
int main() {
for (int i = 1; i < 101; i++)
std::cout << (i % 3) ? ((i % 5) ? "FizzBuzz" : "Fizz") : "Buzz";
}
Would you hire me, /g/?
>>61671142
No. Thinks he's clever, probably arrogant.
for (i=1; i <=100; i++){
i%3 ? (i%5 ? print(i) : print("Buzz")) : (i%5 ? print("Fizz") : print("FizzBuzz"))
}
>>61671285
Whoopsfor (i=1; i <=100; i++){
i%3 ? (i%5 ? print(i) : print("Buzz")) : (i%5 ? print("Fizz") : print("FizzBuzz"))
}
>>61671205
Actually, that was a test. You failed to notice the solution was wrong so I don't want to work for your company anyway.
>>61671318
I stopped reading when I saw chained ternary operators.
>>61671328
No you completely missed it lmao
>>61671401
>Thinks he's clever, probably arrogant.
See, I was right not to hire you.
>>61671418
Thanks for the (You) but your shitposter is in another reply
>>61670848
you would fail my test
>>61666497
underrated
33o<CR>Fizz<CR><Esc>qqABuzz<Esc>5kq19@q:%s/^$/\=line('.')<CR>
pls dont bulli#!/bin/bash
echo "1"
echo "2"
echo "Fizz"
echo "4"
echo "Buzz"
echo "Fizz"
echo "7"
echo "8"
echo "Fizz"
echo "Buzz"
echo "11"
echo "Fizz"
echo "13"
echo "14"
echo "FizzBuzz"
echo "16"
echo "17"
echo "Fizz"
echo "19"
echo "Buzz"
echo "Fizz"
echo "22"
echo "23"
echo "Fizz"
echo "Buzz"
echo "26"
echo "Fizz"
echo "28"
echo "29"
echo "FizzBuzz"
++++++++++[>++++++++++<-]>>++++++++++>->>>>>>>>>>>>>>>>-->+++++++[->++
++++++++<]>[->+>+>+>+<<<<]+++>>+++>>>++++++++[-<++++<++++<++++>>>]++++
+[-<++++<++++>>]>>-->++++++[->+++++++++++<]>[->+>+>+>+<<<<]+++++>>+>++
++++>++++++>++++++++[-<++++<++++<++++>>>]++++++[-<+++<+++<+++>>>]>>-->
---+[-<+]-<[+[->+]-<<->>>+>[-]++[-->++]-->+++[---++[--<++]---->>-<+>[+
+++[----<++++]--[>]++[-->++]--<]>++[--+[-<+]->>[-]+++++[---->++++]-->[
->+<]>>[.>]++[-->++]]-->+++]---+[-<+]->>-[+>>>+[-<+]->>>++++++++++<<[-
>+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>
+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->+++
+++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]+[-<+]->>]+[-]<<<.>>>+[
-<+]-<<]
>>61664845
crap like this is hell to maintain, please don't get hired
Well done, well done.
Now write a formal proof.
>>61661180
What the guck is a natural number?
Suck on my massive dickj=[(['','Fizz'][i%3==0]+['','Buzz'][i%5==0])for i in range(1,101)]
print('\n'.join([(str(i+1)if j[i]==""else j[i])for i in range(100)]));
>>61671142
your code is wrong C++ brainlet
for number in range (1,101):
if number % 15 ==0:
print ('Fizzbuzz')
elif number % 5 ==0:
print ('Buzz')
elif number % 3 ==0:
print ('Fizz')
>>61674869
Digusting and incorrect solution, should be:for number in range (1,101):
if number % 15 ==0:
print ('Fizzbuzz')
elif number % 5 ==0:
print ('Buzz')
elif number % 3 ==0:
print ('Fizz')
else:
print(i)
All you /g/fags are too stupid for FizzBuzz?
>>61674896
Apparently. In my defence though, I'm using a phone,
got a prolog exam in some time. I feel like a retard when programming in this language.
create_list(1,[1]).
create_list(N,L) :-
N2 is N - 1,
create_list(N2,L2),
!,
append(L2,[N],L).
fizzBuzzer(X,"Fizz") :-
(mod(X,3) =:= 0),
(mod(X,5) =\= 0),
!.
fizzBuzzer(X,"Buzz") :-
(mod(X,5) =:= 0),
(mod(X,3) =\= 0),
!.
fizzBuzzer(X,"FizzBuzz") :-
(mod(X,3) =:= 0),
(mod(X,5) =:= 0),
!.
fizzBuzzer(X,X).
fizzBuzzList([],[]).
fizzBuzzList([X|Rest],L) :-
fizzBuzzer(X,NewX),
fizzBuzzList(Rest,NewL),
append([NewX],NewL,L).
fizzBuzz(N,L) :-
create_list(N,L1),
fizzBuzzList(L1,L),
write(L).
>>61672936
what part of
>all natural numbers from 1 to 100
don't you understand?
>>61672533
vim is beating out all of you
>>61662505
and who's going to write the iterator, the end user? fucking twat.
>>61668244
>>61668286
>>61668384
>>61668424
>>61668424
He was refering to doing the problem like this, which is about twice as fast:fizz = 3
buzz = 5
for n in range(1, 101):
o = ''
fizz -= 1
buzz -= 1
if fizz == 0:
fizz = 3
o += 'Fizz'
if buzz == 0:
buzz = 5
o += 'Buzz'
if o == '':
print(n)
else:
print(o)
>>61667030
What are you doing? Scratch has modfizzBuzz n =
case (n `mod` 3, n `mod` 5) of
(0, 0) -> "FizzBuzz"
(0, _) -> "Fizz"
(_, 0) -> "Buzz"
_ -> show n
main = mapM_ (putStrLn . fizzBuzz) [1..100]
#include <iostream>
using namespace std;
int main()
{
for (short i = 1; i < 101; i++)
{
if (i % 15 == 0)
{
cout << "FizzBuzz\n";
}
else if (i % 3 == 0)
{
cout << "Fizz\n";
}
else if (i % 5 == 0)
{
cout << "Buzz\n";
}
else
{
cout << i << endl;
}
}
return 0;
}
cool thread /g/
>not calling a meeting to establish coding guidelines
>not creating a budget
>no risk assessment
>no jira project to track progress
>no agile poker to estimate work hours
>no pair coding session organized
>not writing behavioral test beforehand
>no CI environment setup
>no devops tooling for easy deployment
>no cloud infra for infinite fizzbuzz scaling
>no GPU accelerated ML fizzbuzzing running in your browser
all failed attempts tbf
Can somone tell me why or why not this is an acceptable way of doing it?#include <stdio.h>
#include <stdbool.h>
int main()
{
unsigned int max = 101;
bool three, five;
for (unsigned int i = 1; i != max; i++) {
three = ( (i % 3) == 0);
five = ( (i % 5) == 0);
if (five & three) {
printf("FizzBuzz\n");
} else if (three) {
printf("Fizz\n");
} else if (five) {
printf("Buzz\n");
} else {
printf("%d\n", i);
}
}
return 0;
}
>>61675082
I do not think it did back then. I forgot when I made that.
>>61675874
how do i put teh code in teh nice white boxes that accept my format like teh rest of youse guyses?
Thinking about stuff is for nerds who don't use Java.public class Main {
public static void main(String[] args) {
for(int i = 1; i <= 100; i++) {
StringBuilder out = new StringBuilder();
if(i % 3 == 0)
out.append("Fizz");
if(i % 5 == 0)
out.append("Buzz");
if(out.length() > 1)
System.out.println(out);
}
}
}
>>61676428
Oh btw.
>Garbage Collector Master Race
Heh, fuckin nerds.
>>61676428
>building a string every iteration
>>61675874
<code>
#include <iostream>
using namespace std;
int main()
{
for (short i = 1; i < 101; i++)
{
if (i % 15 == 0)
{
cout << "FizzBuzz\n";
}
else if (i % 3 == 0)
{
cout << "Fizz\n";
}
else if (i % 5 == 0)
{
cout << "Buzz\n";
}
else
{
cout << i << endl;
}
}
return 0;
}
cool thread /g/
</code>
fixt it 4 u
>>61676345like this
>>61676570#include <iostream>
using namespace std;
int main()
{
for (short i = 1; i < 101; i++)
{
if (i % 15 == 0)
{
cout << "FizzBuzz\n";
}
else if (i % 3 == 0)
{
cout << "Fizz\n";
}
else if (i % 5 == 0)
{
cout << "Buzz\n";
}
else
{
cout << i << endl;
}
}
return 0;
}
holy toledo, thanks senpai
>>61676517
>not having the resources to spare
>watching the performance of a program
>not using 100% of the CPU to mine dodge coins
Look at this guy. I bet Mr. Shekelstein is very proud that you are able to optimize his software so well.
>>61661180
back to >>>/reddit/ you piece of garbage
#include <utility>
#include <iostream>
template<char...>
struct static_string;
template<typename...>
struct static_strcat;
template<char... C, typename... A>
struct static_strcat<static_string<C...>, A...>
{
using value = typename static_strcat<
static_string<C...>, typename static_strcat<A...>::value
>::value;
};
template<char... L, char... R>
struct static_strcat<static_string<L...>, static_string<R...>>
{
using value = static_string<L..., R...>;
};
template<int N, bool = (N < 10)>
struct static_itoa;
template<int N>
struct static_itoa<N, true>
{
using value = static_string<'0' + N, '\n'>;
};
template<int N>
struct static_itoa<N, false>
{
using value = typename static_strcat<
typename static_itoa<N / 10>::value,
typename static_itoa<N % 10>::value
>::value;
};
template<>
struct static_strcat<>
{
using value = static_string<>;
};
template<typename>
struct static_cstr;
template<char... C>
struct static_cstr<static_string<C...>>
{
static constexpr char value[] = { C..., '\0' };
};
template<char... C>
constexpr char static_cstr<static_string<C...>>::value[];
template<int N, int _3, int _5>
struct fizzbuzz_val
{
using value = typename static_itoa<N>::value;
};
template<int N, int _5>
struct fizzbuzz_val<N, 0, _5>
{
using value = static_string<'F', 'i', 'z', 'z', '\n'>;
};
template<int N, int _3>
struct fizzbuzz_val<N, _3, 0>
{
using value = static_string<'B', 'u', 'z', 'z', '\n'>;
};
template<int N>
struct fizzbuzz_val<N, 0, 0>
{
using value = static_string<'F', 'i', 'z', 'z', 'B', 'u', 'z', 'z', '\n'>;
};
template<typename>
struct fizzbuzz_aux;
template<int... I>
struct fizzbuzz_aux<std::integer_sequence<int, I...>>
{
using value = typename static_strcat<
typename fizzbuzz_val<(I + 1), (I + 1) % 3, (I + 1) % 5>::value...
>::value;
};
using fizzbuzz = fizzbuzz_aux<std::make_integer_sequence<int, 100>>;
int main(void)
{
std::cout << static_cstr<fizzbuzz::value>::value;
}
O(1) execution time.
ection .text
global _start
_start: ; entry point
mov ecx, 1 ; set loop counter
loop_main:
push ecx ; save loop counter
xor dx, dx ; reset dx
mov ax, cx
mov bx, 15
div bx
cmp dx, 0
jz div_by_3_5 ; if divisible by 3 and 5
xor dx, dx ; reset dx
mov ax, cx
mov bx, 3
div bx
cmp dx, 0
jz div_by_3 ; if divisible by 3
xor dx, dx ; reset dx
mov ax, cx
mov bx, 5
div bx
cmp dx, 0
jz div_by_5 ; if divisible by 5
; print number
mov eax, ecx ; set print_num arg
call print_num
jmp cont
div_by_3_5: ; print fizz buzz
mov eax, 4 ; syscall number
mov ebx, 1 ; stdout
mov ecx, fizzbuzz ; ptr to buffer
mov edx, 11 ; buffer size
int 0x80
jmp cont
div_by_3: ; print fizz
mov eax, 4 ; syscall number
mov ebx, 1 ; stdout
mov ecx, fizz ; ptr to buffer
mov edx, 6 ; buffer size
int 0x80
jmp cont
div_by_5: ; print buzz
mov eax, 4 ; syscall number
mov ebx, 1 ; stdout
mov ecx, buzz ; ptr to buffer
mov edx, 6 ; buffer size
int 0x80
jmp cont
cont:
pop ecx ; restore loop counter
cmp ecx, 100
jz exit ; end of loop
inc ecx ; increment loop counter
jmp loop_main
exit:
mov eax, 1
mov ebx, 0 ; exit(0)
int 0x80
print_num: ; arg eax
push esi ; put counter on stack
mov esi, 0 ; set counter to 0
>>61676854loop_div: ; keep dividing until eax is 0
mov edx, 0
mov ebx, 10
div ebx ; divide eax by 10, mod in edx
add edx, 48 ; ascii char offset
push edx ; put char on stack
inc esi ; increment counter
cmp eax, 0
je print_stack ; eax is 0, break
jmp loop_div
print_stack: ; print chars on stack
cmp esi, 0
je done ; nothing left to print
dec esi ; decrement counter
mov eax, 4 ; syscall number
mov ebx, 1 ; stdout
mov edx, 1 ; length
mov ecx, esp ; syswrite arg is top of stack
int 0x80
add esp, 4 ; update stack ptr
jmp print_stack
done:
; print new line
mov eax, 4 ; syscall number
mov ebx, 1 ; stdout
mov ecx, nl ; ptr to buffer
mov edx, 1 ; buffer size
int 0x80
pop esi ; restore counter
ret
section .data
fizz dw "Fizz", 0Ah, 0Dh
buzz dw "Buzz", 0Ah, 0Dh
fizzbuzz dw "Fizz Buzz", 0Ah, 0Dh
nl dw 0Ah, 0Dh ; new line
section .bss
>>61676623
>not implementing a string pool for your fizzbuzz
it's like you don't want to get hired
Here's my fizzbuzz in rebol :)repeat i 100 [
fizz: "fizz"
buzz: "buzz"
fizzbuzz: "fizzbuzz"
fizzarray: [i fizz buzz fizzbuzz]
a: 1
if (mod i 3) = 0 [a: a + 1]
if (mod i 5) = 0 [a: a + 2]
print do fizzarray/(a)
]
def fizzbuzz(number):
return {
0: number,
number % 3: 'Fizz',
number % 5: 'Buzz',
number % 15: 'FizzBuzz',
}[0]
for number in range(1, 101):
print fizzbuzz(number)
Why does /g/ do these
>>61661180using System;
namespace fizzbuzz
{
public class fizzbazz
{
public void main(string[] args)
{
for(int i=0;i<100;i++)
{
if(i % 3 == 1 && i % 5 == 1)
{
Console.WriteLine("FizzBuzz");
}
else if(i % 3 == 1)
{
Console.WriteLine("Fizz");
}
else if(i % 5 == 1)
{
Console.WriteLine("Buzz");
}
else
{
Console.WriteLine(i);
}
}
}
}
}
>>61677216
This one makes me want to die
>>61677216
oh shit. I wrote 1 instead of 0 consistently
>>61677228
Why? Other than the blatant one instead of zero error. Also the capitalization of Main. Sounds like you just don't like c#.
>>61677250if(i % 3 == 0 && i % 5 == 0)(corrected)
This can be compressed to i%15==0
Plus Console.WriteLine
windows is ick.
It's far, FAR too verbose for me.
>>61677272
Okay, mister, what language would you use instead?
>>61676910
>ever letting the compiler cuck you by reusing objects
>not forcing a new String object out of spite
Oh boy, I guess you need to catch up a bit more until you can work with the pros. Until then have fun getting "hired"(=>enslaved) by ((them)).
>>61677299
I used guile/lisp, but I'd also use python if I wanted to do it quickly
>>61677307
I see.
>>61677216
You are iterating the numbers 0 to 99.
#include <iostream>
#include <string>
int main(int argc, char *argv[]) {
for (int i = 1; i < 101; ++i)
std::cout << ((i % 3==0) ? "Fizz" : "") << (i%5==0 ? "Buzz" : (i%3==0 ? "" : std::to_string(i))) << std::endl;
return 0;
}
Tried to make it as small as possible. Any way to make it smaller?
print("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\n")
Python one liner
#include <stdio.h>
#include <stdlib.h>
#define FIZZBUZZ_CASE(term) case term: printf("FizzBuzz\n"); break
#define FIZZ_CASE(term) case term: printf("Fizz\n"); break
#define BUZZ_CASE(term) case term: printf("Buzz\n"); break
#define EMPTY_CASE(term) case term:
#define NORMAL_CASE(term) case term: printf("%d\n", i); break
int main(void)
{
int i;
for (i = 1; i <= 100; i++)
{
int j = i;
while (j - 15 >= 0) j = j - 15;
switch (j)
{
FIZZBUZZ_CASE(0);
EMPTY_CASE(1);
NORMAL_CASE(2);
FIZZ_CASE(3);
NORMAL_CASE(4);
BUZZ_CASE(5);
FIZZ_CASE(6);
EMPTY_CASE(7);
NORMAL_CASE(8);
FIZZ_CASE(9);
BUZZ_CASE(10);
NORMAL_CASE(11);
FIZZ_CASE(12);
EMPTY_CASE(13);
NORMAL_CASE(14);
}
}
return 0;
}
interface FizzBuzzable {
public int value();
public String doFizzBuzz();
}
final class FizzBuzzableNumber implements FizzBuzzable {
private final int num;
public FizzBuzzableNumber(int n) { this.num = n; }
public final int value() { return this.num; }
public final String doFizzBuzz() { return new Integer(this.num).toString(); }
}
abstract class DivisibleNumber implements FizzBuzzable {
protected final FizzBuzzable original;
public DivisibleNumber(FizzBuzzable origin) { this.original = origin; }
public final int value() { return this.original.value(); }
public final String doFizzBuzz() {
String fizzBuzzed;
if (this.isDivisible())
fizzBuzzed = this.fizzBuzzing();
else
fizzBuzzed = this.original.doFizzBuzz();
return fizzBuzzed;
}
protected abstract boolean isDivisible();
protected abstract String fizzBuzzing();
}
final class NumberDivisibleByThree extends DivisibleNumber {
public NumberDivisibleByThree(FizzBuzzable origin) { super(origin); }
protected final String fizzBuzzing() { return "Fizz"; }
protected final boolean isDivisible() { return ((this.value() % 3) == 0); }
}
final class NumberDivisibleByFive extends DivisibleNumber {
public NumberDivisibleByFive(FizzBuzzable origin) { super(origin); }
protected final String fizzBuzzing() { return "Buzz"; }
protected final boolean isDivisible() { return ((this.value() % 5) == 0); }
}
final class NumberDivisibleByThreeAndFive extends DivisibleNumber {
public NumberDivisibleByThreeAndFive (FizzBuzzable origin) { super(origin); }
protected final String fizzBuzzing() { return "Fizz Buzz"; }
protected final boolean isDivisible() { return ((this.value() % 15) == 0); }
}
public class Main {
public static void main(String[] args) {
for (int i = 1; i <= 100; ++i) {
System.out.print(new NumberDivisibleByThreeAndFive(new NumberDivisibleByFive(new NumberDivisibleByThree(new FizzBuzzableNumber(i)))).doFizzBuzz());
if (i < 100) System.out.print(", ");
}
}
}
>>61666433
Lisp
Sorry, anon, but I don't see any comments here. Didn't your CS professor tell you? If someone else can't look at your code and know what it does, YOU won't be able to either in 8 weeks, so comment, comment, comment!
Why does everyone have the third mod 15 conditional when just two works? Just put a newline at the end of the loop instead of each time output is called.
Are calls to console outputs actually that taxing that a third division operation and comparison is faster?
>>61678430
literally who cares, only way to win fizzbuzz is not to play
>coming first in the special olympics
>>61678714
I care because little autistic optimizations like that interest me, especially when they could become useful later however minutely
Python 2 linerimport fizzbuzz
fizzbuzz.run()
>>61678430
I'm trying to find this again, if I do I'll give an update. I remember something in "The C++ Programming Language" saying that temporaries are held and may be reused. Maybe a good compiler can optimize that if it sees that you're doing (i % 5) with an unchanged i twice in a row and will store and reuse the result. If someone who knows this better can tell me whether or not it's a thing that would be much appreciated.
Of course, even if this is a thing for C++ it may not be so for other languages.
>>61679292
Now that I think about it, technically couldnt you just call two bools that do i%5 and i%3 then compare them, and itll do that regardless of the compiler?bool fizz = i%3;
bool buzz = i%5;
if(fizz&&buzz){
...
} else if(fizz){
...
}else if(buzz){
...
else{
...
}
>>61679610
Shit should be i%x == 0 for those mods
>>61667704
>Good job anon, you found the most autistic way to program this, rather than the most optimized; you're hired!
Very rough draft{⊃,/((⍱/L),L←(⍵⍴3=⍳3),⍪⍵⍴5=⍳5)/¨(⍕¨⍳⍵),⍵2⍴'Fizz' 'Buzz'}100
>>61676830
this is quality coding you don't witness often
>>61679986
If only it produced correct output.
>>61674928
4chan said "Error: Too many lines."
but here you have: https://pastebin.com/tqnkQdbt
I made a slightly different version of this, in which my program takes an input from the user instead.
running = True
while running:
i = int(input("Enter a value here: "))
if int(i) % 15 == 0:
print("Fizzbuzz")
elif int(i) % 5 == 0:
print("Buzz")
elif int(i) % 3 == 0:
print("Fizz")
How did I do /g/? Its my third day in programming.
nice and comfyfor i in range (1, 101): print [i, "fizz", "buzz", "FizzBuzz"][(i%3==0)+2*(i%5==0)]
>>61678997Traceback (most recent call last):
File "C:\Users\Anon\Documents\FizzBuzz.py", line 3, in <module>
import fizzbuzz
ImportError: No module named fizzbuzz
>>61667030
OwO whats this
>>61661209
for (var I=0,I>100,I++);
document.write(I);
if I%3==0:
document.write("Fizz");
else if I%5==0:
document.write("Buzz");
else if I%3 && I%5:
document.write("FizzBuzz");
else:
document.write("nigger")
fkn casuals#include <stdio.h>
void main() {
char f[]="fizzbuzz";
char n[]="%s\n\0%d\n";
for(int i=1;i<101;i++) {
f[4]='b'*(i%5==0);
printf(n+4*(i%3 && i%5),((long)i*(i%3 && i%5))|((long)(f+4*(i%3!=0))*!(i%3 && i%5)));
}
}
%:import:(read) |> r.
: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)
>>61661180using System;
using System.Linq;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
Func<int, string>[] values = {i => i + "", i => "Fizz", i => "Buzz", i => "FizzBuzz"};
var fizzBuzz = Enumerable.Repeat(0, 100)
.Select((x, i) => x + Math.Sin(3886233.05311717 * i + 3886234.09321357))
.Select((x, i) => x + Math.Sin(3319323.02253289 * i + 3319324.77764699))
.Select((x, i) => x + Math.Sin(517102.382386617 * i + 517104.106333962))
.Select((x, i) => 0.7 * x + 1.2)
.Select((x, i) => values[(int) x](i + 1));
Console.WriteLine(String.Join("\n", fizzBuzz));
Console.ReadKey();
}
}
}
>3 comparisons per loop
>3 integer divisions per loop
Y'all suck at this
>>61681362
the actual challenge is to program it on paper, within 5 minutes.
but i agree that most of this thread is babbies first script-tier
>>61681362#include <iostream>
using namespace std;
int main()
{
for (short i = 1; i < 101; i++)
{
if (i % 15 == 0)
{
cout << "FizzBuzz\n";
}
else if (i % 3 == 0)
{
cout << "Fizz\n";
}
else if (i % 5 == 0)
{
cout << "Buzz\n";
}
else
{
cout << i << endl;
}
}
return 0;
}
what about me senpai
>>61682072
>mod 15
terrible
for i in range(1, 101):
if not i % 15:
print('FizzBuzz')
elif not i % 3:
print('Fizz')
elif not i % 5:
print('Buzz')
else:
print(i)
#include <stdio.h>
int main (int argc, char **argv) {
int m;
for (int i=1; i<=100; i++) {
m = i%5;
if (!(i%3)) {
printf("Fizz");
if (!m)
printf("Buzz");
} else if (!m)
printf("Buzz");
else
printf("%d", i);
printf("\n");
}
return 0;
}
#include <stdio.h>
int main(void)
{
for (int i = 1; i <= 100; i++){
printf("%d, %s \n", i,
(const char*[]){"", "fizz", "buzz", "fizzbuzz" }
[(i % 3 == 0) | ((i % 5 == 0) << 1)]);
}
}
>>61676830
tantamount to just storing the output in an array and printing that!
here's the big criticism though:
>_3
>_5
never, ever, ever, use leading underscores. you should also experiment with constexpr if/else, or std::conditional
>>61680447
Made a mistake when trying to shorten it to fit the message length limit.#include <utility>
#include <iostream>
template<char...>
struct s_string;
template<typename...>
struct s_strcat;
template<char... C, typename... A>
struct s_strcat<s_string<C...>, A...>
{
using value = typename s_strcat<
s_string<C...>, typename s_strcat<A...>::value
>::value;
};
template<char... L, char... R>
struct s_strcat<s_string<L...>, s_string<R...>>
{
using value = s_string<L..., R...>;
};
template<int N, bool = (N < 10)>
struct s_itoa;
template<int N>
struct s_itoa<N, true>
{
using value = s_string<'0' + N>;
};
template<int N>
struct s_itoa<N, false>
{
using value = typename s_strcat<
typename s_itoa<N / 10>::value, typename s_itoa<N % 10>::value
>::value;
};
template<typename>
struct s_cstr;
template<char... C>
struct s_cstr<s_string<C...>>
{
static constexpr char value[] = { C..., '\0' };
};
template<char... C>
constexpr char s_cstr<s_string<C...>>::value[];
template<int N, int _3, int _5>
struct fb_val
{
using value = typename s_strcat<
typename s_itoa<N>::value, s_string<'\n'>
>::value;
};
template<int N, int _5>
struct fb_val<N, 0, _5>
{
using value = s_string<'F', 'i', 'z', 'z', '\n'>;
};
template<int N, int _3>
struct fb_val<N, _3, 0>
{
using value = s_string<'B', 'u', 'z', 'z', '\n'>;
};
template<int N>
struct fb_val<N, 0, 0>
{
using value = s_string<'F', 'i', 'z', 'z', 'B', 'u', 'z', 'z', '\n'>;
};
template<typename>
struct fb_aux;
template<int... I>
struct fb_aux<std::integer_sequence<int, I...>>
{
using value = typename s_strcat<
typename fb_val<(I + 1), (I + 1) % 3, (I + 1) % 5>::value...
>::value;
};
using fb = fb_aux<std::make_integer_sequence<int, 100>>;
int main(void)
{
std::cout << s_cstr<fb::value>::value;
}
>>61661180
Public Sub PrintFizzBuzz
FKNARRAY = ["1","2","Fizz","4","Buzz",...,"Buzz"]
For Each DankMeme in FKNARRAY
MsgBox(DankMeme)
Next
End Sub
>>61667524
is this as fast as it seems?
seq 100 | awk '
$1 % 3 == 0 {printf "fizz"; x=1}
$1 % 5 == 0 {printf "buzz"; x=1}
!x {printf $1}
{x=0; printf "\n"}
'
>>61661209
K but ur overloading "i". I would at least declare a result variable.
Because readability counts.
haxe:class Main {
static public function main():Void {
for (i in 1...101)
trace(switch ([i % 3, i % 5]) {
case [0, 0]: "FizzBuzz";
case [0, _]: "Fizz";
case [_, 0]: "Buzz";
case _: i;
});
}
}
>>61661180
I understand how people can check for 3 or 5 last because the question asks, 3 or 5 or (3 and 5) and you could hastily place it as the last if in the if else if else if and get the question wrong.
>>61661180
>if a number is both a multiple of 3 and 5, print FizzBuzz
First time I came across this part I got so mind fucked for some reason.
>>61683644
Yeah, grade school math is really hard.
#include <stdio.h>
int main()
{
for (int i = 1; i < 101; i++) {
!(i % 3) ? printf("Fizz\n") : !(i % 5) ? printf("\nBuzz\n") : !(i % 15) ? printf("FizzBuzz\n") : 0;
}
}
>>61683981
Good job, retard. You failed.
>>61683981
>>61683569
How good is Haxe's pattern matching?
>>61666684
You shouldn't end up with a line feed between fizz and buzz.
>>61682663
>>61683981
gran autismoFizz
Buzz
Fizz
Fizz
Buzz
Fizz
Fizz
Fizz
Buzz
Fizz
Fizz
Buzz
Fizz
Fizz
Fizz
Buzz
Fizz
Fizz
Buzz
Fizz
Fizz
Fizz
Buzz
Fizz
Fizz
Buzz
Fizz
Fizz
Fizz
Buzz
Fizz
Fizz
Buzz
Fizz
Fizz
Fizz
Buzz
Fizz
Fizz
Buzz
Fizz
Fizz
Fizz
Buzz
Fizz
Fizz
Buzz
#!/bin/bash
for y in {1..100};
do
{ (( y % 100 == 0)) && echo "$y fuck off"; } ||
{ (( y % 5 == 0 )) && (( y % 3 == 0 )) && echo "$y 2 memes at once"; } ||
{ (( y % 5 == 0 )) && echo "$y meme"; } ||
{ (( y % 3 == 0 )) && echo "$y meme"; } || echo "$y"
done
>>61672936
great job, best one here
Is there a pajeet reference example?
>>61670848
it's one line if you're not a scrubprint('\n'.join(['Fizz'*(x % 3 == 2) + 'Buzz'*(x % 5 == 4) or str(x + 1) for x in range(100)]))
Fuck, how are you all so retarded? I started learning python, (my first programming language) in July.
In my god damn spare time away from work.
>>61684159
then don't start a new line till after buzz is checked
>>61684355
doesn't look as cool stupid
defmodule FizzBuzz do
def fizzbuzz(n) do
case {rem(n, 3), rem(n, 5)} do
{0, 0} -> "FizzBuzz"
{0, _} -> "Fizz"
{_, 0} -> "Buzz"
_ -> n
end
end
end
1..100
|> Enum.map(&FizzBuzz.fizzbuzz/1)
|> Enum.join("\n")
|> IO.puts()
int main() {
for(int i=0;i++<100;)printf("%d\n\0 Fizz\n\0Buzz\n\0FizzBuzz\n"+6*!(i%3)+12*!(i%5),i);
}
beat this, fuckers
>>61661180(defun fizzp (i) (zerop (mod i 3)))
(defun buzzp (i) (zerop (mod i 5))
(loop for i from 1 to 100
when (fizzp i) do (format t "Fizz")
when (buzzp i) do (format t "Buzz")
when (or (fizzp i) (buzzp i)) do (format t "~%"))
>still nobody made one in binary lambda calculus yet
>>61661180for num in range(1, 101):
if (num%3 == 0 or num%5 == 0):
if (num%3 == 0):
print("Fizz", end="")
if (num%5 == 0):
print("Buzz", end="")
else:
print(num, end="")
print(" ", end="")
Hello, I am a webdev.
>>61685199
i tried to send one just now but it was too long
>>61683858
Apparently I can't logic when I'm looking at a timer counting down...
>>61662225
>printf("\r\n");
>windows
kys
>>61685341
Pastebin works.
>>61661180
>>61661180\eject
\newcount\n
\newcount\x
\n=1
\loop\ifnum\n<100
\x=\n \divide\x by 15 \multiply\x by 15 \advance\x - \n
\ifnum\x=0
\noindent FIZZBUZZ \break
\else
\x=\n \divide\x by 3 \multiply\x by 3 \advance\x - \n
\ifnum\x=0
\noindent FIZZ \break
\else
\x=\n \divide\x by 5 \multiply\x by 5 \advance\x - \n
\ifnum\x=0
\noindent BUZZ \break
\else
\noindent \the\n \break
\fi
\fi
\fi
\advance\n by 1
\repeat
Fucking kill me.
>>61686258
is this fucking tex
Programmed the first half. This shit is easy. You nerds are overthinking it.
>>61686397
Tight cropping and lack of source code. Very suspicious.
No one cares about your fancy code, OP was asking why a lot of programmers can't do it themselves.
>>61686397
here buddy i made a bash script to help you complete that great python fizzbuzz#!/bin/bash
for y in {1..100};
do
{ (( y % 5 == 0 )) && (( y % 3 == 0 )) && echo "print(\"fizzbuzz\")"; } ||
{ (( y % 5 == 0 )) && echo "print(\"buzz\")"; } ||
{ (( y % 3 == 0 )) && echo "print(\"fizz\")"; } || echo "print(\"$y\")"
done
>>61686657
>>61686397
here's the output for convenience sake
print(1)
print(2)
print(fizz)
print(4)
print(buzz)
print(5)
print(fizz)
print(7)
print(8)
print(fizz)
print(10)
print(11)
print(fizz)
print(13)
print(14)
print(fizzbuzz)
etc
>>61686657
could I have a script to make your bash script?
why am i getting connection error when i try to post on /g/?
>FizzBuzz Thread
>240 replies
Good work, OP.
>>61686965
i could but i'm not that committed to meta...
>>61687104
i am amazed at the popularity of this fizzbuzz thread
i can't actually post it here because i get "connection error" ;_;
https://pastebin.com/8x4Lvvsy
Standardized?! No, not even by a long shot. A few recruiters use it as an indicator and nothing more.
>>61665769
is this the elegance I've heard so much about?
>>61666860
I'd like you to write a protocol parser for our highly secure server.
>>61661180
package main
import "fmt"
func main(){
fizzbuzz(1)
}
func fizzbuzz(i int) {
if i % 15 == 0 {
fmt.Println(i)
fmt.Println("fizzbuzz " )
}else if i % 3 == 0 {
fmt.Println(i)
fmt.Println("fizz")
} else if i % 5 == 0 {
fmt.Println(i)
fmt.Println("buzz")
}
if i < 99 {
var j = i + 1;
fmt.Println(i)
fizzbuzz(j)
}
}
pythonfor i in range (1, 101):
if i % 3 == 0:
fizzbuzzstring = "Fizz"
if i % 5 == 0:
fizzbuzzstring += "Buzz"
else:
fizzbuzzstring == i
print(fizzbuzzstring)
It's as easy as that, ladies and gentlemen.
>>61688974
ok first of all this is wrong, it should befor i in range(1, 101):
fizzbuzzstring = ""
if i % 3 == 0:
fizzbuzzstring = "Fizz"
if i % 5 == 0:
fizzbuzzstring += "Buzz"
if fizzbuzzstring == "":
fizzbuzzstring = str(i)
print(fizzbuzzstring)
and also, I had a bit more fun trying to figure out how to automate something like >>61686703for i in range(1, 101):
fizzbuzzstring = "print('"
if i % 3 == 0:
fizzbuzzstring += "Fizz"
if i % 5 == 0:
fizzbuzzstring += "Buzz')"
else:
fizzbuzzstring += "')"
elif i % 5 == 0:
fizzbuzzstring += "Buzz')"
if fizzbuzzstring == "print('":
fizzbuzzstring += str(i) + "')"
print(fizzbuzzstring)
Would commenting my fizzbuzz indicate good programming style or just mental retardation?
>>61666497
Did I do it right?
>>61691256
I improved it, now fizz, buzz, start of list and the end of list can be entered. Also includes an error.
>>61692146
Whoops, quoted the wrong guy.
Anyway here is a version with the main for loop in a sub-vi, like god intended
>>61692316
Just how deep can the rabbit hole go?
#define FIZZTEST 0x4924
#define BUZZTEST 0x4210
char buf[9];
int fizztest = FIZZTEST, buzztest = BUZZTEST;
for (int i = 1; i <= 100; i++) {
buf[0] = 0;
if (fizztest & 1) strcat(buf, "Fizz");
if (buzztest & 1) strcat(buf, "Buzz");
if (!*buf) sprintf(buf, "%d", i);
puts(buf);
fizztest >>= 1;
buzztest >>= 1;
if (!fizztest && !buzztest) {
fizztest = FIZZTEST;
buzztest = BUZZTEST;
}
}
C-Can I have a job now?lastNumber = 101
def getFizzBuzz(number):
if number % 15 == 0:
return "'fizzbuzz'"
elif number % 3 == 0:
return "'fizz'"
elif number % 5 == 0:
return "'buzz'"
else:
return "i"
fizzbuzz = ''
fizzbuzz += 'for i in range(1,%i):\n'%lastNumber
for i in range(1,lastNumber+1):
if i == 1:
fizzbuzz += "\tif i == %i:\n\t\tprint(%s)\n" % (i,getFizzBuzz(i))
else:
fizzbuzz += "\telif i == %i:\n\t\tprint(%s)\n" % (i,getFizzBuzz(i))
f = open('fizzbuzz.py','w')
f.write(fizzbuzz)
f.close()
execfile('fizzbuzz.py')
>>61668047
What language is that? That switch system looks really sexy.
>>61684037
It's cute I guess.
>>61674993
I like this.
>>61667524
woah
>>61692734
Haskell
>>61666886
>>61664845
>>61666854
>>61661209
people usually mess up because they write code like this. This test is all about the follow up question where they add more constraints (ie writee "huzz" for all multiples of 2, 6 etc..)
Because you all wrote code like this, your solution starts to look sloppy when answering the follow up questions.
>>61693010
i don't see any problem with 3 and 4 of what you quoted
>>61661180
How are there 264 fucking replies and no one else has called you out for being subscribed to youtube's favorite adboy trending artist Tom Scat?
>>61661180
an attempt was made#include <stdio.h>
#include <stdlib.h>
int main()
{
for (int i = 1; i <= 100; ++i) {
int flag = 0;
if (i % 3 == 0) {
printf("Fizz");
++flag;
}
if (i % 5 == 0) {
printf("Buzz");
++flag;
}
if (!flag) {
printf("%d", i);
}
puts("");
}
exit(EXIT_SUCCESS);
}
~
>>61694513
Also why is no one vectorizing?i = 1:100;
i3 = find(mod(i,3)==0);
i3str = 'Fizz';
i5 = find(mod(i,5)==0);
i5str = 'Buzz';
ryzen = intersect(i3,i5);
str = cellstr(num2str(i','%d\n'));
str(i3) = repmat({i3str},length(i3),1);
str(i5) = repmat({i5str},length(i5),1);
str(ryzen) = repmat({[i3str i5str]},length(ryzen),1);
fprintf('%s\n',str{:});
>>61692682
>python
Absolutely fucking not.
$ mail jim@intranet
I need a FizzBuzz program within 20min.
^D
>>61692622
Also I made a horrible Python version of this:F = 18724
B = 16912
f = F
b = B
for i in range(1, 101):
o = ["Fizz" if f & 1 else "", "Buzz" if b & 1 else "", i]
if o[0] or o[1]:
del o[2]
print(*o, sep="")
f >>= 1
b >>= 1
if not f and not b:
f = F
b = B
>>61661180
This is in C (Relevant code only):int vrCounter;
vrCounter = 1;
while(vrCounter <= 100){
if(vrCounter % 3 == 0 && vrCounter % 5 == 0){
printf("FizzBuzz!\n");
}
else if(vrCounter % 3 == 0){
printf("Fizz!\n");
}
else if(vrCounter % 5 == 0){
printf("Buzz!\n");
}
else{
printf("%d!\n", vrCounter);
}
vrCounter++;
}
>>61694687
No external libraries.
>>61697490
I see no dependencies except for I/O from the standard C library. This is valid C99.
You're supposed to know if you should write a C program in a freestanding environment.
fizzbuzz.d:module fizzbuzz;
import std.string;
import std.algorithm;
class FizzBuzz
{
private string[int] strings;
private int first;
private int last;
string result;
this(int f, int l)
{
this.first = f;
this.last = l;
}
void add_str(int n, string s)
{
this.strings[n] = s;
}
void del_str(int n)
{
this.strings.remove(n);
}
void set_range(int f, int l)
{
this.first = f;
this.last = l;
}
void run()
{
this.result.length = 0;
int matched;
for (int i = this.first; i <= this.last; ++i) {
matched = 0;
foreach(j; this.strings.keys.sort) {
if (i % j == 0) {
this.result ~= this.strings[j];
matched = 1;
}
}
if (!matched) {
this.result ~= format("%d", i);
}
this.result ~= "\n";
}
}
}
>>61697490
>Standard library
>external
hmm
var log = ''
//Actual function
for (var i = 0; i <= 100; i++) {
var a = (i % 3 == 0 && i > 0), b = (i % 5 == 0 && i > 0);
log += (a ? ( b ? "FizzBuzz" : "Fizz") : (b ? "Buzz" : i)) + "\n";
}
Would /g/ hire me?
#
#include <iostream>
#include <string>
int main()
{
std::string words[3] = { "Fizz", "Buzz", "FizzBuzz" };
for (int i = 1; i <= 100; ++i)
{
int fb = (i % 3 == 0) + (i % 5 == 0) * 2;
if (fb)
std::cout << words[fb - 1] << '\n';
else
std::cout << i << '\n';
}
return 0;
}
const fizzBuzz = () => {
let iteration = 1;
while (iteration <= 100) {
let output = "";
const tryAppend = (divisor, string) => {
if (iteration % divisor === 0) {
output = `${output}${string}`;
}
};
tryAppend(3, "Fizz");
tryAppend(5, "Buzz");
if (output.length === 0) {
output = iteration.toString(10);
}
console.log(output);
iteration += 1;
}
};
fizzBuzz();
That's a FizzBuzz I just wrote in EcmaScript. I don't like oldschool for loops, so I use a while instead.
Probably not the most efficient or extensible way to do it, but it's simple#include <stdio.h>
int main() {
for(int i = 0; i <= 100; i++) {
if(i % 15 == 0)
puts("fizzbuzz");
else if(i % 3 == 0)
puts("fizz");
else if(i % 5 == 0)
puts("buzz");
else
printf("%d\n", i);
}
}
>>61687171
this is the best way
displays to interviews a way to think around modulus and a familiarity with the standard library
>>61661180
>all programmers must pass in order to get hired
lol
no
First time doing this.for i in range (1,101):
if ( i%3 == 0 and i%5 == 0):
print "FizzBuzz"
elif (i % 3 == 0):
print "Fizz"
elif (i % 5 == 0):
print "Buzz"
else:
print i
>>61684192
What the fuck are msec? 'mac seconds'? Macfags are so retarded
>>61693010
You realise I was posting a joke right?
>>61700966
Why do you do else ifs? There are only three possible output states, and you have four conditions in your if statement.
#include <stdio.h>
int main() {
#define f "fizz"
#define b "buzz"
#define fb "fizzbuzz"
const char *x[100/15 + 1][15] = {
[0 ... 100/15] = {0, 0, f, 0, b, f, 0, 0, f, b, 0, f, 0, 0, fb}
};
const char **y = (const char**)x;
for (int i = 0; i < 100; ++i)
printf(y[i]?"%s ":"%d ", y[i]?:i+1);
}
>>61690704
if your code is obfuscated to the point where a fizzbuzz program is not immediately obvious, there's definitely some mental retardation there, anon
not the fastest possible
>>61663120
>map, lambda
>Pythonic
>>61704583
amazing
>>61666497
fucking kek
Matlab:i=1:100;
c=strtrim(cellstr(num2str(i')));
c(mod(i,5)==0) = {'Buzz'};
c(mod(i,3)==0) = {'Fizz'};
c(mod(i,15)==0) = {'FizzBuzz'};
strjoin(c')
Took me longer than I thought because I rarely work with strings or cells. Easy solution would have been a simple for loop but where's the fun in that?
>>61695146
2 improvements:
i3 = mod(i,3)==0;
i5 = mod(i,5)==0;
str( i3 & i5 ) = ...
this doesn't require any finds or intersect. Also you only need:
str(i3) = {i3str};
instead of
str(i3) = repmat({i3str},length(i3),1);
>>61704604
Yeah, right? At least use a list comprehension if you're creating a list anyway.["fizzbuzz" if not x % 15 else "buzz" if not x % 5 else "fizz" if not x % 3 else x for x in range(1, 101)]
>>61661180
Fizz = 3
Buzz = 5
for i in range(100):
if i%Fizz == 0 and i%Buzz == 0:
print("FizzBuzz")
elif i%Fizz == 0:
print("Fizz")
elif i%Buzz == 0:
print("Buzz")
else:
print(i)
Took me all of 20 seconds
>>61707809
And you already fucked up the "all natural numbers from 1 to 100" part.
>>61707928Fizz = 3
Buzz = 5
for i in range(1,101):
if i%Fizz == 0 and i%Buzz == 0:
print("FizzBuzz")
elif i%Fizz == 0:
print("Fizz")
elif i%Buzz == 0:
print("Buzz")
else:
print(i)
>>61664453
Nope.
Ruby and Perl are strictly write only.
>>61667030
What is that?anyone?
>>61686917
Buddy, you forgot to assign variables
fizz = 'Fizz'
buzz = 'Buzz'
fizzbuzz = 'FizzBuzz'
Now that should work.
Backwards compatible up to 1973 when C was invented:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int i;
char * fizzbuzzstring = calloc(1024, sizeof(char));
for (i = 1; i <= 100; ++i)
{
if (i % 3 == 0)
{
strcat(fizzbuzzstring, "fizz");
}
if (i % 5 == 0)
{
strcat(fizzbuzzstring, "buzz");
}
if (fizzbuzzstring[0] == 0)
{
printf("%i\n", i);
}
else
{
printf("%s\n", fizzbuzzstring);
fizzbuzzstring[0] = 0;
}
}
free(fizzbuzzstring);
}
>>61708603
the programming learning stuff for raspberry pi. forgot the name but installed it for my nephew.
>>61708603
Its scratch
>>61661180
Let me guess, are those 'developers' making webshites and whatnot?
>>61707414
¯\_(ツ)_/¯ Spaced on logical indexing.
I'm p sure this PAID MATLAB IDE beats the performance of the FOSS kiddy's C implementation on a system with at least four cores.
>>61709955
The only way I can think of to improve this is to not set "Fizz" and "Buzz" at the intersection indices but that probably doesn't net much performance improvement. Honestly ditching cell arrays altogether would make it fast though harder to maintain. I did the Tom Scott thing and made it so that new rules can be added easily.
This runs 1 to 10,000 in 50 ms on an i5-750.i = 1:100;
iidx{1} = mod(i,3)==0;
istr{1} = 'Fizz';
iidx{2} = mod(i,5)==0;
istr{2} = 'Buzz';
iidxnor = ~any(cat(1,iidx{:}));
str(iidxnor) = cellstr(num2str(i(iidxnor)','%-d\n'));
for j = 1:length(iidx)
str(iidx{j}) = istr(j);
end
str(all(cat(1,iidx{:}))) = {[istr{:}]};
fprintf('%s\n',str{:});
>>61701447
Milliseconds, retard. And that would be Clojure, not macOS itself.
>reinventing the wheel
just use a service for this shit or you will never finish your project if you keep at this pace
http://buzzcloud.xyz/
>>61711728
That last optimization was p simple idk what I was thinking. Also tested removing cell arrays. No measurable gain to be had. Runs to a million with no printing in 1.435 seconds on an i5-750. Can anyone on /g/ beat it or are we all collectively agreeing that MATLAB is the most efficient environment for performance coding?iidxnor = ~any(cat(1,iidx{:}));
iidxand = all(cat(1,iidx{:}));
str(iidxnor) = cellstr(num2str(i(iidxnor)','%-d\n'));
for j = 1:length(iidx)
str(~iidxand & iidx{j}) = istr(j);
end
Private Sub Command1_Click()
Text1.Text = ""
For I = 1 To 100
If I Mod 3 = 0 Then
Text1.Text = Text1.Text & "Fizz"
End If
If I Mod 5 = 0 Then
Text1.Text = Text1.Text & "Buzz"
End If
If I Mod 3 > 0 And I Mod 5 > 0 Then
Text1.Text = Text1.Text & I
End If
Text1.Text = Text1.Text & vbCrLf
Next I
End Sub