Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

This program tells how many guesses you need for a number range, including total number of guesses for all numbers in the range, and the average: (the basic idea behind it is that, you have 1 number that you can hit by exactly 1 guess, you have 2 numbers that you can hit by exactly 2 guesses, you have 4 numbers that you can hit by exactly 3 guesses... you have 2 ** n numbers that you can hit by exactly n + 1 guesses...)

use strict; use warnings; my $total; for my $i (1 .. 20) { my $last = 2 ** $i - 1; $total += $i * 2 ** ($i - 1); my $avg =$total / (2 ** $i - 1); print "For range 1 .. $last, total guesses = $total, avg = $avg\n" +; }

Output:

For range 1 .. 1, total guesses = 1, avg = 1 For range 1 .. 3, total guesses = 5, avg = 1.66666666666667 For range 1 .. 7, total guesses = 17, avg = 2.42857142857143 For range 1 .. 15, total guesses = 49, avg = 3.26666666666667 For range 1 .. 31, total guesses = 129, avg = 4.16129032258065 For range 1 .. 63, total guesses = 321, avg = 5.09523809523809 For range 1 .. 127, total guesses = 769, avg = 6.05511811023622 For range 1 .. 255, total guesses = 1793, avg = 7.03137254901961 For range 1 .. 511, total guesses = 4097, avg = 8.01761252446184 For range 1 .. 1023, total guesses = 9217, avg = 9.00977517106549 For range 1 .. 2047, total guesses = 20481, avg = 10.0053737176356 For range 1 .. 4095, total guesses = 45057, avg = 11.0029304029304 For range 1 .. 8191, total guesses = 98305, avg = 12.0015871078012 For range 1 .. 16383, total guesses = 212993, avg = 13.0008545443447 For range 1 .. 32767, total guesses = 458753, avg = 14.0004577776421 For range 1 .. 65535, total guesses = 983041, avg = 15.0002441443503 For range 1 .. 131071, total guesses = 2097153, avg = 16.0001297006966 For range 1 .. 262143, total guesses = 4456449, avg = 17.0000686648127 For range 1 .. 524287, total guesses = 9437185, avg = 18.0000362396931 For range 1 .. 1048575, total guesses = 19922945, avg = 19.00001907350 +45

In reply to Re: Behold! The power of recursion. by pg
in thread Behold! The power of recursion. by DigitalKitty

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (8)
    As of 2014-07-12 02:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (238 votes), past polls