Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

2

Naming Conventions GetMaxNumber: Since you are evaluating expressions, call it EvaluateMaximum. GetMaxNumberHelper: -helper is an acceptable class name, but not method name. Use an overload of EvaluateMaximum instead. visit: This is the name of a method in the visitor pattern. Don't use it as a variable name. Use number instead. maxMin: This is an ambigious ...


1

Review Here's the method I came up with, but it feels inelegant and incomplete. Any improvements, especially ones that can leverage LINQ are welcome. You could write it more elegantly by using recursion for your pair members. if (pair.First is IEnumerable) { Flatten((root as Pair).First, list); } else if (pair.First is Pair) { list....


1

Data Model I would add a restriction on the attribute and move the convenience method from the creator to this class. [AttributeUsage(AttributeTargets.Class)] class ParentAttribute : Attribute { public ParentAttribute(Type type) { Parent = type; } public Type Parent { get; private set; } } [AttributeUsage(AttributeTargets.Class, AllowMultiple=...


3

Looking over your code, this is what I have for you: Your function can be turned into a one-liner You should use if __name__ == '__main__' to ensure you're not running this program externally. Refactored Code: def recur_factorial(x): return 1 if x == 1 else (x * recur_factorial(x - 1)) def main(): num = int(input("Enter number: ")) print("The ...


1

I would change the following things to your API: let tree items know their parent and children -> easier navigation encapsulate the children -> better integrity As for the rendering, it can be done more lightweight. sample code: using System; using System.Text; using System.Collections.Generic; public class Program { public static void Main() { ...


3

Naming Field babushka should be named wearingBabushka, since that is what the field describes. The method accessing it becomes isWearingBabushka(). For some reason Java-people like exceptions in naming standards and are adamant that it's vital to have a non-standard getter name for boolean typed methods (yes I'm bitter about this, no need to go into it any ...


2

A quick search for "python tail call optimization" results in this SO answer which has a PyPI package, tco. Converting your code to return lists rather than generators should be all you need. recursion is the only way to do looping in a logic programming language This is wrong. If you want it to stay as a generator, then you'll have to manually handle ...


2

Algorithm This is not quite the Sieve of Eratosthenes. The true sieve touches only the multiples of each prime, so it has complexity \$n \log \log n\$. Filtering copies the whole list repeatedly, which is equivalent to a different algorithm, trial division, with different complexity (probably \$n^2 / (\log n)^2\$). That's a dramatic difference, which led ...


5

I think your implicit question was "how may I improve runtime?", in terms of CPU cycles, and in terms of memory read stalls. The only relevant timings to pay attention to seem to be the optimized runs, and in that contest you're already pretty close. Runtimes less than 10 msec suggest that you might want to do a hundred iterations of the whole test, or bump ...


Top 50 recent answers are included