« first day (875 days earlier)      last day (1984 days later) » 

4:43 PM
hey guys
how would you write a function that given an array A of length N describing the lengths of N lists, returns the shortest time required to merge these lists?
p is 100 elements, q is 250 elements, r is 1000 elements
merge p with q: 350ms and with r 1350ms (total of 1700ms)

merge p with r: 1100ms and with r 1350ms (total of 2450ms)

etc....
 
5:00 PM
merge p with r: 1100ms and with q 1350ms (total of 2450ms) *correction
 
well, I hope this function comes with a formula that calculates merging times, at least
 
no the merging times is just the number of elements of the two arrays added toghther
 
so what exactly is your question?
you could do all the possible permutations and return the one with the shortest time
 
im confused (clearly)
im not sure how to write this function
 
that's because your question and logic are confusing, and I'm confused, too
 
5:04 PM
ok
merging a (sorted) list consisting of K elements with L elements takes K+L ms
(given as a fact)
for example: merge p with q: 350ms and then with r 1350ms (total of 1700ms)

merge p with r: 1100ms and then with q 1350ms (total of 2450ms)
p is 100 elements, q is 250 elements, r is 1000 elements
 
that's the problem: you said for two arrays it takes A+B time, but then you go and add a third array
 
the examples are clearest
 
but you were always going to merge three arrays, weren't you?
 
yes
 
but since the merge times are all additive, there's no "shortest" time
only one time
 
5:08 PM
no
not true
you have to add the times of merging the two arrays
theres 2 adds
 
so in the end it still comes down to calculating permutations
look it up
 
but im not sure how
 
google "permutation" and go from here
there's no quick answer, and you won't get a short code example anyway
it's a programming logic question and has nothing to do with C++
 
eek
 
more accurately, it's about algorithms
 
5:12 PM
which is tricky
 
if you have p, q, r, and the result is something like 2pq+r (I think, off the top of my head) or 2pr+q, etc...
 
I ddidnt study CV
 
those two possible results are "permutations" of sorts
 
CS**
which seems to be the problem
 
doesn't matter, the info is out there
 
5:14 PM
im in a test lol
 
what do you mean?
 
online coding test
 
I haven't got days to look it up
 
well, I'm not going to do your work
good luck with your test
 
5:50 PM
if I have partial template specialization, is there a way to find out (inside the code) which one is instantiated?
decltype doesn't seem applicable here
 
6:06 PM
That's a weird question. You can check if the type matches and then std::cout or similar.
 
on line 37 you see the commented out section that didn't work for me
the whole code outputs fine on 64-bit linux, but coliru doesn't handle it well
the idea for the type_name template came from there:
361
A: Is it possible to print a variable's type in standard C++?

Howard HinnantC++11 update to a very old question: Print variable type in C++. The accepted (and good) answer is to use typeid(a).name(), where a is a variable name. Now in C++11 we have decltype(x), which can turn an expression into a type. And decltype() comes with its own set of very interesting rules. ...

err, looks like I solved it, just had to add the call operator on the type in question
 
6:52 PM
32
A: Stringifying template arguments

eduffyYou could try typeid(T).name() Edit: Fixed based on comments.

 
7:30 PM
@Mikhail tried it, got F16ReferenceRemoverIiEvE instead of ReferenceRemover<int>
 
 
4 hours later…
11:41 PM
hello
I have a problem for which I have no idea
I have an array of some prefixed size say around 300
and I partially fill it with some numbers
now I want to sort this array with std::sort in descending order
I call sort(arr, arr + n, std::greater<int>());
for an array declared to be int arr[300]; where n is less than 300
I am getting very strange numbers
the array never gets properly sorted
 
it might be helpful to initialize your array with a number that is not valid for sorting (maybe -1, if all the valid numbers are => 0), and use partial_sort
 

« first day (875 days earlier)      last day (1984 days later) »