94

# I challenged my girlfriend (and myself) for the FizzBuzz thingy. I did it in js (because I suck at js) and she in Java. I never saw such a way to write FizzBuzz. Turns out she forgot there is a thing called modulo operator. I know there are more elegant ways to solve it! Feel free to post your favorites.

• 15
Your girlfriend has a natural talent for DP
• 17
13 lines, but i can make it less probably
• 2
• 20
yeah, down to 7
• 2
@Alice wait hold on, i may be down to 4 lines
• 23
eh, 5 :/
• 20
@sharktits It's not about lines. I can put a 10.000 line js code in one line xD

Yea but I know this approach too (from our dear lord Tom Scott)
• 2
@BambuSource yeah, i separated logical parts into lines, and kept the standard sybtax for that reason
• 9
Yay R
• 5
Not my code, but I love how concise Haskell can be:

```

fizzbuzz :: Int -> String

fizzbuzz n = (test 3 "fizz" . test 5 "buzz") id (show n)

where test d s x | n `mod` d == 0 = const (s ++ x "")

| otherwise = x

```
• 8
My favourite implementation:
https://github.com/EnterpriseQualit...
• 7
@BambuSource ++ for Tom Scott.

Do you watch citation needed?
• 31
cmon guys
• 6
@sharktits @ObiSwagKenobi huh?
• 2
@AlexDeLarge Go hard or use for() :b
• 6
@AlexDeLarge why are you alice
• 1
@sharktits @Alice
• 1
@Alice i am going to fucking gut you mate
• 7
@AlexDeLarge @Alice

I am so confused...
• 2
@daintycode that still counts as 3 lines :>
• 5
for(let i=1;i<101;i++)console.log(((i%3?'':'Fizz')+' '+(i%5?'':'Buzz')).trim()||i)
• 3
@sharktits i did it like that too (I have it somewhere on my youtube channel)

Tho I saw somebody who made it in Haskell (can't remember exactly which language).
It didn't compile, but the error was genious, as the error log itself was the fizzbuzz
• 1
@Meta is this even fucking valid and/or does what it is intended to do?
• 2
@daintycode yes, it's doing the FizzBuzz thing ¯\_(ツ)_/¯ and yes, I came up with that
• 1
@Meta dude i completely misread it. Nice.👌
• 0
@ObiSwagKenobi i liked your solution but "FizzBuzz" is not a correct output
• 1
@bioDan FizzBuzz is the only thing making it so hard to make it a one-liner.

http://wiki.c2.com/?FizzBuzzTest
• 2
@daintycode oh lol thanks!
I got confused by OP's gf code.
Apologies @ObiSwagKenobi

• 1
Hmm, if the space is not valid, then I got wrong intel when I read about it the other day and made that code up there for it 😯
• 2
for (int i = 0; i < 100; i++) {
string output = “”;
if (i% 3 == 0) output += “fizz”;
if (i % 5 == 0) output += “buzz”;

if (output == “”) output = i;
Console.WriteLine(output);
}
• 1
@bioDan no worries! Glad you liked my solution 🙂
• 0
@norman70688 global golf
• 2
let Ruby set you free

(0..100).each do |i|
p "#{i} #{i % 3 == 0 ? 'Fizz' : ''}#{i % 5 == 0 ? 'Buzz' : ''}"
end
• 0
@ewpratten I watched it once. No idea what it is/was about but it was hell of funny

@AlexDeLarge @Alice
I don't know if I love or hate you
• 4
@BambuSource
I have watched all of them. Really funny.
• 1
🍦
• 0
@sladuled What do you want to tell me? xD
• 0
@BambuSource nothin, custom pin xD currently still at work in deep shit, but rant looks interesting xD
• 0
Couple of ways of doing it that I've got in F#.

First is probably the one I prefer, although the second one is a nice demo of active patterns.
• 0
@AlexDeLarge one of my favourite things there (total nerd) is that the (printfn "%s") is actually type checked at compile time.

F# does some magic with format strings where they become functions in their own right, so if you're not pumping the correct types into the function using the format string the compiler will moan.
• 0
@AlexDeLarge I find myself constantly writing up versions of the common monads etc when I'm working on a C# project as well.

I find working without certain functional luxuries a real pain these days.
• 0