Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
smart! 0.0
You can definitely make the argument that the average of an empty list is undefined because [0,] != [ ], and that returning NaN is more semantically correct. Saying it SHOULD be invalidated is a tad strong. There is a convention stating that the sum of zero elements is 0, but I don't know of any convention stating that the average should be 0. Imo an empty list can't have a well-defined mean.
could you solve it using recursion function?
still clever for setting init to a double
Division of 0.0 by 0.0 is NaN. This solution should be invalidated and the empty array added to the test cases.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Yep, definitely.
From what I can see, .begin() is before the 1st element and .end() is after the last element. Is that right?
The third generate function member is a lambda function. [] brackets for variables initialized outside lambda. mutable used here in order to be able modify the k variable.
This comment is hidden because it contains spoiler information about the solution
Use pointers at algorithm library for min/max elements to succeed. It's the only way at this cata & it's owful by the way.
Of Course we will see more "mov' assembler instructions, if we will work with references. Nevertheless the only way to measure optimization of "mov' instructions is time for the CPU to deal with them. As we can see from the benchmarking the CPU managed to sort out 7 additional mov instructions in less time. To summarise, to look only for the amount of generated instructions isn't a precise way to reach a conclusion of optimisation each time.
Benchmarking is tricky and unreliable (depends on too many factors), especially for such small examples. A better metric is to simply check the generated assembly and look at the instruction count. You can use Compiler Explorer for that. Here's a comparison using your solution: https://godbolt.org/z/EY3EK753r. Passing by reference generates 7 additional instructions in this case.
Hi. I have checked my solution using the chrono library in debug mode.
Passing by value: 577 microseconds.
Passing by reference: 386 microseconds.
Release mode
Passing by value: 270 microseconds.
Passing by reference: 271 microseconds.
Therefore I cant agree with your statement. If you have another idea how to practically measure the difference in another way - please tell me.
I have spotted an idea of yours in a book, however I try to check everything by myself.
Loading more items...