95% of /g can't write a program that does this

95% of /g can't write a program that does this.

Attached: the-openclosed-principle-dojo-2-638.jpg (638x491, 48K)

Other urls found in this thread:

themonadreader.files.wordpress.com/2014/04/fizzbuzz.pdf
twitter.com/SFWRedditImages

sage
puts (1..100).map{|i|i%3*i%5==0?(i%3==0?"Fizz":"")+(i%5==0?"Buzz":""):i.to_s}.join(",")

fizzBuzz :: Int -> String
fizzBuzz x
|(x `mod` 3 == 0)&&(x `mod` 5 == 0) = "FizzBuzz"
|(x `mod` 3 == 0) = "Fizz"
|(x `mod` 5 == 0) = "Buzz"
|otherwise = show x

I only just started doing programming, I have no idea how to apply this to each term in the list [1..100]
Do I need recursion?

what the fuck is to_s? How does it know?

I have no idea what language it is, but I guess you should just loop through the range. Languages that support ranges usually support foreach of sorts. If it isn't there - just use the regular loop.
You shouldn't really use recursion when you can get away without using one.

What I mean is, is to_s just" to the end of the map?

.to_s is explicit cast to string in Ruby.

It's haskell, I don't think it has loops in the normal sense

shit i think im part of that 95%

Module FizzBuzz
Sub Main()
Dim I As Integer
For I = 1 to 100
If I mod 15 = 0 Then
Console.WriteLine("FizzBuzz")
ElseIf I mod 3 = 0 Then
Console.WriteLine("Fizz")
ElseIf I mod 5 = 0 Then
Console.WriteLine("Buzz")
Else
Console.WriteLine(I)
End If
Next
End Sub
End Module

wow that was hard

it's ok. Sup Forums is board about a lot of things, not just programming.

Nice post.

> (OP)
>Module FizzBuzz
> Sub Main()
> Dim I As Integer
> For I = 1 to 100
> If I mod 15 = 0 Then
> Console.WriteLine("FizzBuzz")
> ElseIf I mod 3 = 0 Then
> Console.WriteLine("Fizz")
> ElseIf I mod 5 = 0 Then
> Console.WriteLine("Buzz")
> Else
> Console.WriteLine(I)
> End If
> Next
> End Sub
>End Module
>wow that was hard
vb? Really? Lmao shit language learn c# or c++

>c# or c++
You are saying it like they are any fucking similar.

It's interesting to note that the sequence repeats in tuples of 15, so yeah it is possible to do away with modulo since div operations are less efficent.

Why should 100% of Sup Forums be able to write fizzbuzz?
This is a general technology board, not a computer, CS or programming board
Not all technology revolves around computers you autistic fuck

#include
#include

int main(void)
{
for (int i = 1; 1; i++)
{
if (i % 3 == 0 && i % 5 == 0)
{
printf("Op is a faggot, ");
}
else if (i % 5 == 0)
{
printf("faggot, ");
}
else if (i % 3 == 0)
{
printf("Op is a, ");
}
else
{
printf("%i, ", i);
}
Sleep(1000);
}

system("PAUSE");
}

map the function to the array [1..100]

I'm sure OP is glad you guys did his homework for him.

Was pretty tough desu
module Fizz where

data Operation
= Print String
| Skip
| Halt
deriving (Show)

rule :: (Int, String) -> Int -> [Operation] -> [Operation]
rule (i, str) = \x -> if x `mod` i == 0
then \cont -> [Print str] ++ cont ++ [Halt]
else id

fizz :: Int -> [Operation] -> [Operation]
fizz = rule (3, "Fizz")

buzz :: Int -> [Operation] -> [Operation]
buzz = rule (5, "Buzz")

base :: Int -> [Operation] -> [Operation]
base x = \cont -> cont ++ [Print (show x), Halt]

program n = base n . fizz n . buzz n $ [Skip]

interp :: [Operation] -> String
interp = foldr go ""
where
go (Print str) t = str ++ t
go (Skip) t = t
go Halt t = ""

main = mapM_ (putStrLn . interp . program) [1..100]

