[ / / / / / / / / / / / / / ] [ dir / cicachan / imouto / kocsog / nofap / ponerpg / startrek / turul ][Options][ watchlist ]

/tech/ - Technology

You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.
Name
Email
Subject
Comment *
File
Select/drop/paste files here
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Expand all images

File (hide): c6e5b0eeb028160⋯.jpg (22.95 KB, 215x176, 215:176, scott meyers.jpg) (h) (u)

[–]

 No.827768>>827873 >>827894 [Watch Thread][Show All Posts]

Without running it, what will this code print?

Spoiler your answers so other anons can guess too.


#include <iostream>

class Foo {
public:
Foo(int value) :
value(value)
{
std::cout << "Foo ctor\n";
};

Foo(const Foo& t) :
value(t.value)
{
std::cout << "Foo copy ctor\n";
};

Foo(Foo&& t) noexcept :
value(std::move(t.value))
{
std::cout << "Foo move ctor\n";
};

~Foo() {
std::cout << "Foo dtor\n";
};

int value;
};

class Bar {
public:
Bar() :
foo_type(0)
{};

void set(Foo rhs) {
foo_type.value = rhs.value;
};

private:
Foo foo_type;
};

int main() {
Bar b;
Foo f(2);
b.set(f);
f.value = 3;
}

 No.827770>>827772 >>827776

It prints

Rust is a better language than C++


 No.827772>>827776

Foo ctor

Foo ctor

Foo copy ctor

Foo dtor

Foo dtor

Foo dtor

>>827770

agreed


 No.827776>>827777

>>827772

>>827770

kys samefag


 No.827777>>827879

>>827776

kys butthurt c++ fag


 No.827849

OOP was a mistake.


 No.827873

>>827768 (OP)

>Without running it, what will this code print?

>C++

The answer is:

something totally unexpected

/thread


 No.827879

>>827777

check yourself quadsfag


 No.827894

>>827768 (OP)

>Without running it, what will this code print?

it prints nothing retard because you didn't run it


 No.827917

Foo ctor

Foo ctor

Foo copy ctor

Foo dtor

Foo dtor

Foo dtor


 No.827919>>827920 >>827932 >>827958 >>828970 >>828991 >>828994 >>829001

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?


 No.827920

>>827919

>>827919

with approximately* 1000 coins in each bag


 No.827932

>>827919

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


 No.827958>>827993

>>827919

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


 No.827993>>828147

>>827958

>you are only allowed to make one weighing.


 No.828032

It prints I am a street shitting OOP niggermonkey


 No.828147

>>827993

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


 No.828970

>>827919

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


 No.828991>>829019

>>827919

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.


 No.828994

>>827919

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.


 No.829001

>>827919

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


 No.829019

>>828991

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.




[Return][Go to top][Catalog][Screencap][Nerve Center][Cancer][Update] ( Scroll to new posts) ( Auto) 5
21 replies | 1 images | Page ?
[Post a Reply]
[ / / / / / / / / / / / / / ] [ dir / cicachan / imouto / kocsog / nofap / ponerpg / startrek / turul ][ watchlist ]