Pop quiz

Without running it, what will this code print?
Spoiler your answers so other anons can guess too.
#include class Foo {public: Foo(int value) : value(value) { std::cout

It prints
Rust is a better language than C++

Foo ctor
Foo ctor
Foo copy ctor
Foo dtor
Foo dtor
Foo dtor


agreed

kys samefag

kys butthurt c++ fag

OOP was a mistake.

The answer is:
something totally unexpected
/thread

check yourself quadsfag

it prints nothing retard because you didn't run it

Foo ctor
Foo ctor
Foo copy ctor
Foo dtor
Foo dtor
Foo dtor

QUESTION 2

You are given 10 bags with 1000 coins in each bag. 9 bags hold 1000 coins that weigh exactly 1g. The remaining bag holds somewhere between 990-999 coins weighing exactly 1g. You're a technician at a metrology lab and your boss is a hardass about very expensive balance time, so you are only allowed to make one weighing. You're not allowed to take any coins out of the bag or tamper with the bags in any way or you'll get fired for corporate theft. You are being monitored via CCTV as you work. How do you determine which bag is short on coins?

with approximately* 1000 coins in each bag

Let a Jew sniff them. See which he wrinkles his nose at.

Load up all the bags on the scale and remove one at a time

...

It prints I am a street shitting OOP niggermonkey

But I am, I'm just removing the weight very carefully sir :^)

Sounds like a shitty job. What do I get paid for this foolish errand?

1. Weigh 5 on either side, discard heaviest side
2. Weigh 2 on either side, if equal the fifth bag which you didn't way is the one you are looking for, else discard the heaviest side and continue.
3. Weigh the last to bags and discard the heaviest one. The bag that's left is the one you are looking for.
20% of the time it will take 2 operations, 80% of the time it will take 3 operations.

I'm lazy, but it probably wouldn't've been too hard to show that it will have an upper bound of ceil(log(n)) - 1 operations for n amount of total bags.

You split the group into 5 bags. You weigh one group, and select the half that didn’t sum up to 5000 grams. That gives you a 20% chance of randomly selecting a bag with missing coins.
Although that seems low, it is the fairest probability. For example if you weigh 9 bags, you would get 100% of the remaining bag being correct if the weight was 9000 grams. But if it wasn’t, you would have 11% of getting a bag right to choose from.

this detail throws it off
test for 0.50 kg instead

light the bags on fire, you didn't say I would be fired for vandalism or negligence

Missed the fact you can only weight it once. There is no 100% guaranteed way to do it with only one weighing because there are certain cases where it will take the full ceil(log(10)) -1 = 3 measures to figure it out. Here is how to maximize your chances.

let x be an integer between 0 and 5.
let P(x) be the probability of guessing right.
P(x) = ((5-x)/5 * 1/(10-2x)) + (x/5 * 1/x), 0 < x < 5
P(x) = (5-x)/(5*(10-2x)) + 1/5, 0 < x < 5
P(x) = (15 - 3x)/(50 - 10x), 0 < x < 5
P(x) = 3/10, 0 < x < 5

For the whole domain of x we have a piecewise function.
P(x) = 1/10, x=0 | 3/10, 0 < x < 5 | 1/5, x=5
To maximize P(x), x can be 2, 3, or 4.

1. Put x bags on either side of the balance and weigh them. If equal, go to 2a. Else, go to 2b.
2a. Guess at random from the bags you did not weigh.
2b. Guess at random from the lighter side of the balance.
This strategy gives you a 30% success rate.
The reason why we have we don't test the situations with unequal amount of bags is that it gives us no new information.