▼
Posts: 64
Threads: 8
Joined: Oct 2006
While doing some statistics research I ran across this article:
http://faculty.vassar.edu/lowry/ch5pt1.html
It states that the likelihood of at least 7 out of 10 coin tosses coming up heads is 17%. This seamed too high to me, so I set upon verifying the figure.
After about 4 hours, I managed to develop an equation that would tell you for any number of coins (c), the likelihood of at least (h) tosses coming up heads. Of course, 0<h<=c.
On my 50g, my equation worked right out of the editor. But just last week I was given an 11c (in exchange for tutoring in calculus) and I decided to see if I could still program. I was able to get my 11c to give the solution in 25 steps. I calculated the actual probability to be 0.171875.
I’d love to see other solutions. I’ll post mine in a few days.
Very respectfully,
David
▼
Posts: 1,755
Threads: 112
Joined: Jan 2005
Hi, David:
The following 20-step routine for the HP-11C I've concocted
right now will do what you want:
LBL A
STO 0
E3
/
+
STO I
CLX
LBL 0
RCL 0
RCL I
INT
Cy,x
+
ISG
GTO 0
2
RCL 0
Y^X
/
To run it, just enter Heads and Coins in the stack, in that
order, and GSB A. For example:
7 ENTER 10 GSB A -> 0.171875
Best regards from V.
Edited: 3 Feb 2007, 11:26 p.m.
▼
Posts: 1,792
Threads: 62
Joined: Jan 2005
Hi, Valentin --
Very elegant! The answer both of you gave is correct, of course. It assumes a fair coin, so the probabilities of heads and tails need not be incorporated, as the Binomial Theorem would do.
Your program using the example of 10 coins (or flips) and 7 heads took only two seconds flat to run on my
accelerated HP-11C.
The program is simple enough, so I'll leave to others the satisfaction of analyzing it. For those who are interested, it will port to an HP-15C with just one modification: Since "ISG" can work with any register on an HP-15C, its version would have "ISG I" in place of "ISG", which works only with the I register on an HP-11C.
-- KS
Edited: 4 Feb 2007, 3:33 p.m.
Posts: 64
Threads: 8
Joined: Oct 2006
Extremely well done Valentin,
It has been over 9 years since I lost my original 11C to a tragic laundry accident. I think it survived the washing, but the drying did it in.
I’d forgotten the syntax for using the “I” register. My solution included manually incrementing a memory register.
Thank you for a great example of elegant code.
One of my coworkers came up with a creative, but very inefficient solution. He created an Excel spreadsheet with all 1024 possible combinations of coin flips, then counted all where there were 7 or more heads.
The ironic thing, he finished his project about 20 minutes before I got my equation to work,
Thanks again,
David
Edited: 4 Feb 2007, 1:45 p.m.
▼
Posts: 2,448
Threads: 90
Joined: Jul 2005
Alas, 100,000 chimps in a room *can* write Shakespeare after all!
Posts: 1,755
Threads: 112
Joined: Jan 2005
Thanks for your kind words of appreciation, David.
Sorry for your late HP-11C. The 11C's indeed a wonderful machine though if you can, get an HP-15C. It certainly is the very best pure calculator there is and has ever been, bar none.
Thanks also for your interesting 'quiz', it was a welcome relief over more mundane matters.
Best regards from V.
Posts: 564
Threads: 72
Joined: Sep 2005
Here is one for the 41 (my one and only... can you tell me what the 11c is in comparison to say the 12c and the 15c?) which I believe does the trick. It is rather brute force and 'stupid' (both of which is a function of the programmer, not the 41C!) It is not using the fact that the last loop of 00 will always deliver 1 and the one to the last run will always deliver the number of flips.
Also, it calculates the necesseray 'n over k' number brute force and hence a) has a limit of 69 flips - 69! is the max for the 41c - and b) will run into numerical inaccuracies at around 16 flips - 16! has 13 digits . A smarter - and longer - 'n over k' routine in lbl 00 would be needed to push these constraints a bit further as well as use of the above mentioned facts.
To start, just do heads, enter, flips, run to get the number of heads wanted in y and the number of flips in x before starting the routine
Lbl '7oo10
Sto O
E3/E+
LastX
Fact
Sto M
RDN
+
DECX
Sto N
Clx
Sto 00
Lbl 00
Rcl M
Rcl O
Rcl N
Int
-
LastX
Fact
X<>Y
Fact
*
/
Sto+ 00
Isg N
GTO 00
Rcl 00
Rcl O
2
y^x
/
Stop
▼
Posts: 1,792
Threads: 62
Joined: Jan 2005
Hi, Peter --
Quote:
Here is one for the 41 (my one and only... can you tell me what the 11c is in comparison to say the 12c and the 15c?)
The MoHPC pages and "calculator comparison" feature would be helpful for identifying the differences between the three Voyager-series models. The topic of 11C vs. 15C has come up a few times in the Forum over the years.
Quote:
Also, it calculates the necessary 'n over k' number brute force and hence a) has a limit of 69 flips - 69! is the max for the 41c - and b) will run into numerical inaccuracies at around 16 flips - 16! has 13 digits . A smarter - and longer - 'n over k' routine in lbl 00 would be needed to push these constraints a bit further as well as use of the above mentioned facts.
Yes indeed, the HP-41 does not have built-in statistical combination ('n over k' number) or permutation. Nor are these functions available on the Stat Pac ROM. Robust routines -- which will provide the correct answer as long as it is within the displayable range, and which do not waste considerable time doing needless calculations -- do require some thought as to the approach.
The HP-15C in particular is a much better "pure calculator" (i.e., non-expandable, non-I/O, not intended for extensive programming) than the HP-41. Here's the proof!
HP-41 as calc vs. 15C
Of course, I'm delighted with my HP-41C, HP-41CV, and HP-41CX as well as my HP-15C's and HP-11C's...
-- KS
Edited: 4 Feb 2007, 3:36 p.m.
Posts: 564
Threads: 72
Joined: Sep 2005
wow, just came back to the thread. Busy, busy...
I'm not surprised that Valentin posted before me (though, to be fair, I do not know when he read the original puzzle and when I read it, but I don't think it would have mattered ;-) ) Yet I'm happy that his and my solution, developped independently, are quite similar. As we say in Austria, even a blind chicken finds a grain once in a while...
BTW - Valentin, when is the next SSMC? I was out of comission for a year but have 'caught up' programming allmost all of the ones I missed in the meantime, skipping those were the 41c is hopelessly out of his league...
Thanks Karl for the tips on 15c vs 41c, it seems that the 15c is quite a powerful little bugger!
Cheers and thanks for the entertainment!
Peter
▼
Posts: 1,755
Threads: 112
Joined: Jan 2005
Hi, PeterP:
PeterP posted:
"BTW - Valentin, when is the next SSMC?"
Thanks for your interest. I know it's been quite some time since I posted the latest S&SMC, but I couldn't help it. I've been suffering an extreme lack of free time, what with working full-time in an important project on the one hand, while having to cope with some unfortunate events at home on the other.
The result of it all has been that I've been forced to maximize my terminally scarce free time to bring maximum output to the most urgent tasks, and the most urgent HP-related task was to create and send new articles to Datafile for its publication in the very next issue due in February.
They were 3 articles, all of them featured, one of them belonging to a classic series of mine, the "Long Live ..." one, and the other two being the first of two new regular series I've just created. All in all, 12 pages, including 3 programs, some 4 or 5 smaller 'routines', plus formatting, graphics, ... this took all my time, believe me.
Nevertheless, I've just completed *four* more articles belonging to the new series, and intended for the April and June issues, so I can reserve some free time to concoct a worthwhile S&SMC or some interesting Mini-Challenge for the HP-15C, say, I've got some very good ideas to try.
Stay tuned ! :-)
Best regards from V.
▼
Posts: 564
Threads: 72
Joined: Sep 2005
Wow Valentin, you have been busy, very impressive. And very sorry indeed to hear about troubles at home. Those are the hardest one to deal with. All the best for you from here!
Peter
▼
Posts: 1,755
Threads: 112
Joined: Jan 2005
Much appreciated.
Best regards from V.
Posts: 1,107
Threads: 159
Joined: Jan 1970
Isn't this the binomial distribution? P(n,k)?
If I recall correctly, the probability would be:
P(n,k) = Comb(n,k) * p^k * (1-p)^(n-k)
where p in this case is 0.5
▼
Posts: 1,089
Threads: 32
Joined: Dec 2005
I thought so, too. But that results to 0.1171875. What am I missing?
(calculated w/ Commodore SR4190R and HP-30S)
▼
Posts: 1,755
Threads: 112
Joined: Jan 2005
Hi, Thomas:
Thomas posted:
"I thought so, too. But that results to 0.1171875. What am I missing?"
The key word is "at least N heads". The individual probabilities of having 7, 8, 9, or 10 heads out of 10 coins are as follows:
10 7 0.1171875
10 8 0.0439453125
10 9 0.009765625
10 10 0.0009765625
and you need to add them up, to come with 0.171875 which is thus the correct answer. Have a look at my HP-11C program above.
Best regards from V.
▼
Posts: 1,107
Threads: 159
Joined: Jan 1970
Ah, that's it. It's the accumulation of a series of those calculations. Missed the "at least" bit. :-)
Posts: 1,089
Threads: 32
Joined: Dec 2005
Thanks Valentin! Silly me...
Posts: 1,792
Threads: 62
Joined: Jan 2005
Hi, Gene --
Quote:
Isn't this the binomial distribution? P(n,k)?
If I recall correctly, the probability would be:
P(n,k) = Comb(n,k) * p^k * (1-p)^(n-k)
where p in this case is 0.5
From my post of a few hours prior:
"It assumes a fair coin, so the probabilities of heads and tails need not be incorporated, as the Binomial Theorem would do."
If the coin were not fair (that is, p(heads) < > 0.5), then a binomial series with simplified calculations might be the best approach. For example,
if q(n,k) = p^k * (1-p)^(n-k), then q(n, k+1) = q(n,k) * p/(1-p) for 0 < p < 1.
[An implicit assumption of 0^0 = 1 is needed to make the binomial expression give the correct answers of 1.00 for p = 0 and k = 0, and for p = 1 and k = n.]
However, since p = 0.5,
p^k * (1-p)^(n-k) = 0.5^n = 1/(2^n) for all k, which can be factored out from each term. 2^n was the denominator in Valentin's program.
-- KS
Edited: 5 Feb 2007, 12:28 a.m.
Posts: 2,448
Threads: 90
Joined: Jul 2005
There have been some great threads recently. This one is one of my favorites. Thanks for posting!
|