64

I like how you have declared the Fizz and Buzz 'constants'. It makes the code more readable. The comments are useful too, though, for consistency, the second comment should be changed from: BTW Froot will run 1 through 100 to BTW Froot runs 1 through 100 The idea of generating Froot from Frootz is also good, because it reduces the computations later in ...


60

Then add a special case In all likelihood, they were looking to see how flexible and maintainable you could make your code be, and you gave them a showcase of some raw technical knowledge instead. I'm not impressed with the fact that the fizzbuzz logic is written in three different places. If you were tasked with adding another "special case" and keep the ...


50

I'd like to see if this is a reasonable solution, or is just plain terrible. I wouldn't say it is "terrible" - mostly because it works and doesn't appear to be very inefficient. However, there are some improvements that can be made. use strict equality comparison - i.e. === when comparing values. That way it won't need to convert the types. Style Guide ...


48

I really can't believe I'm reviewing lolcode right now... The specification does allow for variables to be any case, but all existing documentation uses lower case for variables. So, lowercase variables would be more idiomatic, but I'd go with camelCase for readability. Frootloopz is creative and idiomatic, but Froot is meaningless beyond it's relation to ...


46

Or if you prefer match/case to if/else: (1 until 100).map(i => (i % 3, i % 5) match { case (0, 0) => "FizzBuzz" case (0, _) => "Fizz" case (_, 0) => "Buzz" case _ => i }).foreach(println) Update: So what we are doing here is taking list of numbers and mapping them first to tuples where on the left side is that number module 3 and on ...


46

Is this FizzBuzz Swift-y? Kinda, but it could be a lot better. Here's what I would do to fix it: Extrapolate this code into a method, then call the method from the for loop. func fizzbuzz(i: Int) -> String { // ... } There is a handy Swift feature called "Tuples". Tuples are groupings of values. We can use them to represent our results from the ...


46

Simplifications Thanks to implementing some analysis of while loops in my Brainduck project (which I worked on thanks to reviewing "Hello, Brainfuck"), I managed to find a bunch of loops that were always performed x times. By expanding these loops (copy-paste their content x times and remove the loop) several simplifications are possible. Boolean peek-a-...


45

Lose the useless brackets This: while (count < 101): can just be: while count < 101: Increment out of the ifs Wouldn't be easier to do: count = 0 while count < 101: if count % 5 == 0 and count % 3 == 0: print "FizzBuzz" elif count % 3 == 0: print "Fizz" elif count % 5 == 0: print "Buzz" else: ...


38

You should "initialize 100" after the "Tape meanings". I consider it to be part of the actual code and the explanation to be a kind of "header" explaining the code. I agree that commenting "what" becomes more important in bf, but you should still explain "why" every now and then. The reasoning behind why you build the "Fizz" and "Buzz" strings the way you ...


33

Since we're doing this in assembly language, it makes sense to do it much more efficiently than is typically done in high level languages. Otherwise, why bother with assembly language? So with that said, there are ways that this can be made much, much more efficient. Avoid division The div instruction in x86 is one of the slower instructions possible. ...


31

