5

This code doesn't work, as can be shown by including <algorithm> and changing the output: std::cout << std::is_sorted(tobesorted.begin(), tobesorted.end()) << std::endl; Other things that are surprising: We pass pointers but always assume they are not null. That suggests we should be using references instead. Misspelt std::srand and std:...


5

why someone just write Overly Complex 2 times I don't know what format you originally received this information in, but it looks like there are 4 "tags" applied to your application: Overly Complex Solution Strange Coding Conventions Poorly Structured Hard to Understand With someone having modified the first one to include some extra information: ...


4

I have little to add to what Pod said. There is nothing wrong with compact code. Your code could be very efficient, and there is clearly a lot of effort in it, but I agree readability could be improved. Indeed the small details count, even whitespace is important in code. The important takeaways: Good code should have a natural flow and should be visually ...


3

Considering DRY principal, this if not conflicts.get(user): conflicts[user] = [ ( contribution.title, contribution.url, ) for person in contribution.person_links if user.affiliation in person.affiliation ] else: conflicts[user] += [ ...


3

Code review In general, the code looks nice and follows consistent styles. Some small observations: Missing #include <string>. Avoid std::endl when \n suffices. std::endl flushes the buffer, while \n does not. Unnecessary flushing can cause performance degradation. See std::endl vs \n. Use std::cout << "YES\n"; instead of std::cout <&...


3

Overview You are passing a std::vector<> to be sorted. There are lots of container types that could be used in its place (std::array, C-Array, std::dequeue, std::string etc). It is more traditional to allow sorting via iterators. You pass the beginning and end of the iterator sequence you want to sort. template<typename I> void sort(I begin, I ...


2

For the first section of code involving nested loops, if you should choose to - use curr instead of i, - assign prev = curr - 1 and - use enumerate(items, 1), the code will literally document itself. for curr, (value, weight) in enumerate(items, 1): prev = curr - 1 for capacity in range(maxweight + 1): if weight > capacity: ...


2

Some other observations, in addition to Toby Speight's answer: Sort your includes. #define NUM 1048576*2 should be constexpr std::size_t num = 1048576*2 (or 2097152) instead. This loop: std::vector<int> tobesorted; for(int i = 0; i < NUM; i++){ tobesorted.push_back(rand()); } can be simplified: (requires <algorithm>) std::vector<int&...


2

The question indeed deserves clarification. That being said... Do you realize that by having an empty catch you are silently swallowing exceptions that may occur, thus making your code hard to debug ? Either remove all those catch or add some code that actually handles the exception. One catch for the whole procedure should suffice anyway. As for this loop:...


2

Data Representation I think [False, True, True] is a very confusing representation of both data types in "reverse" order. Let's revisit that. You have 2 types, and a line which may contain none, one, or both types. types = {'DATA_TYPE_1', 'DATA_TYPE_2'} line = "ALL VALUES BELOW ARE DATA_TYPE_2 AND DATA_TYPE_1, RESPECTIVELY"; Let's use a regex that will ...


1

Having 3 parallel 2D arrays in javascript for simple data is a bit overkill. Put those in a single 2D array or you can fold it into the grid's nodes. If you want step by step visualization then you'll need to break up your function into sections: init, step and finalize. init is everything before the main while loop. step is the while loop body finalize ...


1

The conversions to bit-strings, then ints and back to strings are unnecessary. m and k are bytes, so the elements (e.g., m[0] or k[i]) are already integers in the range 0-255; bitwise operators can be applied to the elements directly. I think routines in the Crypto library return strings, so the encrypt() return value might need to be encoded before using ...


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