Hmm. I wonder if I should've done some napkin math before running this one:

<?php 

$n=pow(10,100);
$p=0;

while($p<=$n){
   echo "1";
   $p++;
}

    Um... that's a BIG number of 1's you're printing sir....

      Yeah, I know. Did think about how long it might take though, heheh. I'll probably have to CTL-C that one ....

        I suppose we could make it into another coding contest; the question is would we be around to announce the winner?

        (Even then it might be faster than waiting for the end of the calendar contest of 2004...)

          dalecosp;11058329 wrote:

          (Even then it might be faster than waiting for the end of the calendar contest of 2004...)

          piersk;10528211 wrote:

          Well... you've finished moving now, so whats your excuse?

          Guess the wait will last forever, I'm tempted to go claim a winner without reviewing submissions 😛

            <?php
            
            $num = bcpow('10', '100');
            $str = str_repeat('1', '1000');
            while(true)
            {
                $newNum = bcsub($num, '1000');
                if(intval($newNum) > 0)
                {
                    echo $str;
                    $num = $newNum;
                }
                else {
                    $str = str_repeat('1', 1000 - intval($newNum));
                    echo $str;
                    break;
                }
            }
            echo PHP_EOL;
            

            Still going to take awhile, but an interesting variation that maybe could be extended to start with a much longer string of 1's, then step down incrementally?

            PS: I killed it after about 4 minutes, because I have other things to do with my CPU cycles. 😉

              echo str_repeat('1', pow(10,100));

              Why even make a loop or variables??

                Derokorian;11058335 wrote:
                echo str_repeat('1', pow(10,100));

                Why even make a loop or variables??

                Hmm, I wonder. v2 would certainly try to use str_repeat, probably with a string of 10 chars, because theoretically you'd want to decrease the runtime by a factor of 10. Or maybe 100, or 1010, etc. But I do wonder about using pow() there ... would it only be figured once? Off to RTFM, I guess....

                PS: I killed it after about 4 minutes, because I have other things to do with my CPU cycles.

                Yeah, sucks when you have to use your own. Use someone else's, more fun, more challenging, less need to actually use them 😉 😉

                I've actually calmed down a bit ... I used to espouse "liberation of resources from the overlords" or somesuch. Rather anti-capitalist in nature, which doesn't exactly jive with my worldview at all (not a heavy pro-capitalist, but certainly not pro-communist...)

                  echo str_repeat('1', pow(10,100));  

                  My guess is that would fail by exceeding the max integer size? If so, though, you could replace instances of 1000 in my code with PHP_INT_MAX. 🙂

                    NogDog;11058341 wrote:
                    echo str_repeat('1', pow(10,100));  

                    My guess is that would fail by exceeding the max integer size? If so, though, you could replace instances of 1000 in my code with PHP_INT_MAX. 🙂

                    Nope, [man]pow[/man] returns a Number, meaning if its within the range PHP_INT_MIN - PHP_INT_MAX it will return an int, otherwise it will return a float. I had originally typed it out using PHP_INT_MAX but then I remembered (and double checked the docs).

                      Except...

                      12:14 $ php -r 'echo intval(pow(10,10)).PHP_EOL;'
                      10000000000
                      
                      12:15 $ php -r 'echo intval(pow(10,20)).PHP_EOL;'
                      7766279631452241920
                      

                      And since str_repeat wants an integer for its second arg....

                        Yuk stack exchange/overflow wonders off to wash eyes with bleach :p

                          A googol ones?

                          This will blow out something somewhere (probably the outer bcpow):

                          echo bcdiv(bcsub(bcpow(10,bcpow(10,101)),1),9);

                          If you built a string of 5**100 ones you could get to a googol by doubling it a hundred times, but that of course means storing half a googol digits at one point long enough to output it twice.

                          The alternative to a hundred doublings is of course to just output it 2**100 times, but that of course won't fit in a 64-bit integer; there's a tradeoff to be made: instead of doubling a hundred times, do fewer doublings (so that the intermediate storage doesn't blow out too far) and then loop over the result as many times as required.

                          That maybe reduces the problem to generating and storing a string of 5100 ones - got a spare 7*(1048) yottabytes?

                          Just for amusement, here's a tiny file I keep around to spook things like antivirus scanners.

                          plex-10.gz.gz.gz.gz.zip
                            Write a Reply...