Guess I'm smarter than 95% of you lol
using System.Math
Private EPSILON As Double = 0.00001
namespace qwerty {
class asdfg {
private sub main(string []argv) {
for (double i = 0; i < 9999999; i++) {
dim msjdkfnk double = 55555;
if ((Round(i/3, 0)-i/3)=epsilon) {
console.write(fizz)
msjdkfnk = 0;
}
if ((round(i/5, 0)-i/3)=epsilon) {
console.write(buzz);
msjdkfnk = 0
}
if (!msjdkfnk) console.write(i);
console.write('\n');
}}}}

If he is just getting the answer from someone else, he is just hurting himself. The code is beyond easy.

there's a paper for that
themonadreader.files.wordpress.com/2014/04/fizzbuzz.pdf

Attached: Prograph FizzBuzz Fizz Buzz.png (1216x629, 65K)

Yeah I read through the paper years ago and wrote an implementation. Was pretty happy I could recall it without having to re-read it.

Yes, but the less brainlets clogging up the board with homework questions, the better. It should never be encouraged or rewarded.

console.log(
Array(100).fill(0).map((a,b) => b).map(function(x) {
var output = "";
if (x % 3 == 0) output += "Fizz";
if (x % 5 == 0) output += "Buzz";
return (output != "") ? output : x;
})
);


not my best work - but that's how I'd do it

yeah, I know the first map function isn't necessary - but I like my shit layed out in a sensible way, as long as performance isn't ans issue

print(" ".join([(i%3==0)*"Fizz"+(i%5==0)*"Buzz" or str(i) for i in range(1,101)]))


Noice m8

Array.apply(null, Array(100)).map((_,i) => i+1).map(x => {
if(x%3===0&&x%5===0) return "FizzBuzz";
if(x%3===0) return "Fizz";
if(x%5===0) return "Buzz";
return x;
}).forEach(x => console.log(x));

Array.apply(null, Array(100))
.map((_,i) => i+1)
.forEach(x => console.log(x%3*x%5===0?(x%3===0?"Fizz":"")+(x%5===0?"Buzz":""):x));

What did he mean by this

console.log(
Array(100).fill(0).map(function(_,n) {
var x = ((n % 3 == 0) ? "Fizz" : "") + ((n % 5 == 0) ? "Buzz" : "");
return (x != "") ? x : n;
})
);


changed it after looking at some stuff you guys did

print(["Fizz" if n%3==0 else "Buzz" if n%5==0 else "FizzBuzz" if (n%3==0) and (n%5==0) else n for n in range(0,20)])

Get fucked OP

U MAD?
for(var i:int=1;i -100)
{
if(variable1 < -100)
{
break;
}
if(variable1 == 0)
{
//yay, i is a multiple of 3
s = "Fizz";
variable2 = "isMultipleOf3";
}
variable1 = variable1 - 3;
}
variable1 = i;
while(variable1 > -100)
{
if(variable1 < -100)
{
break;
}
if(variable1 == 0)
{
//yay, i is a multiple of 3
s = "Buzz";
if(variable2 == multipleOfThree)
{
s = "FizzBuzz";
}
}
variable1 = variable1 - 5;
}
variable2 = "";
trace(s);
}


why yes, I did go to college

I wouldn't even hire a fucking intern to carry coffee around, if he'd write that shit on my whiteboard

thats funny seeing as I work for google

That's some middle school level programming. Why is fizzbuzz a meme? Do they really ask that at job interviews or what?

(* We're using Coq to prove a subset of the FizzBuzz logic, and doing the rest in Haskell. *)
Extraction Language Haskell.

(* In the extraction, we want this to just vanish. *)
Extraction Inline proj1_sig.

(* Types we're importing from Haskell. *)
Extract Inductive sumbool => "Prelude.Bool" [ "Prelude.True" "Prelude.False" ].

Axiom Integer : Set.
Extract Constant Integer => "Prelude.Integer".
Extraction Inline Integer.

Axiom String : Set.
Extract Constant String => "Prelude.String".
Extraction Inline String.

(* We have decidable equality on Integers. *)
Axiom Integer_eq : forall (n m : Integer), { n = m }+{ n m }.
Extract Constant Integer_eq => "(Prelude.==)".
Extraction Inline Integer_eq.

(* A few constants. *)
Axiom zero : Integer.
Extract Constant zero => "0".
Extraction Inline zero.
Notation "0" := zero.

Axiom three : Integer.
Extract Constant three => "3".
Extraction Inline three.
Notation "3" := three.

Axiom five : Integer.
Extract Constant five => "5".
Extraction Inline five.
Notation "5" := five.

Axiom empty : String.
Extract Constant empty => """""".
Extraction Inline empty.

Axiom fizz : String.
Extract Constant fizz => """Fizz""".
Extraction Inline fizz.

Axiom buzz : String.
Extract Constant buzz => """Buzz""".
Extraction Inline buzz.

Axiom nl : String.
Extract Constant nl => """\n""".
Extraction Inline nl.

(* Functions that we're importing from Haskell. *)
Axiom append : String -> String -> String.
Extract Constant append => "(Prelude.++)".
Extraction Inline append.

Axiom mod : Integer -> Integer -> Integer.
Extract Constant mod => "Prelude.mod".
Extraction Inline mod.

Axiom show : Integer -> String.
Extract Constant show => "Prelude.show".
Extraction Inline show.

(* What does it mean for a number to evenly divide another number? *)
Inductive Divides (den num : Integer) : Prop :=
| ModZero : mod num den = zero -> Divides den num
.

Notation "( D | N )" := (Divides D N).

(* Divisibility is decidable. *)
Lemma Divides_dec (den num : Integer) : { ( den | num ) }+{ ~ ( den | num ) }.
remember (mod num den) as m.
remember (Integer_eq m 0) as mzero.
destruct mzero.

left.
apply ModZero.
rewrite e in Heqm.
rewrite Heqm.
reflexivity.

right.
intro contra.
destruct contra.
rewrite H in Heqm.
contradiction.
Qed.
Extraction Inline Divides_dec.

(* The conditions under which we can produce each word. *)
Inductive Fizz (n : Integer) : String -> Prop :=
| EmitFizz : (3 | n) -> Fizz n fizz
| NoEmitFizz : ~(3 | n) -> Fizz n empty
.

Inductive Buzz (n : Integer) : String -> Prop :=
| EmitBuzz : (5 | n) -> Buzz n buzz
| NoEmitBuzz : ~(5 | n) -> Buzz n empty
.

Inductive Show (n : Integer) : String -> Prop :=
| EmitShow : ~(3 | n) -> ~(5 | n) -> Show n (show n)
| NoEmitShow : (3 | n) \/ (5 | n) -> Show n empty
.

Hint Constructors Fizz.
Hint Constructors Buzz.
Hint Constructors Show.

(* We can decide strings which satisfy the above conditions. *)
Lemma Fizz_dec (n : Integer) : { s : String | Fizz n s }.
remember (Divides_dec 3 n) as d3.
destruct d3;
eexists;
auto.
Qed.
Extraction Inline Fizz_dec.

Lemma Buzz_dec (n : Integer) : { s : String | Buzz n s }.
remember (Divides_dec 5 n) as d5.
destruct d5;
eexists;
auto.
Qed.
Extraction Inline Buzz_dec.

Lemma Show_dec (n : Integer) : { s : String | Show n s }.
remember (Divides_dec 3 n) as d3.
remember (Divides_dec 5 n) as d5.
destruct d3, d5;
eexists;
auto.
Qed.
Extraction Inline Show_dec.

(* So, the operation to fizzbuzz a single number. *)
Definition fizzbuzz (n : Integer) : String :=
let fizz := proj1_sig (Fizz_dec n) in
let buzz := proj1_sig (Buzz_dec n) in
let bare := proj1_sig (Show_dec n) in
append fizz (append buzz (append bare nl)).

(* Finally, the code we want to extract. *)
Recursive Extraction fizzbuzz.

print (1)
print (2)
print ('fizz')
print (4)
print ('buzz')
print ('fizz')
print (7)
print(8)
print('fizz')
print('buzz')
print(11)
print('fizz')
print(13)
print(14)
print('fizzbuzz')

I'd continue, but I already proven myself.

Attached: kek.jpg (596x628, 45K)

a friend of mine has been asked to do it at one recently

(position was for a web-dev with react and node-js experience)

It's unironically one of the better tests for a live challenge.

Bring out some autistic challenge that's supposed to be "hard" and literally noone will do it. Even if they are generally capable, it will have to be a take home test to get them in the right mindset.

Kek, vb. Just go and learn c# if you want the same stuff, but not in shit syntax.

Duh, because they are? c# is c++++, thus it can be used as c++, but it has way more stuff.

Attached: Screenshot_20180319-132427.jpg (645x475, 25K)

>/g
This isn't Reddit, op.

It pretty unequivocally does.

const amount = 100;
const rules = [{
factor : 3,
word : "Fizz"
}, {
factor : 5,
word : "Buzz"
}];
var output = Array(amount).fill(0).map(function(_,number) {
var wordchain = "";
rules.forEach(function(rule) {
if (number % rule.factor == 0) wordchain += rule.word;
});
return (wordchain != "") ? wordchain : number;
});
console.log(output);


I had to improve my shit a bit more - just because of being a fucking autist

I'm pretty sure that's the type of answer an interviewer is looking for though

I got the FizzBuzz assignment at a job interview once. I got all angry because I thought they gave me a simple task because I am female. They told me most applicants could not solve it, even if they got to freely pick which language they wanted. I was pretty stunned at this. It is really simple to solve in just plain Java.

>"Yay"
The fuck am I reading?

import com.mybuzzer.FizzBuzzer;

public class MyFizzBuzz {

public static void main(String[] args) {
FizzBuzzer fb = new FizzBuzzerFactory.getFizzBuzzer();
fb.add("Fizz", 3);
fb.add("Buzz", 5);
fb.linkBuzzers("Fizz", "Buzz");

for (int i = 0; i < 100; i++) fb.buzz(i);
}
}

:^)

kek
based java

fizzbuzz = range(1,91)
for number in fizzbuzz:
if number % 3 == 0 and number % 5 == 0:
print('FizzBuzz')
elif number % 3 == 0:
print('Fizz')
elif number % 5 == 0:
print('Buzz')
else:
print(number)


### im a beginner python is my first language

You clearly don't know what C# is, do you?
Even C99 Standard says it just wants to maximize interoperability, not to allow code to be used as another similar lang

Attached: scr.png (1015x196, 36K)

its indented it just doesnt appear so on here

use [*code]*insert code here*[*/code] without the * to put it in the white box thing, letting you use indentation

int main(int argc, char **argv)
{
(void)argc, (void)argv;
char *f[] = {"Fizz","Buzz"}; for (size_t i = 0; i < 100; i++) { char buf[1024] = {0}, *p = buf; if (i % 3 == 0) sprintf(p, "%s", f[0]); size_t j = snprintf(0, 0, "%s", f[0]); if (i % 5 == 0) sprintf(p + j, "%s", f[1]); if (!strlen(p)) printf("%d\n", i); else puts(p); }

return 0;
}

lmao this nigga actually used haskell fuck

cheers m8

Average poster on Sup Forums
>posts code
Female (?) postress on Sup Forums
>doesn't post code
>"it's easy"
>"btw I have a vagina"

I think it's funny, some bitch freaking out at an interviewer for giving her an often used question thinking they are sexist.

Forced positivity of your typical goofaggot intern.

public class MyClass {

public static void fizzbuzz(int x){
for(int i = 1; i

You need to rethink the whole i mod 3 and i mod 5 both equals 0 thing.

Nvm

lol dumb

Why? I'm pretty sure I'm right. I'm a maths grad who's currently long term unemployed.

>technology is only and purely autistic grinding of numbers and words in certain patterns
cars are also technology and I doubt your pussy ass would be able to fix one, so what are you doing on Sup Forums?

everyone who implements every check twice already failed the interview, as far as I'm concerned

the usual next thing to ask, after letting them write out fizz buzz code on the whiteboard, is to let them add additional rules to it, and after that make them change a rule or the order they are applied in

code like or scales horribly.

what I personally like to see is something abstracted out, like which would get perfect marks from me
(I'd personally use reduce() instead of forEach() there, but that's more style than anything)

and are the most impressive solutions though

Attached: rejection.jpg (425x282, 150K)

In Python:
i=0;exec"print i%3/2*'Fizz'+i%5/4*'Buzz'or-~i;i+=1;"*100

if(i%15==0){
System.out.print("fizzbuzz, ");
}


Better?

>everyone who implements every check twice already failed the interview, as far as I'm concerned
so I'd fail an interview?

I just use the FizzBuzz.com API to get FizzBuzz as a service

Scalable is just code word for easy to replace you with someone else desu

anyone who prematurely starts using java abstractions is clearly a certified pajeet and your warning signs and alarms should be going off at full volume

not necessarily, but I'd like to see you change your approach after I tell you to implement two more rules

>after I tell you to implement two more rules
Which would be?

public static void fizzbuzz(){
for(int i=1;i

for (let i = 1, msg; i

for (int i = 1; i

Why define msg in the for? You save one character by just letting it within the scope.
Teach me.

something like "Boom" for every multiple of 7 and "Clank" for every multiple of 11

after that, I'd like to change the order the words are combined in.
(i.e. BuzzFizz instead of FizzBuzz, but the same otherwise)

that's also why solutions like shine

however - almost nobody can come up with something like that on the spot at the whiteboard.

Am European.That question is not common in my country jackass.

Oh sorry I didn't realize this was 'brag about your ability to solve a basic coding 101 problem' thread.

Because then, 'msg' is limited to the 'for' scope. I don't want 'msg' to be used again outside that loop, and writing inside the loop let msg = ''; (as if every iteration a new variable is created) doesn't look right. Any more questions?

why the 8th grade comp. sci questions? are you underage OP? if so, hmu for an assfucking. you'll be fucking my ass.

And just adding those to the existing code would be wrong?

if you're code looks like or yeah

it shows that you're not good at planning ahead and re-evaluating your approach when presented with new circumstances

And how does this differ from a sort of premature optimization or feature creep?
You can expect some sure, but not all. I can see how doing that on paper looks fine, but then you have programmers overcompensating everything they do for potentially no turnaround.
Even if limited to an interview question, you're setting a precedent.

I somewhat agree - that's why I'd set up something like a FizzBuzz task in an interview as multipart task

I wouldn't fault you for botching it in the first stage. that's fast, you're nervous and you have no idea I'm going to give you additional rules to implement afterwards

however, I expect you to stop and think about what you're doing if you really end up writing all condiitions for 4 rules on the whiteboard in a botched approach.

I mean, just try it out now.
You'll realize very quickly that it's not the best way to do this. I wouldn't even care much if you can't come up with anything abstracted out on the spot, as long as you realize and communicate that another approach would be better here

perl -e 'say "Fizz"x!($_%3)."Buzz"x!($_%5)||$_ for 1..100'

foo = range(1,100)
for i in foo[::3]:
foo[i] = 'Fizz'

for i in foo[::5]:
foo[i] = 'Buzz'

for i in foo[::15]:
foo[i] = 'FizzBuzz'

for i in foo:
print(i)


is easy

All these answers look ugly and repetitive. We need languages with less boilerplate and better abstractions. Notation as a tool of thought.

+[-[>+--[>+>++>++>++++++>+>>>++++++>->++>+>>--[[>]>[[>++++++++++[->++++++++++>+ [>>>]++++++++++>+>]]++++++++[-]]

Forgot pic

Attached: shitpost.png (480x800, 42K)

I've heard stories of CS graduates failing this. Assuming the candidate's degree is "real" (i.e. not literally forged), how is that possible? Surely it's not possible to graduate without writing a shitton of code and taking enough maths classes to be well aware of modular arithmetic?

I'm self-taught with no formal qualifications at all, and every time I read one of these stories, I wonder why I haven't found a real job yet. Do I just need to give in and go get that degree, even though it apparently has no predictive value re. actual programming ability?

If this is an actual assignment you give people time for that's fine, but if you are expecting someone to whiteboard a perfect solution after you put them on the spot in an interview situation you are completely delusional and do not know what to look for.
You do those kind of questions to see someone's process, the end result doesn't even fucking matter as long as it works.

33oFizz!qqaBuzz!5kq19@q:%s#^$#\=line('.')

Attached: fizz.webm (1000x630, 233K)