7 Out Of 10 « Next Oldest | Next Newest »

 ▼ dbatiz Member Posts: 64 Threads: 8 Joined: Oct 2006 02-03-2007, 10:37 PM While doing some statistics research I ran across this article: 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 0.171875 ``` Best regards from V. Edited: 3 Feb 2007, 11:26 p.m. ▼ Karl Schneider Posting Freak Posts: 1,792 Threads: 62 Joined: Jan 2005 02-04-2007, 02:49 AM 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. dbatiz Member Posts: 64 Threads: 8 Joined: Oct 2006 02-04-2007, 01:41 PM 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. ▼ bill platt Posting Freak Posts: 2,448 Threads: 90 Joined: Jul 2005 02-04-2007, 03:30 PM Alas, 100,000 chimps in a room *can* write Shakespeare after all! Valentin Albillo Posting Freak Posts: 1,755 Threads: 112 Joined: Jan 2005 02-04-2007, 06:45 PM 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. PeterP Senior Member Posts: 564 Threads: 72 Joined: Sep 2005 02-04-2007, 02:33 AM 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 ``` ▼ Karl Schneider Posting Freak Posts: 1,792 Threads: 62 Joined: Jan 2005 02-04-2007, 03:11 AM 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! 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. PeterP Senior Member Posts: 564 Threads: 72 Joined: Sep 2005 02-04-2007, 04:09 PM 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 ▼ Valentin Albillo Posting Freak Posts: 1,755 Threads: 112 Joined: Jan 2005 02-05-2007, 08:34 AM 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. ▼ PeterP Senior Member Posts: 564 Threads: 72 Joined: Sep 2005 02-05-2007, 11:41 AM 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 ▼ Valentin Albillo Posting Freak Posts: 1,755 Threads: 112 Joined: Jan 2005 02-05-2007, 12:07 PM Much appreciated. Best regards from V. Gene Posting Freak Posts: 1,107 Threads: 159 Joined: Jan 1970 02-04-2007, 08:49 AM 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 ▼ Thomas Radtke Posting Freak Posts: 1,089 Threads: 32 Joined: Dec 2005 02-04-2007, 09:33 AM I thought so, too. But that results to 0.1171875. What am I missing? (calculated w/ Commodore SR4190R and HP-30S) ▼ Valentin Albillo Posting Freak Posts: 1,755 Threads: 112 Joined: Jan 2005 02-04-2007, 10:50 AM 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. ▼ Gene Posting Freak Posts: 1,107 Threads: 159 Joined: Jan 1970 02-04-2007, 12:14 PM Ah, that's it. It's the accumulation of a series of those calculations. Missed the "at least" bit. :-) Thomas Radtke Posting Freak Posts: 1,089 Threads: 32 Joined: Dec 2005 02-04-2007, 03:46 PM Thanks Valentin! Silly me... Karl Schneider Posting Freak Posts: 1,792 Threads: 62 Joined: Jan 2005 02-04-2007, 03:31 PM 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. bill platt Posting Freak Posts: 2,448 Threads: 90 Joined: Jul 2005 02-04-2007, 07:57 PM There have been some great threads recently. This one is one of my favorites. Thanks for posting!

 Possibly Related Threads... Thread Author Replies Views Last Post Shutdown with the Apps key and more than 10 variables in a program. Davi Ribeiro de Oliveira 10 958 11-05-2013, 01:26 PM Last Post: Han Updated PPC DVD Version 2.10: HP-41 Searchable Program Files and Scannable Barcode Jake Schwartz 3 454 09-27-2013, 09:51 PM Last Post: Olivier (Wa) Rounding of 10^x Olivier De Smet 8 616 08-28-2013, 06:33 AM Last Post: Dieter HHC 2012 RPN Programming Contest - 10-Step Way-After-Nashville Solution Jeff O. 32 2,114 10-12-2012, 01:41 AM Last Post: Paul Dale Library 4 update on 10/2/2012 ? Gene Wright 10 797 10-11-2012, 02:31 AM Last Post: Ángel Martin e^pi - pi + 9/10^4 + 1/(10^4*ln(2) + sqrt(10)/6)^2 Gerson W. Barbosa 47 3,196 08-08-2012, 10:58 PM Last Post: Les Koller [WP-34S] Upgrade in 10 mins. now v 3.1 2988 Chris Tvergard 12 918 06-01-2012, 02:39 AM Last Post: Walter B Link for SAMBA v2.10 download Tom Sauntry 9 720 05-28-2012, 11:41 AM Last Post: Tom Sauntry [WP34S] OT - Fonts in Manual on OS X 10.7.3 Les Wright 43 2,426 03-23-2012, 08:41 AM Last Post: Marcus von Cube, Germany Wrong answer when evaluating log(10^-12) Daniel Greenidge 4 379 01-26-2012, 05:54 PM Last Post: Daniel Greenidge

Forum Jump: