[25886] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8114 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 25 11:05:22 2005

Date: Wed, 25 May 2005 08:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 25 May 2005     Volume: 10 Number: 8114

Today's topics:
        網頁寄存服務計劃買十送二............................... dsafl@fald.com
    Re: Fibonacci string <darkon.tdo@gmail.com>
    Re: fibonacci string (Anno Siegel)
    Re: fibonacci string <darkon.tdo@gmail.com>
    Re: get the current week nbr <xx087@freenet.carleton.ca>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 25 May 2005 15:08:21 +0000 (UTC)
From: dsafl@fald.com
Subject: 網頁寄存服務計劃買十送二..................................
Message-Id: <d724d5$i37$34@news.hgc.com.hk>

UHOSTNET.COM 
中港台第一代互聯網服務公司 
現推出全新優惠

服務計劃買十送二,凡預繳十個月服務月費,多送兩個月。
現即由其它公司轉用我們,即多送您三個月服務。
(任何域名轉移)
支援 PHP+MySQL, Access+ASP, ASP.NET, CGI, SSI 電郵病毒過濾, 垃圾電郵過濾 及 WebMail 等......

本月低前申請W1000即送首次安裝購物車程式 osc.
http://shop2.uhostnet.com

每月只需 $20 起

附送實用程式
ASP 留言簿,聊天室,ASP 人數器,PHP 人數器,ASP 網上電郵表格,ASP 檔案管理程式,網上商店,拍賣系統及各款論壇程式..

詳情請參閱\本公司網站
http://www.uhostnet.com
或
致電熱線:3524 3883 / 2380 7669
或
電郵:service@uhostnet.com 查詢
 .................................


------------------------------

Date: Wed, 25 May 2005 13:44:19 -0000
From: "David K. Wall" <darkon.tdo@gmail.com>
Subject: Re: Fibonacci string
Message-Id: <Xns9661631166E6Cdkwwashere@216.168.3.30>

John W. Krahn <someone@example.com> wrote:

> John W. Krahn wrote:
>> David K. Wall wrote:
>> 
>>> Here's a fun fact I ran across in the book _The Golden Ratio_,
>>> by Mario Livio.  Take the string '1' and replace it with '10'.  
>>> Thereafter, replace any occurrence of '1' with '10' and '0' with
>>> '1'.  Then count the number of 0s and 1s in the string.  You get
>>> a Fibonacci sequence for each count (offset by one iteration).
>>>
>>> Here's Perl code to do it.  You get about the same results if
>>> you start with '0', just offset a little.
>>>
>>> use strict;
>>> use warnings;
>>>
>>> my $v = '1';
>>> for (1 .. 20) {
>>>     my ($n0, $n1) = (0, 0);
>>>     $v = join '', 
>>>         map {             
>>>             if ($_) {
>>>                 $n1++;
>>>                 '10';
>>>             }
>>>             else {
>>>                 $n0++;
>>>                 '1';
>>>             }
>>>         } split //, $v;
>>>     printf "%10d %10d\n",  $n0, $n1;
>>> }
>> 
>> You can make that shorter and faster:
>> 
>> my $v = '1';
>> for ( 1 .. 20 ) {
>>     printf "%10d %10d\n", $v =~ y/0//, $v =~ y/1//;
>>     $v =~ s/([01])/ $1 ? '10' : '1' /eg;
>> }
> 
> A bit faster.   :-)
> 
> my $v = '1';
> for ( 1 .. 20 ) {
>      printf "%10d %10d\n", $v =~ y/0//, $v =~ y/1//;
>      $v =~ s/./ $& ? '10' : '1' /eg;
>}

I bow to greater perl-fu, but with the caveat that I was more 
interested in making the idea clear than in coming up with a fast 
implementation.  I'd accuse you of having too much time on your hands 
if I weren't guilty of the same sort of thing myself.


------------------------------

