New answers tagged

1

The implementation is straightforward and correct as far as I can tell. What would you expect the output of std::vector<std::string> case? I expect it to be 2, as both std::vector and std::string are ranges. We have had this discussion before, and in case you want to have recursion stop when reaching a certain type, you might want to introduce ...


1

Welcome to CodeReview! Disclaimer: As noted in the comments, a review of this code is limited since I don't know the entire codebase / algorithmic approach. So this review is limited to this function's current implementation. Naming d and coll are hard-to-understand names, dungeon and collection are already an improvement. collection however is almost ...


0

Though MATLAB allows to expand the size of a matrix by assigning to elements outside its bounds, it is always best to preallocate the array to its final size. The for m=1:k loop has a lot of repeated code. First, m is always used as m-1. You could instead do for m=0:k-1 and simplify the code a bit. Next, l(1,(f+1):(f+3))=[listold(1,(m-1)*3+1) listnew(1,(m-1)*...


3

In addition to G. Sliepen's answer: Return Type std::count returns a difference_type (i.e. std::ptrdiff_t). std::transform_reduce returns a std::size_t (because that's what we specify as the "init" argument). The other two return statements return 1; and return 0; are integers. So with the auto return type, the user will get a type depending on ...


3

Comparing using == is fine In the base comparison part, not sure using input == target as the equivalence condition is OK because ValueType and T may be different. This is fine, it does exactly what std::count() does, and I wouldn't know how else to compare two values for equivalence, apart from passing a predicate function, but then it would become a ...


2

{(wl wr)←⍵ ⋄ (al ar)←⍺ ⋄ (al,wl)(ar,wr)} can be ((⊣/⍤⊣,⍥⊃⊣/⍤⊢),⍥⊂⊢/⍤⊣,⍥⊃⊢/⍤⊢), a crazy looking train indeed. Might be a good idea to add ⎕IO←0 at the beginning of the namespace script. U, '+-×÷' ∘.C ↓⍉↑⍺ ⍵ the , is not needed. the string representations keep getting extra whitespace that I don't know where it comes from It is due to the padding of ↑ in ...


4

Profiling results and algorithmic suggestions I ran the program under the profiler built into Visual Studio. Most of the time, about 75%, is spent in this line: string lastWord = wordList.FirstOrDefault(w => !existingWords.Any(a => a.Equals(w)) && w.StartsWith(startsWith)); And most of the rest of the time is spent in the similar line which ...


7

Algorithm It is always better to start out with a good decent algorithm before we try to optimize by vectoring etc. Let’s look at what we need to do. Iterate through all the words (List<string>) For every word in the dictionary we can start with a matrix like this and fill in the first column and row. To fill in the last column and row we can use a ...


1

The function returns a ceiledLog2 of an eventual n, plus the number of times it has been called until it reaches that eventual n. This observation leads to a simple iterative rewrite (please pardon my c): uint8_t getMmrProofSize(uint32_t index, uint32_t n) { uint8_t ncalls = 0; uint8_t ceiledLog2n = ceiledLog2(n); uint32_t shift = 1 << (...


Top 50 recent answers are included