7 Out Of 10



#20

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


#21

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.


#22

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.

#23

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.


#24

Alas, 100,000 chimps in a room *can* write Shakespeare after all!

#25

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.

#26

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


#27

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.

#28

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


#29

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.


#30

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


#31

Much appreciated.

Best regards from V.

#32

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


#33

I thought so, too. But that results to 0.1171875. What am I missing?

(calculated w/ Commodore SR4190R and HP-30S)


#34

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.

#35

Ah, that's it. It's the accumulation of a series of those calculations. Missed the "at least" bit. :-)

#36

Thanks Valentin! Silly me...

#37

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.

#38

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: