Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫  π  -¹ ² ³ °

You are not logged in.

## #26 2012-07-29 08:16:11

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: An expectation problem:

Yes, it is quite small.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #27 2012-07-29 08:17:39

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,039

### Re: An expectation problem:

How small?

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #28 2012-07-29 08:20:33

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: An expectation problem:

I do not know. But looking at the data the values are very close.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #29 2012-07-29 08:24:25

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,039

### Re: An expectation problem:

Oh. Okay.

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #30 2012-07-29 08:26:22

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: An expectation problem:

To get the sd we would have to run the simulation many times and use the formula. But by inspection you can see the dispersion is going to be small.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #31 2012-07-29 18:56:21

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,633

### Re: An expectation problem:

Hi Bobby and stefy,

I've run several 10,000-cycle simulations in LB and each result was a smidge over 223.0. The result of a 100,000 cycle was 223.03524.

My Excel results varied more, but all were still only just < or > 223. I only tested up to about 1,000 cycles, which would account for the variation difference between the two programs.

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

## #32 2012-07-29 19:52:40

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,039

### Re: An expectation problem:

Hi phrontister

I started running 10 100000-cycles, but I wasn't at the computer long enough to check.

Here lies the reader who will never open this book. He is forever dead.
Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

## #33 2012-07-29 23:11:39

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: An expectation problem:

Hi phrontister;

I got a shade over 223 also.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #34 2012-07-30 01:44:11

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,633

### Re: An expectation problem:

Hi Bobby,

Here's my M code. As you'll see, I was thinking LB while coding M...but it works.

My initial code was slow because I was testing for '200 ones' from the first pick ( ), but changing the test to commence after 199 picks reduced processing time to 1/7th of previous.

My LB code for 100,000 cycles took well over 9 hours c.f. M's 271 seconds.

``````In[1]:= Timing[sum = 0; c = 0; s = Table[0, {1000}];
N[While[c < 100000, t = 199; ss = s;
Do[ss[[RandomInteger[{1, 1000}]]] = 1, {t}]
While[Count[ss, 1] < 200, ss[[RandomInteger[{1, 1000}]]] = 1;t++];
sum = sum + t; c++]; sum/c]]

Out[1]= {270.985, 223.00152}``````

So, again, just a touch > 223.

Last edited by phrontister (2012-08-03 20:23:22)

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

## #35 2012-07-30 03:39:48

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: An expectation problem:

Hi phrontister;

That is fine. It is okay to go from one language to another looking for the same type of commands in each language.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #36 2012-07-30 03:48:34

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,633

### Re: An expectation problem:

Hi Bobby,

That's really the only way I'll get anywhere with M for now. Anything that would require more dedicated study effort will have to wait until I get more time to be able to spend at it...but little by little I'm picking a few things up. Thanks for dangling the "extra credit" carrot...it motivated me.

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

## #37 2012-07-30 03:55:30

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: An expectation problem:

Hi;

Go at your own pace. You did well.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #38 2013-09-02 01:04:06

gAr
Member
Registered: 2011-01-09
Posts: 3,481

### Re: An expectation problem:

J:

``````sim =: monad define
cnt =: 0
a =: y\$0
while. (+/a) < 200 do.
a =: 1 (?y)} a
cnt =: cnt + 1
end.
return. cnt
)
(+/%#) (sim "0) 1000\$1000  NB. (sim&+) also works``````

≈ 223.024

There may be a way to eliminate the loop and speed up.

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

## #39 2013-09-02 01:11:25

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: An expectation problem:

Hi gAr;

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #40 2013-09-02 01:58:45

gAr
Member
Registered: 2011-01-09
Posts: 3,481

### Re: An expectation problem:

Hi bobbym,

About 15.8 seconds for 10000 trials.

``(6!:2) '%. (+/%#) (sim "0) 10000\$1000'  NB. gets the running time``

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

## #41 2013-09-02 02:27:07

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: An expectation problem:

Hi;

Okay, thanks.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #42 2013-09-02 02:34:51

gAr
Member
Registered: 2011-01-09
Posts: 3,481

### Re: An expectation problem:

What's the time taken by the mathematica code?

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

## #43 2013-09-02 02:59:47

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: An expectation problem:

Hi;

I do not know, I never ran a simulation of this one that did not use the answer to speed it up.

I am trying phrontister's code.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #44 2013-09-02 03:10:47

gAr
Member
Registered: 2011-01-09
Posts: 3,481

### Re: An expectation problem:

That's okay, he has mentioned his time for simulation.

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

## #45 2013-09-02 03:16:10

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: An expectation problem:

His code will do about 30 seconds but it is procedural and does not make use of the faster functional paradigm. Also it is not compiled.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #46 2013-09-02 03:19:27

gAr
Member
Registered: 2011-01-09
Posts: 3,481

### Re: An expectation problem:

That's right.

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

## #47 2013-12-08 04:41:39

gAr
Member
Registered: 2011-01-09
Posts: 3,481

### Re: An expectation problem:

Loopless J code, about 30x faster:

``````sim =: 3 : '1+{.I.200=+/\~:?1000#1000'
(+/%#)(sim "0) 100000#0``````

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline