355

I'm going to tell you the things in your code that made me wonder. # Script that verifies the correctness of a toolbar offers import urllib, bencode , hashlib Extra space after bencode suggests lack of attention to detail. from hashlib import sha1 url = "http://update.utorrent.com/installoffer.php?offer=conduit" filename = "content.txt" f= urllib....


296

First of all, you should run the FindPath method a couple of times before measuring, to give the C# runtime a chance to optimize the code. // Warmup iterations for profiling for (int j = 0; j < 10; j++) { FindPath(start, end, CellFilter); } Doing this gets the time down to about 17 ms on my machine (from 38 ms initially). Running the code ...


61

Run your code through pep8 and possibly a more pedantic static analyzer like pylint. You will find these tools don't like some of your formatting and variable names. They will likely complain there are too many variables, branches, etc. because the code is not broken up into modularized functions.


58

1. Review The function knapsack lacks a docstring that would explain what arguments the function takes (what kind of things are in items? must items be a sequence, or can it be an iterable?) and what it returns. This kind of function is ideal for doctests. The comments say things like "Create an (N+1) by (W+1) 2-d list". But what is N and what is W? ...


58

While other answers make good points, I have to wonder why you are using recursion. This is such a simple problem to solve with a for loop. I assume that you are not supposed to start from any index other than index 0, so consider the following routine: public int searchArray(int[] arr, int elem) { for (int i = 0; i < arr.length; ) { if (...


47

If you're to implement something like this, you should first learn about how these things are done. I hope this doesn't sound too harsh. To explain it better, here is my variant of your code, with comparison to what C computes as e using expl(1): #include <stdio.h> #include <math.h> int main () { long double n = 0, f = 1; int i; for ...


47

For the moment, I'm ignoring the C# code (and its speed), and reviewing the C++ code for ways it might be open to improvement in readability (but with a decent compiler, what I'm suggesting shouldn't affect its speed). Cell Rather than having code in main that reads in components, then composes them into a cell, I'd rather the cell knew how to read itself ...


46

The usual advice is "make meaningful variables". However, we know this algorithm (essentially a modification of that published by a young Gauß) and those variables don't have a simple meaning. (See Decoding Gauss Easter algorithm). We know b represents centuries, but even if you did find a word to describe what the variables represent, would using epact or ...


43

If I was to take your code then multiply it out 100 or a thousand times into other files (the size of a regular commercial/enterprise application then it would be a dog's breakfast and not maintainable at all. You need to take more care with your code and make it readable and consistent. Think of it as formatting your resume for a potential employer. Use ...


41

I see some things that you might want to use to improve your code. Use an early bailout If the passed number x is less than 9, the routine can immediately return 0. Eliminate multiples of 2 Since 9 and 2 have no common factors, you can speed up the operation (on average) by shifting the incoming x to the right until the least significant bit is non-zero. ...


36

(long) 0 scructures should be written as 0L. Access modifiers of numList and result should be private: private ArrayList<Long> numList = new ArrayList<Long>(5000001); // status of whether a number is power number private boolean[] result = new boolean[5000001]; ArrayList<...> reference types should be simply List<...>. See: ...


34

This is almost all style suggestions; the code itself looks great. Personally, I prefer the brace-on-same-line style for everything in JS, and I prefer proper blocks instead of inlining expressions. But those are just preferences. I've also skipped the bitwise trick, added some strict comparisons instead of !stack.length etc., moved the i++ over to its "...


33

The problem is in \$O(n)\$. Consider the case that 200_success describes. You have a sequence of alternating 1 and 2's where a single 1 is replaced by a 3. When you are asked to search for a 3 you know, after inspecting the first element, that it will have an even index. But if every odd index holds a 2 then any even index can hold a 3, so you can ...


33

From a pure Python standpoint, a list is already a stack if you narrow its methods down to only pop and append. l.append(x) will put x at the end of the list, and l.pop() will remove the last element of the list and return it. So generally speaking, when you need a stack in Python, you'll just make a list and use append and pop. The same goes for queues, ...


31

Complexity Pedantically, the time-complexity is \$ O( m \times n ) \$, where m is str.length and n is substr.length. This matters when \$ \left| m-n \right| \$ is large. The Space complexity is \$ O(1) \$. You do not allocate any size-based memory structures. Safety It all looks good. There are no threading issues, no leaks, no problems. Correctly Nope,...


31

GroupValues GroupValues doesn't seem to serve much of a purpose beyond what you get from Map; it adds no functionality beyond an unused field. In practice, all I think it is achieving is obscuring what is actually going on. FieldGroup That you are extending ArrayList, rather than composing with it, is a code smell. I find myself looking at ...


31

Too frenetic I ran your program but it was very frenetic. It was constantly clearing the "Loading" prompt and reprinting it which resulted in a flickering effect. In addition, the cursor also moved around in a flickery manner (similar to the green box in the animated image). To improve this, I would do two things: Don't constantly draw when nothing has ...


31

No. This is just a worse Caeser cypher. steps to break: Convert each string to an int in the output Subtract everything from the min output value - ord('A') Everything is now between 0 and 26 If the message is readable, you are done (this will be true if the message contains an 'a') Otherwise, add 1 to the each character After repeating this between 1 and ...


31

Bug: When I input -6 and -3 I expect the result to be 3 but I get a RecursionError exception instead: RecursionError: maximum recursion depth exceeded in comparison For the sake of UX: Leave some space between the text you display and the data to input: Enter a number6 Enter a number5 This would be the minimum better: Enter a number: 6 Enter a ...


30

In general, the code you have is neat, and easy to follow. The QuickSort algorithm is relatively traditional, and the pieces I expect to see are about where I expect them to be. Let's go through the issues that I see though... and some of them are serious... Namespaces Using namespace::std is generally a poor idea. The possibility of namespace pollution ...


30

The algorithm you have implemented is known as counting sort. Its run-time cost is linear in the size of the input – faster than any comparison-based sorting algorithm can possibly get. (At the cost of being also linear in the difference of the maximum and minimum element in the input.) Congratulations if you've come up with this idea on your own. Since ...


30

I think it's a great project! But it could do with a few improvements: Neuron Type(1) Suppose we have a network of perceptrons that we'd like to use to learn to solve some problem. For example, the inputs to the network might be the raw pixel data from a scanned image of a signature. And we'd like the network to learn weights and biases so that the output ...


29

Your find_second() function is rather weird. It never finds the second-largest number if it is a. It sometimes finds the second-largest number if it is b or c. I don't know if your program works or not — your main() tries to make up for the deficiencies in find_second() by calling it three times — but the function name is a big fat lie. Special numbers ...


29

1. Introduction It is not a good plan to leave code running for 30 hours. Until you have analyzed the code, and have figured out how its runtime varies according to the size of the input, then you have no idea how long it will take. Maybe it will take 31 hours, but maybe it will take a million hours. In this situation you need to (i) analyze the algorithm ...


28

Problems: I would say that import should be an efficient way of reusing the libraries. import urllib, bencode , hashlib from hashlib import sha1 In the above line of code you have imported hashlib and sha1 from hashlib on the second line. There is nothing wrong in that, but when you just want to use only sha1, then no need to import the entire class. ...


28

Don't using namespace std; It is considered bad practice because of possible name collisions, ... Although nobody will hurt you, as this is such a small program :) Don't compare booleans to booleans Things like running == true are completely unnecessary, as running is already a condition in itself. Just use running. You don't need running The variable ...


27

Over all, this is good, but there's unfortunately some very major performance problems, and I have a few minor design suggestions. A string can be reversed quite trivially in linear time. Your algorithm is quadratic. You can just do a single backwards loop over the input string instead of this convoluted nested loop. Since mon_string_rev doesn't alter ...


25

Since you asked for a feedback on the encryption algorithm, too. You are not specialized in cryptography. Do not even attempt to come up with a cryptographic algorithm unless you're doing it for fun and/or to learn and plan to never actually use it. As Bruce Schneier said: Anyone, from the most clueless amateur to the best cryptographer, can create an ...


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