You are not logged in.

- Topics: Active | Unanswered

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

Can't you, please, post the code?

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,717

Okay, I am now pretty sure of it's accuracy:

```
maze[]:=Module[{box, L={0,0,0,0}},
firstmove=RandomInteger[{1,4}];
If[firstmove==1, box=1;L[[4]]=1];
If[firstmove==2, box=2;L[[4]]=2];
If[firstmove>2, box=3;L[[4]]=3];
Do[
move=RandomInteger[{1,2}];
If [box==1 && move==1,L[[1]]=1;Return[L]];
If [box==1 && move==2,box=2];
move=RandomInteger[{1,3}];
If [box==2 && move==1,box=1];
If [box==2 && move==2,L[[2]]=1;Return[L]];
If [box==2&& move==3,box=3];
move=RandomInteger[{1,3}];
If [box==3&& move==1,box=2];
If [box==3 && move>1,L[[3]]=1;Return[L]],
{100}]
]
ans =Table[maze[],{1000000}];
(Select[ans,#[[3]]==1 && Last[#]==1&]//Length)/(Select[ans,#[[3]]==1 &]//Length)
0.07703891543158152
```

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

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

Shouldn't you be checking if Last[#] is 1. That is where he enters.

And what is the rest of the list L for?

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,717

The list L contains all that information.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

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

But, shouldn't you be checking if the third element is 1 and the fourth is 1?

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,717

L[[4]] has the room the rat entered in

L[[1...3]] Has either a 1 or a 0. For instance L={0,1,0,3} would mean the rat entered the maze in room 3 and exited from room 2. L={1,0,0,2} would mean the rat entered the maze in room 2 and exited from room 1.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

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

Then that means you are selecting the cases where the rat has entered in room 3 and left at room 1!

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,717

Yikes, that is correct. I told you not to rush me! I have adjusted the code.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

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

You need #[[3]]==1 in the second select as well.

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,717

Hi;

No, that is correct. Last[L] == 1 says it entered the maze in room 1.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

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

Oh, I tought that was for c).

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,717

That is what I did it for:

(c) If the rat leaves the maze from Room 3 find the probability that it entered at Room 1.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

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

Well, that probability is P(entered at 1 and left at 3)/P(left at 3). That means the second Select selects the cases when the rat left at three, i.e. when #[[3]]==1.

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,717

Hmmm, I think it should be

( the cases it left at 3 and started at 1) / (cases it started at 1 ).

That is what I have calculated.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

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

That is not correct. That will give you the answer for a).

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,717

Hi;

How about this way of thinking;

Out of 1000000 tries the rat started in room 1, 250077 times. About 1 / 4 which is

just what we expect. The number of times it left room 3 after starting in room 1 is

38522

38522 / 250077 = 0.15404 which is just what I am getting with mine.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

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

Yes, but that still answers a).

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,717

Maybe the answers are the same? Is there something wrong with what I did in post #416?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

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

Yes, there is.

Do we agree that the probability we are looking for is P(entered at 1|left at 3)?

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,717

Yes, that looks good.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

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

And, do you agree that P(A|B)=P(A and B)/P(B)?

*Last edited by anonimnystefy (2013-03-31 13:58:24)*

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,717

Yes, that is the definition.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

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

That means that P(entered at 1|left at 3)=P(entered at 1 and left at 3)/P(left at 3).

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

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,717

Hmmmm, hard to argue with that one. By golly I think you are right. I did not look at it that way.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

Offline

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

Well, there you have it. What is the new result?

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