What is really brilliant here, aside of the naive (yet perfect) answer, is the ordering of the results in columns that highlights the pattern of this algorithm
For someone who has no idea what fizzbuzz is, what this person did is not an unreasonable interpretation of the instructions. Technical interviews are often full of arbitrary seemingly unrelated questions brought on by interviewers who think they're being clever so it's hard to figure out what they actually want out of it.
It only looks stupid when you know what fizzbuzz is and fill the unwritten instructions in mentally. So in the end it's pretty much asking "Do you know what fizzbuzz is well enough to fill in the missing instructions?"
To be completely fair, this interpretation is the only reasonable interpretation of what the question asks... if you take it literally. If you write out some code on a piece of paper that code is never going to actually "print" anything. But writing the numbers out is printing them... the question should really just be worded:
"Write pseudocode (or java or whatever) which will ... [etc]"
It took me a good minute or two to figure out what he did wrong and I'm pretty sure I've heard of fizzbuzz at least in passing...
Technically what's written there is already a form of pseudocode, I think the person writing the answer interpreted the question as "evaluate this pseudocode".
Yeah, honestly I had to come in to the comments to see why this was funny...I mean, I'm just learning to program and have obviously never had an interview, but were I presented with that piece of paper I wouldn't know what to do other than what the person in the picture did.
FizzBuzz is a common question asked by interviewers. The task is really easy and can be solved by good programmers in minutes, the purpose is only to filter out people who don’t have any clue of what they’re doing.
Generally, the task is: Write a program that prints the result shown in the image, but the instructions didn’t mention the "program" part, so OP read it literally and just wrote the expected result, as asked.
This would be a whole lot funnier to me if we hadn't had like 30 people come though interviews like this. The number of people who apply for development jobs with no programming knowledge blows me away.
If it really bothers you so much why not just re-write the question so it's not ambiguous? To me, this shows nothing of a lack of programming knowledge. If it were not ambiguously worded, someone wouldn't even have to know what "fizzbuzz" is to work this out. It's really easy... just put "write code such that" in front of it...
How do they get interviews though? Don't most employers want a Github link, experience, a relevant degree, or anything indicating that the applicant is familiar with what they're applying for?
Yeah? You get tons of these people in interviews, and I, who have an extensive github history proving how capable I am, don't even get the interview...
The problem with common knowledge is that it's not as common as you'd think. Everyone has a first time learning something. Of course you've seen the relevant XKCD comic? Of course you have.
Also if it really were universally known, it would be entirely possible to get around it without knowing what you're doing by memorising a piece of code.
Was it a development job?? Even if he is not familiar with FuzBuzz and even if the task didn't specifically said "write a code", the '"print" the numbers" is a give away of , mostly common, print functions and hence it assumes, print - using code. It didn't say "write numbers".
I understand how he got confused, but through half of the task he should've realized that something is wrong.
Just search the web for a FizzBuzz jQuery plugin, then spend the rest of the day trial-and-erroring your way through all the settings for that plugin, so it matches the 3 and 5 requirements... good enough.
EDIT: For the hell of it, I went ahead and did a low level C implementation for an arduino uno. Except I didn't use their libraries and it's mostly from scratch.
If they aren't in programming jobs that's fine. I know some really good network engineers that couldn't write a line code to save their lives. That's what we are here for.
I had to come to the comments to understand why this was wrong and what it had to do with computing.
Nowhere on the page that I can see does it say to write an algorithm to do it, it literally says"do this". I would have done the same thing and thought it was the most pointless exercise ever.
In all fairness, if it was a programming job and had I never heard of fizzbuzz, I would have assumed that they wanted pseudo-code simply from context and the use of the term 'print'.
Would have been better if they actually requested pseudo-code though as this is a literal interpretation and not technically incorrect.
Nah, not interview questions. Instead, a peek inside the heads of hiring managers so your job search can be more efficient. Fizz Buzz comes from the coding horror blog which tends to be informative and entertaining. I've found that there's rarely a direct approach when looking for a new position.
Is this seriously an interview question? I'm a 16 year old with little/no Java experience and this looks way too easy. For loop, if/else if/else statement, modulo operator, done.
This sort of question is routinely used during interviews as a first question because when you have an open programmer position you get a staggering number of applicants who do not actually know how to program. So by asking a question like this and immediately disqualifying anyone who can't write a reasonable solution to it within ~5 minutes, you save a ton of time by not having to actually interview people who had no business applying in the first place.
While their answer perfectly follows the vague instructions, it shows the candidate failed this part of the interview.
Why? Because before blindly doing the task, they didn't think about the larger context (in a programming interview, no one cares about your ability to act out non-code instructions), what was more likely to have been meant (even if it wasn't specifically specified), and didn't ask any clarifying questions. In the real world, instructions will be vague more often then not.
(Granted, you can fail one part of an interview and potentially still get a job offer, especially if you do very well on other aspects).
for (int i = 1; i <= 100; i++)
{
if (i % 3 == 0 && i % 5 == 0) print("FizzBuzz");
else if (i % 3 == 0) print("Fizz");
else if (i % 5 == 0) print("Buzz");
else print(i);
}
Programming Student early in academic career who has never seen this test or heard of it. Am I being stupid to think just written else if in between the lines of instructions isn't sufficient enough? I assume because he didn't write code the tester gave him free will to write what he thought answer was and wouldn't it of just been easier or ok to show pseudo?
Writing "else if" between the lines would not work... in this order. Consider the case where the number is 45. The first test would evaluate to true and it would print "Fizz", yet it should have printed "FizzBuzz".
The proper else-if based approach would be to test the 3+5 case first, then hit 3 and 5 separately with else-ifs.
Another strategy is to check 3 then 5 with if statements and not worry about 3+5. If a number is divisible by both, "FizzBuzz" gets printed since they both triggered. The issue there, of course, is that you have to put the newline at the end of the loop block, not in the print statements.
I had to complete this question a couple times in my interviews fresh out of university, so I've given it a fair bit of thought.
After reading your explanation then rereading problem I completely see where I went wrong. Thank you for explanation and even showing two separate ways.
I decided to see whether I could still do this. After a slight issue with having the mod 3 catch before the mod 3 && mod 5, I made this in Python really quickly. I've never done FizzBuzz in Python.
for elem in range(1, 101):
if elem % 3 == 0:
if elem % 5 == 0:
print "FizzBuzz"
else:
print "Fizz"
elif elem % 5 == 0:
print "Buzz"
else:
print elem
I tried finding you a good authoritative source using it (such as PEP 8), but haven't been able to find one. Otherwise, The Zen of Python encourages flat coding over nested coding, and in general, it is good Python tradition to avoid being needlessly superfluous if it makes sense to condense code. This obviously fits the bill, since it saves you an if/else statement in favor of a simple Boolean statement. I could dig around and see if there's any trusted Python code that does this if I had time.
The more I look at it, the more I feel like accepting it as okay style, but it still looks weird to me. It makes so many assumptions about truthish values and short-circuiting behaviour and the return value of boolean operators so on. I mean, you need the empty string to be falseish, you need or to short-circuit and you need or to return the value of the first truthish argument – otherwise the last one. Maybe I'm just not used to it.
Edit: I just asked a bunch of Python programming friends and they all instinctively said, "Go for the or expression!" but when they looked at it closer they started to question whether they even gave the same result. While they do give the same result, I think their doubt speaks for avoiding it in production code.
the only time i've done it i did it in python, but that was almost 4 years ago and i can read what you've written, but unsure if i could have written it myself anymore :/
I misunderstood the question and tried doing this without division, but it grew convoluted really quickly (save all states and keep track of them)... and then I got bored. Happened several years ago, so I have never in my life completed FizzBuzz.
In case you haven't seen it before, you should check out /r/dailyprogrammer. They post a problem of roughly this difficulty every Monday. It's pretty fun and good practice.
I assume they'd let you do it in any language you choose. The intent behind this (I assume) is to test your logical problem solving using code, rather than proficiency in any given language.
While FizzBuzz originally was intended to be done this way to teach children about division, it has been widely adopted by interviewers to test an applicant's programming skills. The asssumption made by the interviewer in OP's friend's situation is that the friend is aware of this and thus wouldn't need to be told that he needs to solve it using code.
Fizz buzz has been used as an interview screening device for computer programmers. Creating a list of the first 100 Fizz buzz numbers is a trivial problem for any would-be computer programmer, so interviewers can easily sort out those with insufficient programming ability.
Adults may play Fizz buzz as a drinking game, where making a mistake leads to the player having to make a drinking-related forfeit.
about|/u/Sargeron can reply with 'delete'. Will also delete if comment's score is -1 or less.|To summon: wikibot, what is something?
Since the else if is following if (divisibleBy5), you don't really need to check !divisibleBy5 in it.
Edit: Also, since after making that change you'd then only be using divisibleBy5 once, you might as well just put the calculation directly into the if statement to free up that variable. But yours is really fine like it is for readability.
I've never seen this problem and I could immediately tell that the intent was to have the person write code to do it. I mean, I would write a program anyway. Also, the use of the word 'print'. Am I the only one?
You know those times during an interview when you get a problem that you can easily solve and therefor get relaxed and decide to initially break a related joke, try getting a smile from the interviewer, show some social skills and that you grasp not only the direct problem but also several different solutions and possible pitfalls.
This is clever. Actually there was a problem where someone wanted to know if all the numbers from 1 to some large number was Prime. the large number was under 100,000
So I wrote the program, and then left a second answer. I used the first program to generate the answers into a file, used that output as a array, (depending the number they pushed, I would output X of the array up to that number) and just posted that as my answer. Explaining the answer (Just looking up the first 100,000 values is faster than the sieve of eratosthenes.)
The question emphasized speed over algorithm, but I forgot what happened with the interview so I have no idea if that was the better answer.
To be fair, this pseudo-code is by far the fastest implementation. It doesn't have the overhead of a loop, nor the expensive modulo and comparison operations.
If the question was to optimize for speed, this is exactly how I would do it (except maybe a "printf" or something similar preceding each line.
public void main()
{
FizzTheBuzz(["Fizz", "Buzz", "FizzBuzz"], [3, 5, 15], 100);
}
/// <summary>
/// Takes a collection of strings and ints.
/// If any number below count is divisible by any of the conditions, it outputs
/// the matching text in the output array. The length of output and conditions
/// must be the same.
/// </summary>
/// <param name="outputs">What to say if there's a match</param>
/// <param name="conditions">On what numbers do you want to say an output?</param>
/// <param name="count">How high to you want to count</param>
public void FizzTheBuzz(string[] outputs, int[]conditions, int count)
{
if (output.Length != conditions.Length)
{
Console.WriteLine("The lengths of outputs and conditions don't match.");
return;
}
for (int i = 0; i < count; i++)
for (int i1 = 0; i1 < conditions.Length; i1++)
Console.WriteLine((i % conditions[i1] == 0) ? outputs[i1] : i);
}
EDIT: what is wrong with me? Maybe it's just because it's Saturday and I don't want to do work.
n = 1
while n<=100:
fizz = n % 3 == 0
buzz = n % 5 == 0
if fizz and buzz:
print "FizzBuzz"
elif fizz:
print "Fizz"
elif buzz:
print "Buzz"
else:
print n
n += 1
for(int i = 1; i <= 100; i++)
{
if (i % 3 == 0) System.Console.WriteLine("Fizz");
if (i % 5 == 0) System.Console.WriteLine("Buzz");
if (i % 3 == 0 && i % 5 == 0) System.Console.WriteLine("FizzBuzz");
}
Console.ReadLine();
The read out is the same thing and unless you're running this calculation one hundred thousand times per millisecond, I'm not sure it would make big difference other than the few characters you saved typing. In which case, it might also be better not to use "System.Console.Writeline()" 3 times but instead assign a string variable string s; [...] s = "Fizz" etc, [...]WriteLine(s); etc etc. for a net savings in typed characters.
<?php
$text = <<<FIZZBUZZ
int i = 1;
while (i <= 100) {
if (i == 1) {
System.out.println("1");
} else if (i == 2) {
System.out.println("2");
} else if (i == 3) {
System.out.println("FIZZ");
} else if (i == 4) {
System.out.println("4");
} else if (i == 5) {
System.out.println("BUZZ");
} else if (i == 6) {
System.out.println("FIZZ");
} else if (i == 7) {
System.out.println("7");
} else if (i == 8) {
System.out.println("8");
} else if (i == 9) {
System.out.println("FIZZ");
} else if (i == 10) {
System.out.println("BUZZ");
} else if (i == 11) {
System.out.println("11");
} else if (i == 12) {
System.out.println("FIZZ");
} else if (i == 13) {
System.out.println("13");
} else if (i == 14) {
System.out.println("14");
} else if (i == 15) {
System.out.println("FIZZBUZZ");
} else if (i == 16) {
System.out.println("16");
} else if (i == 17) {
System.out.println("17");
} else if (i == 18) {
System.out.println("FIZZ");
} else if (i == 19) {
System.out.println("19");
} else if (i == 20) {
System.out.println("BUZZ");
} else if (i == 21) {
System.out.println("FIZZ");
} else if (i == 22) {
System.out.println("22");
} else if (i == 23) {
System.out.println("23");
} else if (i == 24) {
System.out.println("FIZZ");
} else if (i == 25) {
System.out.println("BUZZ");
} else if (i == 26) {
System.out.println("26");
} else if (i == 27) {
System.out.println("FIZZ");
} else if (i == 28) {
System.out.println("28");
} else if (i == 29) {
System.out.println("29");
} else if (i == 30) {
System.out.println("FIZZBUZZ");
} else if (i == 31) {
System.out.println("31");
} else if (i == 32) {
System.out.println("32");
} else if (i == 33) {
System.out.println("FIZZ");
} else if (i == 34) {
System.out.println("34");
} else if (i == 35) {
System.out.println("BUZZ");
} else if (i == 36) {
System.out.println("FIZZ");
} else if (i == 37) {
System.out.println("37");
} else if (i == 38) {
System.out.println("38");
} else if (i == 39) {
System.out.println("FIZZ");
} else if (i == 40) {
System.out.println("BUZZ");
} else if (i == 41) {
System.out.println("41");
} else if (i == 42) {
System.out.println("FIZZ");
} else if (i == 43) {
System.out.println("43");
} else if (i == 44) {
System.out.println("44");
} else if (i == 45) {
System.out.println("FIZZBUZZ");
} else if (i == 46) {
System.out.println("46");
} else if (i == 47) {
System.out.println("47");
} else if (i == 48) {
System.out.println("FIZZ");
} else if (i == 49) {
System.out.println("49");
} else if (i == 50) {
System.out.println("BUZZ");
} else if (i == 51) {
System.out.println("FIZZ");
} else if (i == 52) {
System.out.println("52");
} else if (i == 53) {
System.out.println("53");
} else if (i == 54) {
System.out.println("FIZZ");
} else if (i == 55) {
System.out.println("BUZZ");
} else if (i == 56) {
System.out.println("56");
} else if (i == 57) {
System.out.println("FIZZ");
} else if (i == 58) {
System.out.println("58");
} else if (i == 59) {
System.out.println("59");
} else if (i == 60) {
System.out.println("FIZZBUZZ");
} else if (i == 61) {
System.out.println("61");
} else if (i == 62) {
System.out.println("62");
} else if (i == 63) {
System.err.println("FIZZ");
} else if (i == 64) {
System.out.println("64");
} else if (i == 65) {
System.out.println("BUZZ");
} else if (i == 66) {
System.out.println("FIZZ");
} else if (i == 67) {
System.out.println("67");
} else if (i == 68) {
System.out.println("68");
} else if (i == 69) {
System.out.println("FIZZ");
} else if (i == 70) {
System.out.println("BUZZ");
} else if (i == 71) {
System.out.println("71");
} else if (i == 72) {
System.out.println("FIZZ");
} else if (i == 73) {
System.out.println("73");
} else if (i == 74) {
System.out.println("74");
} else if (i == 75) {
System.out.println("FIZZBUZZ");
} else if (i == 76) {
System.out.println("76");
} else if (i == 77) {
System.out.println("77");
} else if (i == 78) {
System.out.println("FIZZ");
} else if (i == 79) {
System.out.println("79");
} else if (i == 80) {
System.out.println("BUZZ");
} else if (i == 81) {
System.out.println("FIZZ");
} else if (i == 82) {
System.out.println("82");
} else if (i == 83) {
System.out.println("83");
} else if (i == 84) {
System.out.println("FIZZ");
} else if (i == 85) {
System.out.println("BUZZ");
} else if (i == 86) {
System.out.println("86");
} else if (i == 87) {
System.out.println("FIZZ");
} else if (i == 88) {
System.out.println("88");
} else if (i == 89) {
System.out.println("89");
} else if (i == 90) {
printf("FIZZBUZZ");
} else if (i == 91) {
System.out.println("91");
} else if (i == 92) {
System.out.println("92");
} else if (i == 93) {
System.out.println("FIZZ");
} else if (i == 94) {
System.out.println("94");
} else if (i == 95) {
System.out.println("BUZZ");
} else if (i == 96) {
System.out.println("FIZZ");
} else if (i == 97) {
System.out.println("97");
} else if (i == 98) {
System.out.println("98");
} else if (i == 99) {
System.out.println("FIZZ");
} else if (i == 100) {
System.out.println("BUZZ");
}
i += 1;
}
FIZZBUZZ;
echo $text;
?>
for i=1,26 do
if i==1 then print("<?php") end
if i==2 then print("printf(\"<?php\n\");") end
if i==3 then print("printf(\"\$text = <<<FIZZBUZZ\n\");") end
if i==4 then print("printf(\"\t\ti += 1;\n\");") end
if i==5 then print("printf(\"\t\twhile (i <= 100) {\n\");") end
if i==6 then print("for($i = 1; $i <= 100; $i++){") end
if i==7 then print("\t$res = \"\";") end
if i==8 then print("\tif(!($i % 3) || !($i % 5)){") end
if i==9 then print("\t\tif(!($i % 3))") end
if i==10 then print("\t\t\t$res = \"FIZZ\";") end
if i==11 then print("\t\tif(!($i % 5))") end
if i==12 then print("\t\t\t$res .= \"BUZZ\";") end
if i==13 then print("\t}") end
if i==14 then print("\telse{") end
if i==15 then print("\t\t$res = $i;") end
if i==16 then print("\t}") end
if i==17 then print("\tprintf(\"\t\t%s (i == %s) {\n\", $i == 1 ? \"if\" : \"} else if\", $i);") end
if i==18 then print("\tprintf(\"\t\t\tSystem.out.println(\\"%s\\");\n\", $res);") end
if i==19 then print("}") end
if i==20 then print("printf(\"\t\t}\n\");") end
if i==21 then print("printf(\"\t\ti += 1;\n\");") end
if i==22 then print("printf(\"\t}\n\");") end
if i==23 then print("printf(\"FIZZBUZZ;\n\");") end
if i==24 then print("printf(\"echo \$text;\n\");") end
if i==25 then print("printf('?>');") end
if i==26 then print("?>") end
end
public void performGenerationForCurrentStep(SingleStepOutputGenerationParameter generationParameter) {
final int nGenerationParameter = generationParameter.retrieveIntegerValue();
if (myFizzStrategy.isEvenlyDivisible(nGenerationParameter)) {
myFizzStringPrinter.print();
}
if (myBuzzStrategy.isEvenlyDivisible(nGenerationParameter)) {
myBuzzStringPrinter.print();
}
if (myNoFizzNoBuzzStrategy.isEvenlyDivisible(nGenerationParameter)) {
myIntIntegerPrinter.printInteger(nGenerationParameter);
}
myNewLinePrinter.print();
}
public class FizzBuzz {
public static void main(String[] args) {
for(int i = 1; i < 101; i++){
if(i%3 == 0 && i%5 == 0){
System.out.println("FizzBuzz" + " (" + i + ")");
}else if(i%3 == 0){
System.out.println("Fizz" + " (" + i + ")");
}else if(i%5 == 0){
System.out.println("Buzz" + " (" + i + ")");
}else{
System.out.println(i);
}// end if/else
}// end for
}// end main
}// end class
128
u/zebishop Jan 16 '14
What is really brilliant here, aside of the naive (yet perfect) answer, is the ordering of the results in columns that highlights the pattern of this algorithm
149
u/novagenesis Jan 16 '14
What does an employer expect when they ask the FizzBuzz question in a way only completely unambiguous to someone who knows the FizzBuzz question?
Why not just say "hey, can you do fizzbuzz?"
48
u/matterball Jan 16 '14
None of these answers are going to make it in the Real World. Here's a reusable enterprise quality solution for this problem: https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition
204
u/paranoid_twitch Jan 16 '14
This would be a whole lot funnier to me if we hadn't had like 30 people come though interviews like this. The number of people who apply for development jobs with no programming knowledge blows me away.
103
u/tohryu Jan 16 '14 edited Jan 17 '14
I had to come to the comments to understand why this was wrong and what it had to do with computing.
Nowhere on the page that I can see does it say to write an algorithm to do it, it literally says"do this". I would have done the same thing and thought it was the most pointless exercise ever.
17
u/boxingdog Jan 16 '14
Correct answer -> https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition
9
u/absurdlyobfuscated Jan 16 '14
Aren't we being too literal?
17
u/ehmpsy_laffs Jan 16 '14
A project manager is born.
8
u/katyne Jan 16 '14
guise... you guise... monoids
no srsly
7
u/thomplinds Jan 16 '14
had to answer this question for my first ever professional job, this is extremely entertaining
7
u/rohanivey Jan 17 '14
My friend looked over my shoulder at this, "What language did they want it in?"
"I'm guessing not English."
6
u/[deleted] Jan 21 '14
Is this seriously an interview question? I'm a 16 year old with little/no Java experience and this looks way too easy. For loop, if/else if/else statement, modulo operator, done.
24
u/djimbob Jan 16 '14
While their answer perfectly follows the vague instructions, it shows the candidate failed this part of the interview.
Why? Because before blindly doing the task, they didn't think about the larger context (in a programming interview, no one cares about your ability to act out non-code instructions), what was more likely to have been meant (even if it wasn't specifically specified), and didn't ask any clarifying questions. In the real world, instructions will be vague more often then not.
(Granted, you can fail one part of an interview and potentially still get a job offer, especially if you do very well on other aspects).
4
u/Kazinsal Jan 16 '14
My favourite way to do FizzBuzz involves nesting ternary operators.
A lot of people don't even think it's real code.
4
u/martinmine Jan 17 '14
7
u/[deleted] Jan 16 '14
Programming Student early in academic career who has never seen this test or heard of it. Am I being stupid to think just written else if in between the lines of instructions isn't sufficient enough? I assume because he didn't write code the tester gave him free will to write what he thought answer was and wouldn't it of just been easier or ok to show pseudo?
10
u/KBKarma Jan 16 '14
I decided to see whether I could still do this. After a slight issue with having the mod 3 catch before the mod 3 && mod 5, I made this in Python really quickly. I've never done FizzBuzz in Python.
3
u/takatori Jan 17 '14
It's a trick question: they were checking to see if he would use cursive instead of printing.
8
u/Chemical_Scum Jan 16 '14
dick stuck in FizzBuzz?
2
u/[deleted] Jan 16 '14
They didn't specify a language, was i supposed to write it in pseudo code?
2
u/[deleted] Jan 16 '14
I am so lost. What is this? It looks like they did it right to me.
2
u/Xiver1972 Jan 17 '14
There are so many ways to answer this question...
4
u/thereddarren Jan 16 '14
And now I wait for smarter people to tell me what's wrong with it.
3
u/pirate_platypus Jan 16 '14
Since other people have tossed in their version, here's my submission for the silliest way to do it (Python 3)
[("FizzBuzz" if x % 15 == 0 else ("Buzz" if x % 5 == 0 else ("Fizz" if x % 3 == 0 else x))) for x in range(1, 101)]2
u/DemiReticent Jan 16 '14
I've never seen this problem and I could immediately tell that the intent was to have the person write code to do it. I mean, I would write a program anyway. Also, the use of the word 'print'. Am I the only one?
2
u/cypr Jan 16 '14
You know those times during an interview when you get a problem that you can easily solve and therefor get relaxed and decide to initially break a related joke, try getting a smile from the interviewer, show some social skills and that you grasp not only the direct problem but also several different solutions and possible pitfalls.
Yeah, I don't think this is such a time.
1
u/Sakuya_Lv9 Jan 16 '14
I got this:
12Fizz4BuzzFizz78FizzBuzz11Fizz1314FizzBuzz1617Fizz19BuzzFizz2223FizzBuzz26Fizz2829FizzBuzz3132Fizz34BuzzFizz3738FizzBuzz41Fizz4344FizzBuzz4647Fizz49BuzzFizz5253FizzBuzz56Fizz5859FizzBuzz6162Fizz64BuzzFizz6768FizzBuzz71Fizz7374FizzBuzz7677Fizz79BuzzFizz8283FizzBuzz86Fizz8889FizzBuzz9192Fizz94BuzzFizz9798FizzBuzz(hint: not println)
1
u/[deleted] Jan 16 '14
Q
1
u/Kinglink Jan 16 '14
This is clever. Actually there was a problem where someone wanted to know if all the numbers from 1 to some large number was Prime. the large number was under 100,000
So I wrote the program, and then left a second answer. I used the first program to generate the answers into a file, used that output as a array, (depending the number they pushed, I would output X of the array up to that number) and just posted that as my answer. Explaining the answer (Just looking up the first 100,000 values is faster than the sieve of eratosthenes.)
The question emphasized speed over algorithm, but I forgot what happened with the interview so I have no idea if that was the better answer.
1
u/acfman17 Jan 17 '14
Rosetta Code has how to do it in over 180 languages. Everybody should be able to do this.
1
u/Rikkety Jan 17 '14
To be fair, this pseudo-code is by far the fastest implementation. It doesn't have the overhead of a loop, nor the expensive modulo and comparison operations.
If the question was to optimize for speed, this is exactly how I would do it (except maybe a "printf" or something similar preceding each line.
1
u/mm94 Jan 17 '14
am I missing something?
1
u/balkonkind Jan 17 '14
needs more design patterns:
1
u/mcdileo Jan 18 '14 edited Jan 18 '14
Just because:
EDIT: what is wrong with me? Maybe it's just because it's Saturday and I don't want to do work.
1
u/nicholas818 Jan 20 '14 edited May 02 '14
+/u/CompileBot python
1
u/Coopsmoss Jan 16 '14
I've never heard of it, is this a serious programming interview question? Why am I'm unemployed, I'm practically a programming god comparatively.
0
u/[deleted] Jan 17 '14
FizzBuzz Program:
+/u/CompileBot C#
-11
u/[deleted] Jan 16 '14
This solution would be easier if it was written like this:
Then just repeat 5 times.
0
u/[deleted] Jan 16 '14
[deleted] — view deleted comment
0
u/[deleted] Jan 16 '14
[deleted] — view deleted comment
0
u/[deleted] Jan 16 '14
[deleted] — view deleted comment