Damien Conway's Selfgol · GitHub
Skip to content Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert Instantly share code, notes, and snippets. pjlsergeant / selfgol.pl Created July 9, 2012 13:36 Show Gist options Download ZIP Star 1 ( 1 ) You must be signed in to star a gist Fork 0 ( 0 ) You must be signed in to fork a gist Select an option No results found Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/pjlsergeant/3076628.js"></script> Save pjlsergeant/3076628 to your computer and use it in GitHub Desktop.
Select an option No results found Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/pjlsergeant/3076628.js"></script> Save pjlsergeant/3076628 to your computer and use it in GitHub Desktop. Download ZIP Damien Conway's Selfgol Raw selfgol.pl #!/usr/local/bin/perl -sw $;=$/;seek+DATA,!++$/,!$s;$_=<DATA>;$s&&print||$g&&do{$y=($x||=20)*($y||8);sub i{sleep&f}sub'p{print$;x$=,join$;,$b=~/.{$x}/g}$j=$j;sub'f{pop}sub n{substr($b,&f%$y,3)=~tr,O,O,}sub'g{$f=&f-1;($w,$w,substr($b,&f,1),O)[n($f-$x)+ n($x+$f)-(substr($b,&f,1)eq+O)+n$f]||$w}$w="\40";$b=join'',@ARGV?<>:$_,$w x$y;$b=~s).)$&=~/\w/?O:$w)ge;substr($b,$y)=q++;$g='$i=0;$i?$b:$c=$b; substr+$c,$i,1,g$i;$g=~s?\d+?($&+1)%$y?e;$i-$y+1?eval$g:do{$i=-1;$b=$c;p;i 1}';sub'e{eval$g;&e}e}||eval||die+No.$; __DATA__ if($j){{$^W=$|;*_=sub{$=+s=#([A-z])(.*)#=#$+$1#=g}} @s=(q[$_=sprintf+pop@s,@s],q[ if($j){{$^W=$|;*_=sub{$=+s=#([A-z])(.*)#=#$+$1#=g}} #_The_Perl_Journal_# @s=(q[%s],q[%s])x2;%s;print"\n"x&_,$_;i$j;eval} ])x2;$_=sprintf+pop@s,@s;print"\n"x&_,$_;i$j;eval}$/=$y;$"=",";print q<#!/usr/local/bin/perl -sw if(!$s){>.($_=<>).q<}else{@s=(q[printf+pop@s,@s],q[#!/usr/local/bin/perl -sw if(!$s){>.(s$%$%%$g,tr=[=[===tr=]=]=||&d,$_).q<}else{@s=(q[%s],q[%s])x2;%s} ])x2;printf+pop@s,@s} > yozlet commented Oct 19, 2020 Copy link Copy Markdown About SelfGOL SelfGOL was Damian Conway 's intended entry to the Obfuscated Perl Contest.
It can print its own source code (self-replicate), rewrite other Perl programs so they can print their own source code (and still perform their original functions), detect un-rewritable Perl programs, play John Conway's Game of Life using its own source code or a specified file as a pattern for the board with a board of arbitrary size, or animate a rotating banner of an arbitrary short amount of text. SelfGOL's source is under 1000 bytes of standard Perl, does not import any modules, and doesn't use a single if , unless , while , until , for , foreach , goto , next , last , redo , map , or grep .
Usage selfgol -s outputs its own source code. selfgol < perlprog.pl makes perlprog.pl self-replicating (with a command line switch of -s ), outputs new source to STDOUT . selfgol -g [-y=## -x=##] [< gamefile] plays the Game of Life with its own source code or an arbitrary file, with optional height and width restrictions. selfgol -d[=bannertext] displays a rotating banner with the provided text. If no text is provided, it uses the program name as the text.
Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment You can’t perform that action at this time.