Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: (Golf) Fibonacci Strings

by danger (Priest)
on Jul 20, 2001 at 09:29 UTC ( [id://98335]=note: print w/replies, xml ) Need Help??


in reply to (Golf) Fibonacci Strings

I found all the solutions interesting (even those that let 'ab' slide through). For my own entry, I wanted to do it all in one regex and succeeded but the initial cost was nearly 90 characters. After a dinner and beer break I managed to simplify it out (I was using an extra grouping that wasn't needed), and was then able to use a bit of japhy's techniques to squeeze down to tie at 74:

sub is_fibo { pop=~/^(?{$x=$y=0})(?:(.)(??{"\Q$1"x$y})(?!\1)(?{$y=($x+=++$y)-$y})){3 +,}$/ }

Even passes 'strict' in 5.6.1, but not in 5.00503. Of course, there is the distinct possibility that my brain is mushier than I think from the beer and I'm missing some obvious failure mode with this one.

Update: Doh! And along comes japhy to casually make a putt I completely missed for a 2 stroke savings ... probably only used one hand too :-)

Replies are listed 'Best First'.
Re: Re: (Golf) Fibonacci Strings
by japhy (Canon) on Jul 20, 2001 at 16:07 UTC
    In the name of Golf, shave out the ?:
    pop=~/^(?{$x=$y=0})((.)(??{"\Q$2"x$y})(?!\2)(?{$y=($x+=++$y)-$y})){3,} +$/

    _____________________________________________________
    Jeff japhy Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://98335]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-24 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found