Thoughts on this code?

Thoughts on this code?

Attached: Screenshot_20190310-154308.png (1920x1080, 1.43M)

Other urls found in this thread:

youtube.com/watch?v=QPZ0pIK_wsc#t=4m18s
twitter.com/NSFWRedditImage

5/10

In J this is just
":`('Fizz'"_)`('Buzz'"_)`('FizzBuzz'"_) @. ((0: = 3&|) + 0: +:@= 5&|)"0 >:i.99

Attached: x.png (971x866, 1.23M)

Here is mine:
const fizzbuzz = require('fizz-buzz')
console.log(fizzbuzz([1,2,3,4,5,6,7,8,9,10]))

do npm install fizz-buzz first

Attached: lol.png (1205x81, 117K)

I don't like how he uses

It's okay.
I'd move the "Fizzbuzz" check to the top so that you would only need to do a single modulus/remainder check in the following ifs.

that's the cringiest and ugliest piece of code I have ever seen in my life
good job on being so minimal

Looks like classic plugman bodge.
Also is this the new fizzbuzz thread?

#include
#include
int main()
{
char* fizz = "Fizz";
char* buzz = "Buzz";

int fb[2] = {3,5};
int i, n;
int* fp;
int* bp;
int* ip;
char *ptr;

fp = &fb[0];
bp = &fp[1];
ip = &i;

for(*ip = 1; *ip

FizzBuzz in lua

t = {[true] = {[true] = "FizzBuzz", [false] = "Fizz"}, [false] = {[false] = false, [true] = "Buzz"}}

for i=1, 100 do
print(t[(i % 3) == 0][(i % 5) == 0] or i)
end

i think he intended it to be easier to follow, even if its wildly inefficient

It works but you can compact it more.
for (var i = 0; i < MAX_FIZZ; i++) {
if (i % 15 == 0)
console.log("FizzBuzz");
else if (i % 3 == 0)
console.log("Fizz");
else if (i % 5 == 0)
console.log("Buzz");
else
console.log(i);
}

>console.log
>not alert
is it 2010 again?

I bet a skilled Perl user could beat that.

Fuck my indentation got stripped.

#include
int main() {
using std::cout;
constexpr size_t num_factors = 2;
constexpr int factors[num_factors] = {3, 5};
constexpr size_t max_str_length = 5;
constexpr char factor_str[num_factors][max_str_length] = {"fizz","buzz"};
auto check_for_no_factor = [&factors](int i) constexpr { for (auto num : factors) if (i%num == 0) return false; return true; };
auto print_factor = [&factors, &factor_str, num_factors](int j) {for (size_t i = 0; i

this check fizzbuzz once on 15 instead of twice (3 and 5).
also use the fucking else statement.

Recursive FizzBuzz in Elixir:
def fizzbuzz(n) do fizzbuzz(1, n+1, 1, 1) end
def fizzbuzz(n, n, _, _) do [] end
def fizzbuzz(i, n, 3, 5) do [:fizzbuzz | fizzbuzz(i+1, n, 1, 1)] end
def fizzbuzz(i, n, 3, b) do [:fizz | fizzbuzz(i+1, n, 1, b+1)] end
def fizzbuzz(i, n, f, 5) do [:buzz | fizzbuzz(i+1, n, f+1, 1)] end
def fizzbuzz(i, n, f, b) do [i | fizzbuzz(i+1, n, f+1, b+1)] end


[1, 2, :fizz, 4, :buzz, :fizz, 7, 8, :fizz, :buzz, 11, :fizz, 13, 14, :fizzbuzz]

>console.log()
Its shit

Scheme:
(map (Lambda (x) (display
(cond ((zero? (modulo x 15)) "FizzBuzz")
((zero? (modulo x 3)) "Fizz")
((zero? (modulo x 5)) "Buzz")
(#t x)))
(newline))
(iota 100 1))

#include
#include

int main(void) {
int i;
i = 1;
loop:
if (i % 5 == 0) goto five;
if (i % 3 == 0) goto three;
if (printf("%d\n", i) < 0) goto printerr;
endloop:
if (i++ == 100) goto done;
goto loop;
five:
if (i % 3 == 0) goto fivethree;
if (printf("buzz\n") < 0) goto printerr;
goto endloop;
fivethree:
if (printf("fizzbuzz\n") < 0) goto printerr;
goto endloop;
printerr:
fprintf(stderr, "printf error\n");
return EXIT_FAILURE;
done:
return EXIT_SUCCESS;
three:
if (printf("fizz\n") < 0) goto printerr;
goto endloop;
}

A better one
#include
#include

const char *const formats[] = {
"%d",
"fizz",
"buzz",
"fizzbuzz"
};

int main(void) {
int i;
for (i = 1; i

Fuck, I actually laughed at this.

>better
>goto
yikes

OK show me a solution without duplicated code or test and no goto.

I mean, he's not wrong.

>fizzbuzz is the only piece of code Jow Forums ever talks about

Attached: r1zr3jm86ba11.jpg (550x543, 83K)

There is also average two ints in C.

import re

fizz = re.compile(r"([0369]*|[147][0369]*[258]|[258][0369]*[147])+$")
buzz = re.compile(r"\d*[05]$")

for i in range(1,101):
f = fizz.match(str(i))
d = buzz.match(str(i))
if f and d:
print("FizzBuzz")
elif f:
print("Fizz")
elif d:
print("Buzz")
else:
print(i)

let () =
let rec loop = function
| 101 -> ()
| i ->
let str_opt =
match i mod 5, i mod 3 with
| 0, 0 -> Some "fizzbuzz"
| 0, _ -> Some "buzz"
| _, 0 -> Some "fizz"
| _, _ -> None in
begin
match str_opt with
| None -> print_int i
| Some s -> print_string s;
end;
output_char stdout '\n';
loop (succ i) in
loop 1
;;

I went and checked the code of the repo. The code is wrong because on 15 it doesn't print out "fizzbuzz". So I guess it is even more true to the average js experience.

In sed:
python -c 'print("\n".join(str(i) for i in range(1,101)))' | sed -E 's/^(([0369]*|[147][0369]*[258]|[258][0369]*[147])+)$/\1Fizz/g ; s/^([0-9]*[05][Fiz]*)$/\1Buzz/g ; s/^[0-9]*([^0-9]+)$/\1/g'

Is this an esoteric fizzbuzz thread?

Yes

He even looks guilty for making it

straight-forward and explicit but verbose. not really a fan but can't blame the fag for it.

user, how old are you?
Goto is ancient as fuck.

What the fuck

If you posted a screenshot from later in his video you'd see that he improves the code quite a bit by using a separate string which he concatenates iirc.

goto is the future (ie. TCO)

My code is love.

for (i = 0; i < 100; i++ {
str = ""

if (i % 3 == 0) {
str += "Fizz"
}

if (i % 5 == 0) {
str += "Buzz"
}

print str


Morons.
All of you.

again
wow that was hard

based

Attached: 2019-03-10 16_48_57-FizzBuzz_ One Simple Interview Question - YouTube.png (929x472, 711K)

Fuck's sake I hit tab and then enter and posted it prematurely.

You get the point though.

How can all of you be so incompetent at programming that you write a specific case for "FizzBuzz"
I hope this automatically bars you from every having any kind of programming job.

tfw seen so many stupid people I honestly can't tell if you are trolling anymore.

#include
static const char *fmts[] = {
"FizzBuzz\n",
"%d\n",
"%d\n",
"Fizz\n",
"%d\n",
"Buzz\n",
"Fizz\n",
"%d\n",
"%d\n",
"Fizz\n",
"Buzz\n",
"%d\n",
"Fizz\n",
"%d\n",
"%d\n",
};
int main()
{
for (int i = 1; i

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

t. jobless faggot that hates JS because "lol [] == 0"

Python. Kneel.
for i in range(1,101):
print("FizzBuzz"[i*i%3*4:8--i**4%5] or i)

Can you do without modulus?

It's simple.

>inb4, defining modulus does not count.

What's wrong with

You forgot to handle errors, but nice code.
4/10 (because of unhandled errors).

>int
Yeah, numbers bigger than 32767 are a myth.
>num_factors
>max_str_length
Nice C code, user. Try using std::string, std::size, or std::array next time.

Fucking sepples lol

Here's my attempt at it. I just started learning this week, could you give me some constructive criticism?

for num in range(1, 101):
if num % 3 == 0 and num % 5 == 0 and num % 10 == 0 :
print("FizzBuzzTrizz")
elif num % 5 == 0 and num % 10 == 0 :
print("BuzzTrizz")
elif num % 5 == 0 and num % 3 == 0 :
print("FizzBuzz")
elif num % 3 == 0 :
print("Fizz")
elif num % 5 == 0 :
print("Buzz")
elif num % 10 == 0 :
print("Frizz")
else :
print(str(num))

I don't like for statements
I almost only use while statements
It just feels more natural for me

Attached: 1465380635971.jpg (521x600, 30K)

int main(void) {
for( int i=1; i

Let's say we start fizzbuzz at 0 like proper arrays starts.

Is 0 FizzBuzz or 0?

Didn't try that hard to make this small, but here it is with minimal math (I'm not sure how to get rid of the summation, and I'm not really counting the subtraction since it's just to convert from char to int)

using System;
using System.Linq;
class Program {
static void Main(string[] args)
{
for(int i = 1; i x - 48).Sum();
return sum == 3 || sum == 6 || sum == 9 ? true : sum > 10 ? div3(sum.ToString()) : false;
}

static bool div5(string num)
{
return num.EndsWith("5") || num.EndsWith("0");
}

static string fizzBuzz(int num)
{
string snum = num.ToString();
bool isdiv3 = div3(snum), isdiv5 = div5(snum);
string ret = "";
if(isdiv3)
{
ret = "Fizz";
}
if(isdiv5)
{
ret += "Buzz";
}
if(ret == "")
{
ret = snum;
}
return ret;
}
}

in C++17 with funlib this is just

const auto fb = Integers() | map(fizzBuzz);

std::cout

Attached: Illya 1163 (PP).jpg (960x540, 29K)

std::variant fizzBuzz (int i)
{
if(i % 15 == 0) return "FizzBuzz";
if(i % 5 == 0) return "Buzz";
if(i % 3 == 0) return "Fizz";

return i;
}
...
const auto fb = Integers() | map(fizzBuzz) | Take(15) | map(
[](const auto v){ std::visit(overloaded {
[](int arg) { std::cout

Attached: 1546755625036.jpg (1074x1910, 947K)

I'm fully erect.

Love this

>How can all of you be so incompetent at programming that you write a specific case for "FizzBuzz"

#1 you are finding integer sequences, if someone wants to do something with the sequences they have to process your output another time.
#2 strings can be immutable therefore using concatenation can produce worse space complexity.

0 is perfectly divisible by both 3 and 5, therefore...

Lurk moar, ranjesh.

I'm not even a code artisan, but even I know you could just print fizz and buzz. If the number is divisible by 15 that will print fizzbuzz.
Why you faggots making it harder than it has to be?

[spoiler]say "Fizz"x$_%%3~"Buzz"x$_%%5||$_ for 1..100[/spoiler]

>no code posted

Okay Rajesh.

Read the thread, it was already posted.

youtube.com/watch?v=QPZ0pIK_wsc#t=4m18s

Javascript:
for(i=1;i

C:
#include
#define F(x,y) printf("%s",i%x?"":#y"zz")
int main(int i){for(--i;i++^100;puts(""))F(3,Fi)|F(5,Bu)||printf("%i",i);return 0;}

Not sure what you mean. Some shitty print command that insets new line at each call? Use something better and insert new line/tabulation/whatever and the end of the loop.

He's obviously a noobie but it's fine. This problems fits itself better to functional languages (with monads)

PHP:
for($i=0;$i++

t. poojeet whose salary is less than what a mcd janitor makes

should be using else for the last 3 if statements. Otherwise very nice. One thing that stands out as good code is the way the for loop is written. Most for loops have the structure for(i=0;i

This is more compact.
for (var i = 0; i < MAX_FIZZ; i++) {
console.log(!(i % 15) ? "FizzBuzz" : !(i % 3) ? "Fizz" : !(i % 5) ? "Buzz" : i);
}

Python3:
for i in range(1,101): print("Fizz"*(i%3==0) + "Buzz"*(i%5==0) or i)

uses argv to take in number

#include
#include
int main(int a,char**s){int n=atoi(*++s);if((n%3)&&(n%5))printf("%d\n",n);else printf("%s%s\n",(n%3)?"":"Fizz",(n%5)?"":"Buzz"); }

>He's obviously a noobie

He's a professional webdev

GNU sed:
sed -nz '0~3s/^/Fizz/;0~5s/$/Buzz/;tx;=;b;:x;p;100q' /dev/zero | sed 'y/\c@/\n/'

for(int i = 1; i < 100; ++i)
{
bool div3 = i % 3 == 0;
bool div5 = i % 5 == 0;
if (not div3 and not div5) { std::cout

This one is for Bash:
for i in {1..100};do ((($i%15==0))&& echo FizzBuzz)||((($i%5==0))&& echo Buzz;)||((($i%3==0))&& echo Fizz;)||echo $i;done

Its shit. You can use breaks and not execute every if statement for no reason on every loop

It's shit on purpose, he was demonstrating what the test actually tests for by giving an example of quick and bad code.
This is his improved version and he's still not entirely happy with it.

Attached: snapshot.jpg (1280x720, 162K)

this looks like brainfuck

maybe that's why nobody uses it

Speaking of, here's the one for brainfuck
++++++++++[>++++++++++>++++++++++>->>>>>>>>>>>>>>>>-->+++++++[->++
++++++++[->+>+>+>+>++++++++[-]++++
+[-]>>-->++++++[->+++++++++++[->+>+>+>+++++++>++++++++[-]++++++[-]>>-->
---+[-+>[-]++[-->++]-->+++[---++[-->-[+
+++[----]++[-->++]--++[--+[->[-]+++++[---->++++]-->[
->+>[.>]++[-->++]]-->+++]---+[->-[+>>>+[->>++++++++++-[>+>>]>[+[-]>+>>]+>>]>[+[-]>
+>>]

lmao fucking trash
for (let i = 0; i < MAX_FIZZ; ++i) {
console.log((!(i%3)?"fizz":"")+(!(i%5)?"buzz":"")||i);
}

xor ax, ax
aa: inc ax
push ax
mov dx, ax
mov bp, sp
push 0x240a
push 0x7a7a
aam 5
jnz @f
push 0x7542
@@: mov ax, dx
aam 3
jnz @f
push 0x6946
@@: mov ax, dx
cmp sp, -8
jne @f
aam 10
xchg al, ah
or ax, 0x3030
pop dx
push ax
@@: mov ah, 0x09
mov dx, sp
int 0x21
mov sp, bp
pop ax
cmp al, 100
jne aa
ret

60 bytes in machine code

If you want to talk about code go to /dpt/ retard

Mutable data, dumb structure, bad usage of a language that supports pure functions

0/10

fizzBuzz arr = List.map (\n -> if (remainderBy 15 n == 0) then "fizzbuzz" else if (remainderBy 5 n == 0) then "buzz" else if (remainderBy 3 n == 0) then "fizz" else String.fromInt n) arr

fizzbuzz (List.range 1 100)

.LC0:
.string "fizzbuzz"
.LC1:
.string "fizz"
.LC2:
.string "%d\n"
fb(int):
push r12
mov r12d, edi
push rbp
mov ebp, 15
push rbx
xor ebx, ebx
.L6:
cmp ebx, r12d
jge .L1
mov eax, ebx
mov edi, OFFSET FLAT:.LC0
cdq
idiv ebp
test edx, edx
je .L8
mov eax, ebx
mov ecx, 3
cdq
idiv ecx
test edx, edx
jne .L5
mov edi, OFFSET FLAT:.LC1
.L8:
call puts
jmp .L4
.L5:
mov esi, ebx
mov edi, OFFSET FLAT:.LC2
xor eax, eax
call printf
.L4:
inc ebx
jmp .L6
.L1:
pop rbx
pop rbp
pop r12
ret

Attached: 4340.png (1943x1948, 3.06M)

It's not optimized but desu most people that do this interview question are just asking for basic knowledge of looks and conditionals without being too clever about it.
I never use fizzbuzz for interviews but my coworkers have and outputting a one line fizzbuzz doesn't tell us anything about how good of a candidate you are, just that you're able to memorize a line of code.
But again, I never use this for interviews, I have my candidates build something.

is this -O0? what shitty compiler doesn't convert a constant div into mul/shr?

Os vs O3

#!/bin/sh
jot 100 |
rs 0 3 | awk '
NF == 3 { $3 = "fizz"; print }
{print}
' |
rs 0 5 | awk '
NF == 5 && $5 != "fizz" { $5 = "buzz"; print }
NF == 5 && $5 == "fizz"{ $5 = "fizzbuzz"; print }
{print}
' | rs 0 1

>table lookup
nice