Fizzbuzz thread

Fizzbuzz thread.
Why haven't you joined the ML master race already, Sup Forums?

let rec f n s =
if n = 101
then print_string s
else f (n+1) (s ^ "\n" ^ (
(fun x ->
if x = ""
then string_of_int n
else x)
(List.fold_left
(fun x y -> x ^
if (n mod (fst y) = 0)
then (snd y)
else "" )
""
[3,"fizz";5,"buzz"] )
))
in f 1 "";;

Other urls found in this thread:

youtube.com/watch?v=hKcOkWzj0_s
twitter.com/NSFWRedditImage

If you insist on using meme languages, at least use proper variable names and don't obfuscate your code.
Your FizzBuzz is unacceptable.

I replaced dolist with a while. Now it should look cleaner.
(defun fizzbuzz ()
(interactive)
(let ((fizz nil)
(buzz nil)
(counter 1))
(while (< counter 101)
(insert (format "%s%s%s\n"
(if (setq fizz (= (mod counter 3) 0))
"Fizz" "")
(if (setq buzz (= (mod counter 5) 0))
"Buzz" "")
(if (not (or fizz buzz))
(number-to-string counter) "")))
(setq counter (1+ counter)))))

>OCaml
>Meme Language
Good try, m8.
Might as well disregard the fact that it's used by a very succesful HFT trading firm
youtube.com/watch?v=hKcOkWzj0_s
Or the fact that it's dialect has been adopted by Microsoft for F#
Or the fact that you're obviously talking out of your ass to make up for the fact that you couldn't understand functional paradigm if your life depended on it.

