Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

spiraling quine

by Len (Friar)
on Jun 20, 2002 at 15:23 UTC ( #176043=obfuscated: print w/ replies, xml ) Need Help??

This self-reproducing code prints a turning spirale filled with it's own code. Turning speed depends on processor speed. Comments welcome.
#!/usr/bin/perl $_=' $q ="\ 47"; wh ile ($ ;= $z += .5 ){ %c= $r=0;$/ ="";whi le(2 0+ $z>($;+=.05)){$c{int$ _+ 2 6+ 2*($ r+= .0 2) * s in$ ;}{1 -$_ +1 0+ int $r*c o s $ ;} =1for(0. .1) }$ t =r ever se;$ /. =` c le ar `. " #! / usr /bi n/ pe rl \n\ $_ =$q \n" ; fo r$y (1..20){$c{$_} { $ y }? $ /.=chop$t : ($/ . =" \4 0") for(0. .53) ; $/. ="\n"}pri nt"$/$ q; s; ". chr(9 2)."s;;g;eval\n "} ';s;\s;;g;eval

Comment on spiraling quine
Download Code
Re: spiraling quine
by thelenm (Vicar) on Jun 20, 2002 at 15:27 UTC
    My only complaint is that I don't have the ability to upvote it multiple times. :-) That is absolutely incredible. Good work!!

    -- Mike

    --
    just,my${.02}

      I totaly aggree. That kind of code just shows me how mutch more I have yet to learn. Keep it up Len. (++) :-)

      ---If it doesn't fit use a bigger hammer
Re: spiraling quine
by sschneid (Deacon) on Jun 20, 2002 at 18:10 UTC
    (++) ...wow. quite incredible, if i do say so myself.
Re: spiraling quine
by Marza (Vicar) on Jun 20, 2002 at 20:06 UTC

    Really slick! Only had to change clear to cls as I have a PC.

      Really slick! Only had to change clear to cls as I have a PC.

      s/PC/DOS or Win32 based PC/;

      PCs can run many different operating systems, and Windows is just one of them. Unixish operating systems use "clear", DOS (and Win32) systems use "cls", but it can be something completely different. If you want to extend your computer (or PC :) knowledge, or just dislike Windows' instability, try some operating systems, like Linux or FreeBSD. Many are free.

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

Re: spiraling quine
by cecil36 (Monk) on Jun 20, 2002 at 20:40 UTC
    My upvote has just crossed over into...the Twilight Zone.
Re: spiraling quine
by phrenesis (Initiate) on Jun 21, 2002 at 12:54 UTC
    This is really cool, too bad im a n00b and cant vote on it yet :) Phrenesis
Re: spiraling quine
by BrowserUk (Pope) on Jun 21, 2002 at 14:09 UTC

    Brilliant. A real clever twist on the theme.

Re: spiraling quine
by Anonymous Monk on Jun 21, 2002 at 19:07 UTC
    Easily the strangest thing I've seen in code. Jolly good work, Len.
Re: spiraling quine
by RMGir (Prior) on Jun 21, 2002 at 19:54 UTC
    Wow.

    /msg'd myself, I definitely want to ++ this tomorrow...

    What were you drinking when you thought this up, though? :)
    --
    Mike

Hypnotic
by perlmoth (Hermit) on Jun 27, 2002 at 12:20 UTC
    I lost an hour playing with this code this morning. Now I feel a strange compulsion to ++ all your nodes.
please delete
by NodeReaper (Curate) on Jun 27, 2002 at 16:25 UTC

    Reason: neophyte delete (requested by author)

    For more information on this node visit: this

      Wow. My head's spinning.... One of the best obfuscateds I have seem.
      Tnx Olecam.

      I've done some minor changes to the Windows code.

      Putting the system("cls") just before the print gives a better flicker-free image.
      And because system("cls") has more chr's than `clear` some frames (for example the 5th frame) are not self-replicating because the output code is incomplete. So I've decreased the radius of the spiral a bit so all the code fit's in it....

      #!/usr/bin/perl $_=' $q= "\4 7" ;wh ile($;=$z+=.5 ){ %c =$r =0;$/="";while( 21+$ z> ( $; +=.05)) {$c{i nt $ _+ 26 +2*( $r+=. 0 1 9 )*s in $; }{1 - $_ +10+int$r*c os$; }=1 f or(0..1)}$t=re v e r s e; $/. =`cl s` ." #! /u sr /bi n/ pe rl \n\ $_=$q\n" ;f or $y (1. .20){ $c {$ _ } { $y }? $ /.= chop$ t:( $/ . ="\4 0")for( 0..53 ); $ /.=" \n"}system("cls ") ;p ri nt "$/$q;s ;". c h r(92) ."s; ; g; eva l\n" } ';s;\s;;g;eval
        The version for *nix kind of worked on Win32, if you screwed your eyes up. I was impressed with 'just' that.

        Having read on and found this (the Win32 version) - I'm blown away!
Re: spiraling quine
by johnirl (Monk) on Jul 12, 2002 at 15:29 UTC
    Fantastic Len!!

    recently at my first day in my new job my boss said we going to require you to do mostly perl programming. I said no problem always willing to learn a new language. He said we expect you to be up too this level in a few weeks and showed me this code.
    Frightened the life out of me.

    Cool code though. :-)

      Sounds like a cool place to work in :)
Re: spiraling quine
by RocketPro (Initiate) on Oct 21, 2002 at 23:56 UTC
    Yeah, um... on Windows NT it looks like crap... too bad there isn't a way to clear the window.
      The initial version of this code was designed for *nix.

      However, there is a Windows version available as well.

Re: spiraling quine
by wufnik (Friar) on Jul 25, 2003 at 12:15 UTC
    beautiful; your spiral the best tool for perl evangelism i have know of. should be sent to hofstadter for inclusion in his next volume.

    wufnik

    -- in the world of the mules there are no rules --
Re: spiraling quine
by PyrexKidd (Monk) on Feb 17, 2011 at 21:20 UTC

    In an effort to understand what is going on here, I decided to put the code in a more readable format

    #!/usr/bin/perl $_=' $q="\47"; while($; = $z+ =.5){ %c = $r = 0; $/=""; while(20+$z>($;+=.05)){ $c { int $_ + 26 + 2 * ($r += .02) * sin $; } { 1 - $_ + 10 + int $r * cos $; } = 1for(0..1) } $t = reverse; $/ .= `clear` . "#!/usr/bin/perl\n\$_=$q\n"; for $y (1..20){ $c{$_}{$y} ? $/ .= chop $t : ($/ .= "\40")for(0..53); $/.="\n" } print "$/$q;s;" .chr(92). "s;;g;eval\n" } '; s;\s;;g;eval

    Quite amazingly it prints the same image in this format. I think it has to do with the sin/cos.

    Two things I am unfamiliar with, the $; variable and this line:

    s;\s;;g;eval

    Big props BTW

Re: spiraling quine
by ambrus (Abbot) on Feb 18, 2011 at 11:02 UTC

    Just like Sparkling Japh, I have to pipe this through

    | perl -we 'use Time::HiRes "sleep"; $/="\e"; while(<>){ print; sleep +0.1 }'
    so that it becomes enjoyable.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://176043]
Approved by ferrency
Front-paged by rob_au
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-11-27 18:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (187 votes), past polls