Date: 25 May 2005 14:09:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: fibonacci string
Message-Id: <d720u9$bgl$1@mamenchi.zrz.TU-Berlin.DE>

Josef Moellers  <josef.moellers@fujitsu-siemens.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > david k. wall <darkon.tdo@gmail.com> wrote in comp.lang.perl.misc:
> > 
> >>here's a fun fact i ran across in the book _the golden ratio_, by 
> >>mario livio.  take the string '1' and replace it with '10'.  
> >>thereafter, replace any occurrence of '1' with '10' and '0' with '1'.  
> >>then count the number of 0s and 1s in the string.  you get a 
> >>fibonacci sequence for each count (offset by one iteration).

[...]

> > The observation that it doesn't matter where the zeroes and ones
> > appear in the strings leads to a solution that doesn't use s///:
> > 
> >     my $v = '1';
> >     for ( 1 .. 20 ) {
> >         my $n0 = $v =~ tr/0/1/;
> >         printf "%10d %10d\n",  $n0, length( $v) - $n0;
> >         $v .= '0' x ( length( $v) - $n0);
> >     }
> > 
> > I generates a different sequence of strings $v (less fancy patterns),
> > but with the same distribution of ones and zeroes.  If you prefer
> > to call it "cheating" I won't object.
> 
> No, I'd call this professionalism.

Well, it's only a step away from generating the fibonacci numbers the
way they are defined and creating $v on the side:

    my( $n0, $n1) = ( 0, 1);
    for ( 1 .. 20 ) {
        my $v = '1' x $n1 .  '0' x $n0;
        printf "%10d %10d\n",  $n0, $n1;
        ( $n0, $n1) = ( $n1, $n0 + $n1);
    }

That generates the same sequence $v as above, and it *would* be cheating.
It *is* dramatically faster (either way) than the s///-solutions we've seen.
These strings get large fast, and s/// does a lot of tail-copying for
all the size-changing replacements.

BTW, I have no idea how this subthread lost connection to the main thread
on the subject, at least for my newsreader.

Anno


------------------------------

Date: Wed, 25 May 2005 14:08:50 -0000
From: "David K. Wall" <darkon.tdo@gmail.com>
Subject: Re: fibonacci string
Message-Id: <Xns9661673947145dkwwashere@216.168.3.30>

Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:

> Anno Siegel wrote:
> 
>> The observation that it doesn't matter where the zeroes and ones
>> appear in the strings leads to a solution that doesn't use s///:
>> 
>>     my $v = '1';
>>     for ( 1 .. 20 ) {
>>         my $n0 = $v =~ tr/0/1/;
>>         printf "%10d %10d\n",  $n0, length( $v) - $n0;
>>         $v .= '0' x ( length( $v) - $n0);
>>     }
>> 
>> I generates a different sequence of strings $v (less fancy
>> patterns), but with the same distribution of ones and zeroes.  If
>> you prefer to call it "cheating" I won't object.
> 
> No, I'd call this professionalism.
> I wish I'd be as thorough as you.
> 
> I bow my head,

Agreed.  I just wanted to generate it so I could look at the pattern 
for longer strings than the book contained.

The original string does have some interesting properties that do 
depend on the order of the ones and zeroes.  Some of them are 
described at this URL:
http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibrab.html
The book I was reading mentions a few others.

Sorry, this is getting a bit removed from Perl.


------------------------------

Date: 25 May 2005 14:04:27 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: get the current week nbr
Message-Id: <slrnd991fc.lbs.xx087@smeagol.ncf.ca>

At 2005-05-25 08:06AM, Alexandre Jaquet <alexj@freesurf.ch> wrote:
>  Hi again,
>  
>  Rigth now I'm looking for a function to get the current week nbr we are.

    use POSIX 'strftime';
    my $weekno = strftime '%V', localtime;

-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8114
***************************************


home help back first fref pref prev next nref lref last post