http://www.perlmonks.org?node_id=98691

  
perl -le '(1 x $_++) =~ /^(1(??{1x$-[1]}))*$/ && print while 1'
and...
  
perl -le 'print "Fibonacci" if (1x(-1+pop)) =~ /^(1(??{1x$-[1]}))*$/' +<NUMBER>
both require 5.6 or higher
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
Re: Fibonacci Regex
by nop (Hermit) on Jul 27, 2001 at 01:49 UTC
    would someone explain this magic? curious. thanks. nop
Re: Fibonacci Regex
by hacker_j99 (Beadle) on Jul 25, 2001 at 05:21 UTC
    i dont know if its just me but the second code is not displaying correctly but both are correct in using 5.6 or higher, although I learned that through hard knocks.

    Hacker_j99
      You have to supply a numeric command-line argument. If it's a fibonacci number, it will print "Fibonacci". Otherwise, it prints nothing.
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print