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

Pentominos Solving Quine

by halley (Prior)
on Apr 26, 2003 at 14:40 UTC ( #253363=obfuscated: print w/ replies, xml ) Need Help??

Set your code-viewing glasses to a full 80 columns or more. (Find it in your user settings, if you see red plus marks.) This code tested on 5.8.0 on a variety of Linux architectures.

CAUTION! This program can use a lot of computing resources for very long periods of time. It may take an hour or more just to find the first of thousands of possible solutions.

    $ perl quine
For more output, try adding the --verbose command line option. This will cause the program to print incomplete results every few seconds, to help you see what it is doing. These partial results are usually full quines, but this isn't guaranteed. Full solutions are always quines.
#!/usr/bin/perl $_=$w=q# $w=~s=\s|\n==sg ;++$L{' FfFffFF fFf'};($b,$B,$b b,$BB) +=(10,6,8, 6);$q=int($b/2) ;($*,$" ,$/,$:, $;)=split//,"\0 40:\n\ +043_";$D= $"x($b+2);$D=$D .($".($ *x$b).$ ")x$B.$D;$Z=sub {rever +se@_};++$ L{'IIIIi'};$T=s ub{my($ x,$P,$T ,$O,$F)=(0,$b*$ q+$q,@ +_);$_=$"x ($b+$b*$b+$b);m y@T=(-2 -$b,1,2 +$b,-1);@T=&$Z( @{T})i +f$F;while ($T){$X=substr( $T,0,1, '');$x= lc${X}i f!$x;s +u bstr($_,$P,1,$x );(${X}ne$x)?($ P+=$T[$ O]):($O =($O+1)%(@T))} +s =\A$"+= =s;s=$"+\z==s;$ _};++$L{'LlLLLl '};$W=s ub{$_=s hift;eval(qq%y +/ $"f-z/. $*/%);s-(\.{4,} )-'.{'.length($ 1).'}'- ge;qr/$ _/};++$L{'NNnn +n NnNn'}; ++$L{'PPpPpPp'} ;$r=sub{local($ _,$m)=@ _;s/$"/ /g;s/(.)/$1x$b +b /ge;$x= $bb*$b;s|(.{$x} )|$1x$BB|eg;s~( ?<=(.)) (.)~($1 eq$2)?$2:$*~eg +; $x--;s~ (?<=(.) .{$x})( .)~($2n e$1)?$* :$2~ge; + s|.(.{$ x})|\1$ /|g;s!.*?$/!!s; $x=$w.$ ;.$w;s: \S:subs tr($x, +0,1,''):g e;print "$:!$^X$/",q@$_ =$w=q@, $:,$/,$ _,"$:", q@=>s= +\s|\n|@,$ ;,$;,q@ .*==sg=>eval@,$ /,"$;$; DATA$;$ ;$*$m$/ ";};++ +$L{'TTtTt tTTt'}; $L=sub{my($Z,$O ,$F);fo r$x(key s%L){$L {$x}={ +};for$O(0 ..3){fo r$F(0,1){$Z=&$T ($x,$O, $F);$L{ $x}{$Z} =&$W($ +Z);}}}};+ +$L{'Uu UUuUu'} ;($L5, +$ L4,$L3,$LL)=($b -4,$b-3 ,$b-2,$ b-1);($ S,$s)=( "S-S$L +L :","S-- S$LL:");$h=["S$ b:S-S$b :S","S$ b:${S}S -S$b:S" ,"SS$L +L :${s}SS ","S$b:${S}${S} S-S$b:S ","SSS$ L4:S--- S$L4:SS ","S$b +: ${S}${s }SS","S$b:S-S$L 3:${s}S S","SS$ LL:S--S $L3:S-S $b:S", +" SS$LL:$ {s}S-S$b:S","S$ b:$S$S$ {S}S-S$ b:S","S SS$L5:S ----S$ +L 5:SS"," SS$LL:S --S$L3: ${s}SS" ,"S$b:$ S$S$S$ +S ${S}S-S $b:S"]; for(@$h){s=S=\134S=g;s= \-=$*=g ;s=(\d+ ):=.{$ +1 }=g;$_= qr/$_/} ++$L{'VVvVVv'};$H=sub{m y$X=shi ft;for$ x(@$h) +{ return' 'if$X=~ /$x/}1;};++$L{'WwWwwwWw Ww'};$V =sub{my ($I,$D +, $q,$Q)= (0,@_); for$I(0..-1+length($Q)) {$_=sub str($Q, $I,1); +i f($"eq$ _){next }substr($D,$I+$q,1,$_); }&$H($D )&&&$A( $D);}; ++ +$L{'XX xxXxXxx XXx'};$ S=$c=0; + ++$L{'Y yYyyYYYy'};$A=s ub{++$c ;my($D)=@_;!@A&&(&$r($D ,"SOLUTION".++ +$S),retur n);@ARGV&&(@A<3 )&&&$r( $D,"$c$*moves");my($aa, $a)=('',pop@A) +;for$aa(s ort(keys%{$L{$a }})){wh ile($D=~m/(?=$L{$a}{$aa })/g){&$V($D,p +os($D),$a a);++pos($D);}} push@A, $a;};++$L{'ZzZZzzzZz'}; &$L;@A=&$Z(sor +t(keys%L) );&$A($D);__@@* %&(*%(* @&%(*&@^_$w=~s=\s|\n==s g;++$L{'FfFffF +FfFf'};($ #=>s=\s|\n|__.*==sg=>eval __DATA__ [ e d @ h a l l e +y . c c ]

Watch this space. I'll insert a link to my POD documentation which gives the blow-by-blow explanation in a few days. For now, the name and the visuals are all I'll give away.

Replies are listed 'Best First'.
Analysis of the Pentominos Solving Quine
by halley (Prior) on Apr 29, 2003 at 22:06 UTC
    Visit the Full Analysis on the Pentomino Solving Quine, only if you aren't trying to deconstructing it yourself.

    Or check the Full Pretty Source Code if still you're trying to read the Perl code in the blocky form.

    As far as obfuscation goes, this program isn't very obscured, but the methods and algorithm may be hard to work out if you're not familiar with the problem.

    Even if you're not into quines, or obfuscation, I hope the program is an entertaining plaything... it was fun for me to put it together. My first version was in Turbo Pascal in the mid-80's, and it took four solid MONTHS to collect all the solutions on an IBM PC-AT, with similar heuristics.

    [ e d @ h a l l e y . c c ]

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://253363]
Approved by Mr. Muskrat
Front-paged by kelan
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2016-06-27 00:42 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (333 votes). Check out past polls.