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 "";;
>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.
Michael Brooks
function p(x){console.log(x)} function d(x,n){return x%n==0} for (i=1; i
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.
Parker Garcia
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) }
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)); }
Luis Morris
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'
Sebastian Hall
>font-family: Helvetica; font-weight: 300 Why? It makes no difference, nobody cares about what font you use.
Joshua Price
>(interactive)
My CL is a little rusty, what does this do?
Zachary Lewis
>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.
Xavier Hughes
Forgot the () after input. Doing this on phone is shit.
Lucas Butler
Pretty sure that's elisp, not cl.
Justin Gray
That isn't Common Lisp, it's Emacs Lisp. (interactive) allows the function to be called interactively, so you can do M-x fizzbuzz.
Mason Jackson
>Serif fonts on the Web Ew
I use OS X, appearance matters a lot to me, can't ya tell?
Justin Bennett
0/10, doesn't even get interpreted and even if it did it'd be wrong.
Zachary Morales
font-family: monospace; The only right choice if you want your stuff to look good.
Joseph Brown
Does anyone on web use monospace except for code?
Dylan Sanders
That is literally the OCaml meme
Dylan Phillips
What's wrong other than the input ()? Also, shebangs aren't necessary as running $python would work just as well.
Aiden Hall
Not sure if retarded or just pretending. >url says Sup Forums.org/g/ Oh.
Ethan Ramirez
>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?
Cooper Bell
Not as stupid as you that's for sure. Hell, even the pytard is smarter than you I'd bet.
Jordan Hall
Okay, then, guy. Sure.
Luis Davis
(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))
Camden Martin
Let me spell that out for you. THE CODE TO REUSE IS THE FUCKING IF STATEMENT FOR N MOD X = 0 Holy fuck.
Jose Fisher
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.
Hunter Gutierrez
Have you tried having an IQ of 10 or above? They say people in that range are not as retarded as you.
Isaac Ortiz
you're shit at python. for i in range(1,101): print "FizzBuzz"[i*i%3*4:8--i**4%5] or i
Aiden Roberts
At least mine's readable.
Noah Wood
Who gives a fuck if your fizzbuzz is readable. It will never be useful.
Leo Sullivan
desu this, anybody can make a readable fizzbuzz, the obfuscated and silly ones are the ones slightly amusing
Ryder Torres
Please don't use ^ here for string concatenation. Turns the algorithm into O(n^2)
Christopher Sanders
>using input() in python 2
Ryder James
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
Carson Powell
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).
Jackson Jackson
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.
Julian Fisher
thank you bro. Also why the double - in algorithm .
Chase Myers
Damn, this is actually pretty tight.
Jackson Diaz
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))
...did not mean to reply, but I suppose it's sort of appropriate.
Thomas Rodriguez
(JUST[fuck[#], my~~shit])/.""->@Up
Matthew Peterson
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().
Robert Wilson
reading that felt like being waterboarded
Brayden Torres
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"
Nathaniel Hughes
console.log(Array.apply(null, Array(100)).map((a, b) => (++b%3?'':'Fizz')+(b%5?'':'Buzz')||b).join('\n'));
perfection
Carter Perry
Sounds like a mistake copied from C++.
Ryan Martinez
inbred >>>/reddit/
Charles Harris
That doesn't exist in C++ and isn't a mistake either.
Leo Ramirez
String literals aren't std::string because of backwards compatibility with C.
Christian Johnson
Completely unrelated.
Cooper Stewart
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.
Ethan Taylor
Sweet quads, mate.
Aiden Jones
>Sans-serif fonts anywhere Disgusting.
Hudson Ortiz
Thanks my dude, I was afraid nobody noticed for a second there.
Brayden Cook
...
Josiah Martin
Have you tried getting a brain or do you think repeating "I'm clinically retarded! Look at me!" is making you look smart?
Dominic Baker
gr8 retort, m8
Angel Bell
Oh shit, I didn't know Rust had this. Time to jump on the meme train.
Thanks, mods can close the thread now that the defacto solution has been found.
Julian Gomez
If your code has the "FizzBuzz" string, you're doing it wrong.
Nathan Butler
>ruby syntax why
Jack Ross
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?
Thomas Taylor
>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.
Thomas Young
also, what's wrong with ruby syntax?
Isaiah Brown
too oop-y too much trying to be like the english language
Lincoln Sullivan
well, always better than an average Java/C#/PHP cancer.
Nathan Hughes
>Pretending the real performance hurdle isn't printing.
Isaiah Sanchez
Well then, what am I supposed to do? Manually inspect the memory to see the results?
Zachary Diaz
You're supposed to not care because it'll always be slow as fuck
Jackson Campbell
those suffer from similar issues
Henry Watson
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 "";;
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 "";;
Grayson Barnes
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 "";;
Eli Perry
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)
THIS is one good elixir implementation. Also, what's with clojurian-syntax in scheme?
Nathan Sanchez
Retard.
Christopher Price
why?
Colton Scott
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.
Christian Sanchez
>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
Hudson Gonzalez
>doesn't print anything Haskelfags everybody!
Parker Sullivan
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.