function p(x){console.log(x)} function d(x,n){return x%n==0} for (i=1; i

Runtime-loopless fizzbuzz
import std.stdio;
import std.conv;

string fizzbuzz()
{
auto code = "auto fizzbuzz = \"";
foreach (i; 0..100)
{
auto fizz = i % 3 == 0;
auto buzz = i % 5 == 0;
if (fizz && buzz) code ~= "fizzbuzz";
else if (fizz) code ~= "fizz";
else if (buzz) code ~= "buzz";
else code ~= to!string(i);
code ~= "\n";
}
code ~= "\";";
return code;
}

void main()
{
mixin(fizzbuzz());
writeln(fizzbuzz);
}

That works, but I was going for the more pure functional stuff and code reusability. (in the context that you have to evaluate (n mod x = 0) multiple times).
I still have some pretty limited knowledge and OCaml is a beast of a language for the functional stuff.

function d3(x){return x%3==0 ? console.log("fizz") : true}
function d5(x){return x%5==0 ? console.log("buzz") : true}
for (i = 1; i < 100; i++) { !d3(i) || !d5(i) || console.log(i) }

fkin n00bz

let me show ya how it's done in 2016

let fizzbuzz = function*(){
for (var val = 1; val < 100; val++) {
if(val % 15 === 0){
yield "FizzBuzz";
}
else if(val % 3 === 0){
yield "Fizz";
}
else if(val % 5 === 0){
yield "Buzz";
}
yield val;
}
}();

for (var n of fizzbuzz) {
console.log(n);
}

main(i){printf((char[3][9]){"%d\n","Fizz%s","%s"}[!(i%3)?1:!(i%5)*2],!(i%5)?"Buzz\n":!(i%3)?"\n":i);return i

CSS MASTER RACE


body{counter-reset: item; font-family: Helvetica; font-weight: 300}
div{counter-increment: item}
div:not(:nth-of-type(5n)):before{content: counter(item) ""}
div:nth-of-type(3n):before{content: "Fizz"}
div:nth-of-type(5n):after{content: "Buzz"}
document.write(Array.apply(null, Array(100)).map(() => '').join(''))

VS100|+*"Fizz"!%N3*"Buzz"!%N5N

Rust is the best ML language, and your fizzbuzz is so bad it's insulting.
fn fizzbuzz(n: i64) -> String {
match (n % 3, n % 5) {
0, 0 => "fizzbuzz".to_string(),
0, _ => "fizz".to_string(),
_, 0 => "buzz".to_string(),
_, _ => n.to_string(),
}
}

for n in (1..101) {
println!("{}", fizzbuzz(n));
}

In for python.
a = input
For n in range (a):
If a % 3 && a % 5:
Print 'FizzBuzz'
Elif a % 3:
Print 'Fizz'
Elif a % 5:
Print 'Buzz'

>font-family: Helvetica; font-weight: 300
Why?
It makes no difference, nobody cares about what font you use.

>(interactive)

My CL is a little rusty, what does this do?

>pure functional
>code re-usability
>the code can't be used anywhere except inside the whole
>printing in the inner function itself
>if-then-else
Absolutely disgusting.

Forgot the () after input. Doing this on phone is shit.

Pretty sure that's elisp, not cl.

That isn't Common Lisp, it's Emacs Lisp.
(interactive) allows the function to be called interactively, so you can do M-x fizzbuzz.

>Serif fonts on the Web
Ew

I use OS X, appearance matters a lot to me, can't ya tell?

0/10, doesn't even get interpreted and even if it did it'd be wrong.

font-family: monospace;
The only right choice if you want your stuff to look good.

Does anyone on web use monospace except for code?

That is literally the OCaml meme

What's wrong other than the input ()? Also, shebangs aren't necessary as running $python would work just as well.

Not sure if retarded or just pretending.
>url says Sup Forums.org/g/
Oh.

>in the context that you have to evaluate (n mod x = 0
Did you even read my post?
Just how fucking stupid can you be?

Not as stupid as you that's for sure. Hell, even the pytard is smarter than you I'd bet.

Okay, then, guy. Sure.

(define (fizzbuzz x)
(map (lambda (i)
(cond ((= (modulo i 3) 0) 'Fizz)
((= (modulo i 5) 0) 'Buzz)
((= (modulo i 15) 0) 'FizzBuzz)
(else i)))
x))

Let me spell that out for you.
THE CODE TO REUSE IS THE FUCKING IF STATEMENT FOR
N MOD X = 0
Holy fuck.

for i in range(1,100):
if i % 15 == 0:
print("fizzbuzz")
elif i % 3 == 0:
print("fizz")
elif i % 5 == 0:
print("buzz")
else:
print(i)

python masterrace.

Have you tried having an IQ of 10 or above? They say people in that range are not as retarded as you.

you're shit at python.
for i in range(1,101): print "FizzBuzz"[i*i%3*4:8--i**4%5] or i

At least mine's readable.

Who gives a fuck if your fizzbuzz is readable. It will never be useful.

desu this, anybody can make a readable fizzbuzz, the obfuscated and silly ones are the ones slightly amusing

Please don't use ^ here for string concatenation. Turns the algorithm into O(n^2)

>using input() in python 2

python newbie here.
can you explain the logic for the computer behind why when i is not a multiple of 3 or 5 it gets printed?
Also im assuming [i*i%3*4:8--i**4%5] determines the lenght of the string. Is it because the string is null so it prints i?

Thanks

or is a short circuit operator that can operate on truthy and falsy values.
a string with chars is truthy. an empty string is falsy.
boolA or boolB teaches us that boolB only needs to be evaluated if boolA is false.
the same is true in this case: if "FizzBuzz" is empty (falsy), the second part of the or is evaluated.
[i*i%3*4:8--i**4%5] determines which part of the string to use (slicing: [lower:upper], where upper is an exclusive bound).

ACLS
LOX=0
FOR I=1 TO 100
M=I MOD 30
IF M==0 THEN
LOCATE LOX,29
LOX=LOX+9
ELSE
LOCATE LOX,M-1
ENDIF

THREED=FALSE
IF I MOD 3==0 THEN
THREED=TRUE
? "Fizz";
ENDIF
IF I MOD 5==0 THEN
? "Buzz";
ELSEIF !THREED THEN
? I;
ENDIF
NEXT
LINPUT _$
LOCATE 38,28


Fucking around with SmileBASIC. The shit at the top is to move the cursor around so everything gets printed on the same screen and you can actually read it.

thank you bro. Also why the double - in algorithm .

Damn, this is actually pretty tight.

a unary - has higher precedence than the binary - (or +) (and higher precedence than %, which is why it's applied before %).
8--i**4%5 is equivalent to (8-((-(i**4))%5))

you've been so helpful, thanks

>"fizzbuzz".to_string()
JUST.fuck!().my::shit().up!()

(If[Mod[#,3]==0,"Fizz",""]~~If[Mod[#, 5]==0,"Buzz",""])/.""->#&/@Range[100]

Golf this, bitch.

...did not mean to reply, but I suppose it's sort of appropriate.

(JUST[fuck[#], my~~shit])/.""->@Up

fizzbuzz is an &'static str, i.e. a string which is in the txt segment of the program. to_string() returns a String, which is a heap- (or stack-)allocated object which points to the string. Instead of this, another option was to -> &str for the function signature, and n.to_string().as_slice() instead of just n.to_string().

reading that felt like being waterboarded

Like I said in another post, I was aiming at code reusability, not the most obvious or readable solution.
Notice how you use "n %" twice?
Notice how your function returns "fizzbuzz" instead of concatenating "fizz" and "buzz"

console.log(Array.apply(null, Array(100)).map((a, b) => (++b%3?'':'Fizz')+(b%5?'':'Buzz')||b).join('\n'));

perfection

Sounds like a mistake copied from C++.

inbred >>>/reddit/

That doesn't exist in C++ and isn't a mistake either.

String literals aren't std::string because of backwards compatibility with C.

Completely unrelated.

Meme or not, you're code a shit. It's hard to read, yet not impressive or clever in any way.

If this was my introduction to OCaml I'd say OP answers itself.

Sweet quads, mate.

>Sans-serif fonts anywhere
Disgusting.

Thanks my dude, I was afraid nobody noticed for a second there.

...

Have you tried getting a brain or do you think repeating "I'm clinically retarded! Look at me!" is making you look smart?

gr8 retort, m8

Oh shit, I didn't know Rust had this. Time to jump on the meme train.

Elixir master race coming through

whichfizz = fn
(0, 0, _) -> "FizzBuzz"
(0, _, _) -> "Fizz"
(_, 0, _) -> "Buzz"
(_, _, n) -> n
end

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

IO.inspect Enum.map(1..100, fizzbuzz)


Thanks, mods can close the thread now that the defacto solution has been found.

If your code has the "FizzBuzz" string, you're doing it wrong.

>ruby syntax
why

You're a faggot.
Why the hell are you passing 3 fucking arguments to your first function instead of stating n mod 3/5/15/whatever in your pattern matching conditions?

>oh no, I called the same function twice with different arguments
>better wrap it in a pointless function that just calls it anyway
You're retarded. I know that modulus is resource intensive, and that's why I store the results in variables so I don't have to do the same thing twice.

also, what's wrong with ruby syntax?

too oop-y
too much trying to be like the english language

well, always better than an average Java/C#/PHP cancer.

>Pretending the real performance hurdle isn't printing.

Well then, what am I supposed to do? Manually inspect the memory to see the results?

You're supposed to not care because it'll always be slow as fuck

those suffer from similar issues

Back with more OCamemes
let rec f n s =
if n > 100
then print_string s
else
f (n+1) (s ^ "\n" ^ (
(fun x -> if x = "" then string_of_int n else x) (
(fun x -> if n mod 5 = 0 then x^"buzz" else x^"") (
(fun x -> if n mod 3 = 0 then x^"fizz" else "")
""))))
in f 0 "";;

fizzbuzz fizz buzz fizz fizz buzz fizz fizzbuzz fizz buzz fizz fizz buzz fizz fizzbuzz fizz buzz fizz fizz buzz fizz fizzbuzz fizz buzz fizz fizz buzz fizz fizzbuzz fizz buzz fizz fizz buzz fizz fizzbuzz fizz buzz fizz fizz buzz fizz fizzbuzz fizz buzz fizz fizz

More OCaMemes!
let rec f n s =
if n > 100 then print_string s
else
f (n+1) (s ^ "\n" ^ (
let cond n x s2 s1 =
if n mod x = 0 then s2^s1 else s1 in
(fun x -> if x = "" then string_of_int n else x)
(
(cond n 3 "fizz")
(cond n 5 "buzz" "")
)
))
in f 0 "";;

I'm enjoying myself way too much
let rec f n s = match n with
|100 -> print_string s
|_ ->
f (n+1) (s ^ "\n" ^ (
let cond n x s2 s1 = match n mod x with
|0 -> s2^s1
|_ -> s1
in
(fun x -> match x with
| "" -> string_of_int n
|_ -> x
)
((cond n 3 "fizz")
(cond n 5 "buzz" "")
)
))
in f 0 "";;

That's not how you FizzBuzz in Elixir.

1..100 |> Stream.map(fn(x) ->
case {rem(x, 3), rem(x, 5)} do
{0, 0} -> "FizzBuzz"
{0, _} -> "Fizz"
{_, 0} -> "Buzz"
{_, _} -> x
end
end) |> Enum.each(&IO.puts/1)


And here it is with CHICKEN:

(use streams matchable clojurian-syntax)

(->> (stream-range 1 101)
(stream-map (lambda (x)
(match (list (remainder x 3)
(remainder x 5))
((0 0) "FizzBuzz")
((0 _) "Fizz")
((_ 0) "Buzz")
((_ _) x))))
(stream-for-each print))

THIS is one good elixir implementation.
Also, what's with clojurian-syntax in scheme?

Retard.

why?

clojurian-syntax is a CHICKEN egg which provides the ->> and -> macros, which are from Clojure. It lets you write things in a pipeline kind of like how you use |> in Elixir.

>no haskell
% = mod

fizzbuzz n | n % 15 == 0 = "FizzBuzz"
| n % 5 == 0 = "Buzz"
| n % 3 == 0 = "Fizz"
| otherwise = show n

fizzbuzz n = case (n % 5, n % 3) of
(0, 0) -> "FizzBuzz"
(0, _) -> "Buzz"
(_, 0) -> "Fizz"
(_, _) -> show n

there, two different wa to fizzbuzz

>doesn't print anything
Haskelfags everybody!

I know that, it just said that those are two ways to implement fizzbuzz in haskell.

And its not valid haskell code because it has to names that conflict, you dumb negro.