Re: Fibonacci string



Ilmari Karonen <usenet@xxxxxxxxxxxxxx> wrote in comp.lang.perl.misc:
> Anno Siegel <anno4000@xxxxxxxxxxxxxxxxxxxxxxx> kirjoitti 26.05.2005:
> >
> > Avoiding s/// altogether gains another factor of 50 or so:
> >
> > my $v = 1;
> > for ( 1 .. 20 ) {
> > printf "%10d %10d\n", $v =~ y/0//, $v =~ y/1//;
> > $_ .= length > 1 ? substr( $_, 0, tr/1/1/) : 0 for $v;
> > }
>
> If we're allowed to change the algorithm as long as the same strings
> are produced, I think I can do even better:

I think we should *always* consider a change in algorithm when playing
optimization games. It is the most promising approach, if applicable.
This thread has shown it again.

> my $v = 1; my $v2 = 0;
> for ( 1 .. 20 ) {
> printf "%10d %10d\n", $v =~ y/0//, $v =~ y/1//;
> my $t = $v; $v .= $v2; $v2 = $t;
> }

Ah, an append-only solution. Yes, it beats my fastest version

use constant PHI => ( 1 + sqrt(5))/2;
my $c = 1;
for (1 .. 20) {
$c .= length( $c) > 1 ? substr( $c, 0, int 0.5 + length()/PHI) : 0;
}

slightly.

Anno
.



Relevant Pages

  • Re: Best Job Skill --> .NET or Java
    ... strings, ... But the same basic brute-force algorithm was ... It compiled a histogram of trigrams, ... finds one random trigram that is unique, it expands that one, ...
    (comp.programming)
  • Re: How to efficiently determine if a string contains any one of many strings
    ... If you are looking to apply an algorithm similar to determining what is ... the algorithm that is used in most heuristic spam filters. ... kinds of classifications lend themselves to searches for string literals: ... Of course, assuming more input strings to match, you'd have a lot more ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Data mining algorithm
    ... the "best" descriptive strings for data. ... That sounds like the first step of a compression algorithm. ... In a similar data set this column will show similar repetativeness at ...
    (comp.programming)
  • Re: Reversing a number
    ... )> Lemme ask you a question: Suppose I have an algorithm that solves the ... )> Return the base-10 digits of the input number, ... limited the problem space to specific strings and use numbers to ... I'm not working with numerals. ...
    (comp.programming)
  • Re: GA ver. Parallel tempering
    ... the bulk of processing time will be spent in evaluating potential ... algorithm itself [of course this may not be supportable for search spaces ... sense that evaluations are of necessity performed serially. ... numbers of strings in those regions. ...
    (comp.ai.genetic)