I prefer your solution to his. My reasoning is that: yours has constants only in the String manipulation you do not do string concatenation the logic is distinct for each remainder. Both options could be better though. The lack of 'breathing space' (white space between keywords, variables, values, and operators) leads to hard-to-read code. Lines like: for(...


30

FizzBuzz is kind of a difficult example because its simplicity means it looks more or less the same in every language. That said, we can go out of our way to emphasize the functional aspect of Scala. First, we can wrap the core logic of FizzBuzz up in its own function: def fizzBuzz(x:Int) = { if (x % 15 == 0) "FizzBuzz" else if (x % 3 == 0) "...


30

Proliferation of tables Database schemas should not be designed such that you need to create more tables to accommodate more data. The same principle applies here. Instead of separate tables Fizz, Buzz, Woof, Ping, and Plop, you should have a single NoiseDefs table. A classic unparameterized FizzBuzz should be much simpler… WITH NoiseDefs(multiple, ...


30

Indentation You've gone with a structure like this: O RLY? YA RLY Froot R "Buzz" OIC I don't really like it. It has an extra indentation level. Instead, I'd opt to do this: O RLY?, YA RLY Froot R "Buzz" OIC You do get multiple statements on one line, but I'd see the IZ WIN (== true for those who are LOLCODE-inexperienced) as a part of ...


29

Loading This is unconventional: var fizzLoaded; function fizzLoad() { if (fizzLoaded) { return; } fizzLoaded = true; … } There isn't any harm in removing the "lock". However, a more elegant way would be to write window.onload = function fizzLoad() { … }; You can use the onload handler to populate the output immediately using the ...


28

Let's compare your version to the % 15 version: public class FizzBuzz { public static void main(String[] args) { for (int i = 1; i <= 100; i++) { if (i % 15 == 0) { System.out.println("FizzBuzz") } else if (i % 3 == 0) { System.out.println("Fizz"); } else if (i % 5 == 0) { ...


28

System.out.printf("%4.8s ", ...); is actually not necessary here: this code means that you will format your String so that it has at minimum 4 characters, at most 8. Since "Fizz", "Buzz" and "FizzBuzz" have a length between 4 and 8, this will result in just outputing the String with no change. Therefore, it is simpler to have System.out.print(... + " ");. ...


28

Coming from Python world, I was tempted to create a separate method named fizzBuzz() which I then called in my main() method. Is this a bit of overkill for such a simple task ? Well, it is a little bit too much for such a simple task, but it is a good habit to do so and if I were you I would stick to it. Overall your fizzBuzz looks good. Naming -> ...


26

Java 8 has good support accross all IDEs but there are still a few differences. For example your code, as-is, doesn't compile with the latest Eclipse version (Mars.2). On the command line with JDK 1.8.0_51, it compiles fine. I would hope they didn't reach out to you because they tested it with Eclipse. (Since I'm using Eclipse, I tweaked it a little to ...


26

Congratulations. First, because you made it quite easily into the next round of your job interview. That's better than 80% to 90% of all candidates applying for the average software development job apparently. Seriously, a lot of people applying for jobs wouldn't have been able to write that code. Second, because you resisted the temptation to write an "...


25

I apologize if the tone of this is a bit harsh, but hopefully I can provide some valuable advice. For me, Fizzbuzz is about three things: Is there a loop? Is there a function? Does the code run? You've got 2.5 of 3. There's no function/method that takes an integer and returns something printable for that input; that's the heart of fizzbuzz. I understand ...


24

Overall, I like this. It is concise, and neat, and all. My only beef is the nested ternaries. In general, ternary operator precedence is complicated by the lack of blocks.... The need for the parenthesis on the modulo precedence makes the conditions clear ( (n % 15 == 0) ) and the actual indenting you have, makes the logic a little clearer, but precedence ...


24

One of the problems is that the case where you check i % 15 (i.e. i is a multiple of 3 and 5) is unnecessary. You have the concept of 3 and 5 repeated, and the concept of Fizz and Buzz repeated. This is not currently much of a problem but suppose someone asks you to extend your program to print "Jazz" when i is a multiple of 7. Using your current strategy ...


22

getString and maxNum should be get_string and max_num, by PEP 8 recommendation. getString sometimes returns a number, and sometimes returns a string. This violates the expectation set up by the function name. Also, a function that is indecisive about its return type is harder to work with. num = 1; ← No semicolons in Python, please. The fizzbuzz loop is ...


21

Then he asked me which I would prefer if I was handed that code Here's what I would say: It depends. rolfl has already added some comments about your solution so I'll add some comments (pros and cons) about the second solution. First of all, rolfl's comment about spacing applies here too, of course. The biggest pro about his solution is that it's more ...


19

Your code looks good to me, and I have only some minor remarks and suggestions. An Optional has an implicit initial value of nil, so var retnValue: String? = nil can be simplified to var retnValue: String? In func generate() -> GeneratorOf<String> { var value: Int = self.startValue return GeneratorOf<String> { return (...


19

Your private one-liner functions do very little to help with anything, and they're not really DRY. Might as well do this: private boolean isDivisibleBy(Integer number, Integer divideBy) { return number % divideBy == 0; } As you can see this does nothing much more than wrap the modulo operator with a function call... which is questionable. Notice: "...


18

I think your scripts could use a bit more vertical whitespace; maybe it's the uppercasing, but I find this: BEGIN SET SEARCH_PATH = PhrancisFizzBuzz; -- call populate function with input parameters PERFORM fncPopulateFizzBuzz( prmMaxNumber, prmFizz, prmBuzz, prmWoof, prmPing, prmPlop ); DROP TABLE IF EXISTS tmpFizzBuzzResults; CREATE ...


18

I'd prefer to use the String.Join method instead of the Aggregate: public static string FizzBuzz(int start, int end) { return String.Join(" ", Enumerable.Range(start, end - start + 1).Select(FizzOrBuzz)); } This should eliminate multiple string concatenations. EDIT. Removed the superfluous generic type parameters.


Only top voted, non community-wiki answers of a minimum length are eligible