## r.stiltskin's Profile User Rating:

Reputation: 1833 Grandmaster
Group:
Mentors
Active Posts:
4,956 (1.63 per day)
Joined:
27-December 05
Profile Views:
36,252
Last Active:
Apr 29 2013 05:42 AM
Currently:
Offline

### Previous Fields

Country:
US
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Who Cares
Dream Kudos:
100
Expert In:
Java and C++

### Latest Visitors

r.stiltskin has not set their status

1. #### In Topic: What is the probability of (X=6)?

Posted 16 Apr 2013

louisdjKSU, on 16 April 2013 - 09:18 PM, said:

... So how can we put a number on the possible outcomes? It's infinity, isn't it??

Thus P = 720/ infinity =0.

I wouldn't interpret it that way. Consider strings of length 7. There aren't only 720 "successful" strings of 7 characters, because the 7th character can be any of 4 possibilities. So there are 720*4 successful strings of length 7. And 720*4*4 successful strings of length 8. And so on. So if you want to consider strings of infinite length, there will be an infinite number of successes. But all of those trailing "4s" will appear in both the numerator and the denominator and cancel each other out.

Looking at it another way, suppose we were dealing with flips of a fair coin and I asked for the probability that the first heads appears on the second flip. Of course it is possible (unlikely, but possible) that tails comes up 1000 times before the first heads. Or 1000000 times. Or 1000000000 times. So would you say that therefore the probability of the first heads appearing on the second flip is 0?

I'd say that the universe of possible outcomes is HH HT TH TT, and the only "success" is TH, so the probability is 1/4. Or, it is the probability that heads doesn't come up on the first flip (1/2) times the probability that heads does come up on the second (also 1/2); therefore 1/2 * 1/2 = 1/4.

If we do 3 flips, the universe is HHH HHT HTH HTT THH THT TTH TTT and the successes are THH THT. Probability 2/8; i.e., still 1/4. And the same will hold for 4 flips, etc.

So for the OP's problem, I'd still say that the denominator is the number of possible strings of length 6 (of the alphabet ABCDE) in which there are no adjacent duplicates. And you can calculate the probability as the product of the probability that we don't find 1 of each character in a string of length 5 times the probability that we do find (at least) 1 of each character in a string of length 6.
2. #### In Topic: Storing arithmetic operations in an array

Posted 15 Apr 2013

You should read about stringstream. You can write the result of your arithmetic to a stringstream the same way you would write it to cout, using the << operator. Then you can use the stringstream's str() member to output that result as a C++ string. And then you can access the individual digits of the string using the [] operator, just as you would in an array.
3. #### In Topic: having trouble.

Posted 10 Apr 2013

makeitloud, on 10 April 2013 - 10:31 AM, said:

... call is not being initialized.

Do you know what that means?

It means that your program is trying to use the value of call, but that you never assigned any value to call.

It also means that either you didn't pay attention to (or didn't understand) the last comment in my previous post. Look at it again.
4. #### In Topic: having trouble.

Posted 10 Apr 2013

In the 'else' block on lines 62-79 (and incidentally, I suggest placing that code in braces {} ) you already know that choice == 'y'. The program won't get into that block otherwise. So there's no point having any 'if' statements containing choice == 'y' or choice != 'y' in their conditional expressions.

And if you're in the 'else' block on lines 68-79, it has already been established that coins > 0, so there's no point having coins <= 0 as a condition there. In fact, neither of the 'if' conditions in this block can ever be satisfied because we already know that choice == 'y' and coins > 0.

Furthermore, you input a value for choice2, but where do you ever use it?

Take a closer look at line 36 too.
5. #### In Topic: What is the probability of (X=6)?

Posted 8 Apr 2013

deprosun, on 08 April 2013 - 06:57 PM, said:

There are five songs, lets say {A,B,C,D,E}.
No song is played twice in a row. For example, ABACAE is valid; while ABBACE is not.
Let X be the number of songs played until every song has played.
What is the value of P(X=6)?

Lets say, if we are to find P(X=5).
Wouldn't we do
```5*4*3*2*1/5*4*4*4*4
```
?
That seems correct for P(X=5), but P(X=6) is much more complex.

macosxnerd101, on 08 April 2013 - 07:29 PM, said:

So you have 5! ways of permuting A-E. Then you choose a song to stick at the end, so C(4, 1) = 4. The total number of ways to arrange five elements in a string of length 6 is 5^6. So: P(X = 6) = 5! * 4/5^6

Not correct. Your numerator is the number of ways to play each of 5 songs once in the first 5 plays, and then play one more song without duplicating the 5th one. And your denominator is the number of ways to play a string of 6 plays (out of 5 songs) with no restrictions as to order. So it seems to be the probability that each song is played once in the first 5 selections, and that the 6th song doesn't duplicate the 5th, when songs are chosen completely randomly (not according to the stated rule).

Your problem is to find the number of 5-strings, each consisting of 4 letters out of a 5-letter alphabet, in which duplicates are not in adjacent positions, and then multiply that by the number of ways you can select a set of 4 out of 5 letters. You can visualize it this way:
x _ x _ _
x _ _ x _
x _ _ _ x
_ x _ x _
_ x _ _ x
_ _ x _ x

The x's mark the locations where the duplicated letters are placed. The underscores mark the locations where the remaining 3 out of each set of 4 letters can be placed (and permuted).

So you're going to choose 4 out of 5 letters to place in those first 5 positions, and choose 1 out of 4 to be duplicated, and then permute the remaining 3. And multiply by the number of ways to choose 1 out of 4, and by the number of ways to chooose 4 out of 5.

And finally divide the resulting number of events by the total number of possible strings that obey the "no consecutive duplicates" rule (NOT all possible strings of 6) to find the probability.

### My Information

Member Title:
D.I.C Lover
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Years Programming:
10
Programming Languages:
c, c++, java, lisp

E-mail:
Website URL:
http://

### Friends

Page 1 of 1
1. #### aresh

09 Jul 2012 - 01:39
You don't seem to be online now-a-days...
2. #### aaron1178

13 May 2012 - 06:45
3. #### Btu

24 Mar 2012 - 00:51
I just wanted to personally thank you for taking so much time to explain things on my threads. You have been a really big help.
-B
4. #### ssharma286

21 Dec 2011 - 16:16
Thank you so MUCH! You are the most helpful person ever! THANKS A BUNCH finally got the binary tree working. I am impressed by how quickly you are able to spot such complex errors! Hopefully I can be as good a programmer as you one day :P
5. #### ishkabible

04 Dec 2011 - 19:25
6. #### ishkabible

04 May 2011 - 06:00
lookin' good in purple :)
7. #### ishkabible

21 Mar 2011 - 19:24
you need to be a forum leader
8. #### modi123_1

15 Mar 2011 - 12:36
400x80 is the preferred sig image size. 490x137 isn't quite it.
9. #### goldfish

26 Feb 2011 - 07:46
Thank you so much for stopping me from going to wrong way. I'm going to work on it today and may bring my code back later when I have MORE problems.
10. #### James1981

25 Feb 2011 - 10:35
Thanks for your help with my posts! Sorry if I was unclear at times. I am pretty useless when it comes to computers but I am learning. Thanks again!
11. #### bedmond

16 Oct 2010 - 19:31
thanks
12. #### greenska_89

17 Jun 2010 - 14:55
thanks for your posts at my question..
really appreciate it..
thank you very much
13. #### wmugume2000

06 May 2010 - 15:25
I am really so greatful for your assistance,all the unwavering efforts you put to my bidding similation programe.Am not yet done! but I appreciate all.
Page 1 of 1