Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

This was a lot of fun

by ninja-joe (Monk)
on May 06, 2004 at 13:55 UTC ( [id://351115]=obfuscated: print w/replies, xml ) Need Help??

################################################################ #################### Digital Clock v1.0 ######################## ################################################################ $m[0]='521122211132111132115111421142521132111142';$m[1]='15311' .'5211521133114133'.'114153115134113414113153115133115';;;$m[2]= '15311521152131131131121315321515421542311311153215143215';$m[3] ='153115'. '2115212'# .'113214'. ''. ''. '1144115'# .'411515'. ''. ''. '3115211'# .'321153'. '11'.'54'# .'115';//; ;;;;$m[4]= '153215221522111332143213411542131432131113311532154115';//;;$r= q$ _/\|$;$s=5;for($k=0;$k<$s;$k++){$x=length($m[$k]);for($i=0;$i <$x;$i=$i+2){$n=substr($m[$k],$i,1);$c=substr($m[$k],$i+1,1);$~[ $k].=substr($r,$c-1,1)x$n;}}do{$_=localtime(time); /.*(\d)(\d):(\d)(\d):(\d)(\d).*/;for($i=0;$i<5;$i++){print"\ec", ,qq$\075$x45,qq{\012}if($i==0);print"\174\040",substr($~[$i],$1* 5,5),"\040",substr($~[$i],$2*5,5),(($i==2)?"\157\040":"\040"x2), (($i==3)?"\157\040":"\040"x2),substr($~[$i],$3*5,5),"\040", substr($~[$i],$4*5,5),,(($i==2)?"\157\040":"\040"x2),,(($i==3)? "\157\040":qq{\040}x2),(substr($~[$i],$5*5,5)),qq{\040},substr( $~[$i],$6*5,5),"\040\174","\012";print"\174\040" ,"\040"x41,"\040\174","\012","\075"x45,qq{\012} if($i==4);}}while(sleep(1.5));

Replies are listed 'Best First'.
Re: This was a lot of fun
by ambrus (Abbot) on May 08, 2004 at 20:53 UTC

    Spoiler!

    Download the code or set code wrapping to larger value than default if you want to read this.

    Here's the cleaned up code with some explanations.

    The code has run-lenght encoded images of the digits.

    use warnings; $INITTERM= "\n"; # originally "\ec" $r= ' _/\|'; # The format of the rle data in @m is like this: # One digit for count, one digit for the character: 1=space 2=_ 3=/ 4= +\ 5=| # I've inserted spaces for clarity. $m[0]= '52 112221 113211 113211 51 1142 1142 52 113211 + 1142'; # _____ __ ___ ___ ____ ____ _____ ___ + ____ $m[1]= '153115 211521 133114 133114 153115 1341 1341 4113 153115 + 133115'; # | | | / \ / \ | | / / / | | + / | $m[2]= '153115 211521 311311 311213 153215 1542 1542 311311 153215 + 143215'; # | | | / _/ |___| |____ |____ / |___| + \___| $m[3]= '153115 211521 211321 4114 4115 4115 153115 211321 153115 + 4115'; # | | | / \ | | | | / | | + | $m[4]= '153215 221522 111332 143213 4115 4213 143213 111331 153215 + 4115'; # |___| __|__ /___ \___/ | ____/ \___/ / |___| + | $s= 5; for $k (0..$s-1) { # decode the rle data to plain strings while ($m[$k]=~ /(\S)(\S)/g) { $t[$k].= substr($r, $2-1, 1) x $1; } } # @t (orig. @~) now contains the decoded characters, each element is o +ne line: # _____ __ ___ ___ ____ _________ ___ ____ # | | | / \/ \| |/ / /| |/ | # | | | / _/|___||____|____ / |___|\___| # | | | / \ | || | / | | | # |___|__|__ /___\___/ |____/\___/ / |___| | do { localtime=~ /.*(\d)(\d):(\d)(\d):(\d)(\d).*/; for $i (0..4) { # for each line if ($i==0) # before 1st line, print top of frame { print $INITTERM, "=" x 45, "\n" } print "| "; # print the first digit print substr ($t[$i], $1*5, 5), " ", substr ($t[$i], $ +2*5, 5); # the first colon print+(($i==2) ? "o " : " "), (($i==3) ? "o " : " ") +; # the second digit print substr ($t[$i], $3*5, 5), " ", substr ($t[$i], $ +4*5, 5); # the second colon print+(($i==2) ? "o " : " "), (($i==3) ? "o " : " ") +; # the third digit print substr ($t[$i], $5*5, 5), " ", substr ($t[$i], $ +6*5, 5); print " |\n"; if ($i==4) # and the bottom frame after the 5th line { print "| ", " " x 41, " |\n", "=" x 45, "\n" +; } } } while(sleep(1.5)); __END__
      Rock on!
Re: This was a lot of fun
by Anonymous Monk on May 06, 2004 at 16:32 UTC
    Only works well for me in Windoze adding $|=1; at the begining.
Re: This was a lot of fun
by ysth (Canon) on May 06, 2004 at 16:36 UTC
    Very nice. You do know that sleep only takes an int, so that 1.5 is turning into 1, right? And occasionally a second is skipped.
      Yes I realize that it takes integers, the older version of this script was using Time::HiRes for a bit but I realized that it doesn't need it. That was also the beginning of obfuscating the magic numbers, but I was anxious to post it :-)
Re: This was a lot of fun
by perlinux (Deacon) on May 06, 2004 at 16:37 UTC
    Very great & interesting. I will study it... ++
Re: This was a lot of fun
by Trag (Monk) on May 06, 2004 at 18:07 UTC
    How does it work?

    *********************************************
    print "Just another iconoclastic Perl hacker";
Re: This was a lot of fun
by Sameet (Beadle) on May 06, 2004 at 18:30 UTC
    Great,
    How does it work!
      I suppose that's a question for you guys to answer! I mean, if you break it down into the actual statements and do a few other key things it should be easily discernable.

      I imagine an average programmer could open up shop and shut my script down, it just takes time.

      Me spoiling this isn't nearly as fun as you guys spoiling it! :-)
Re: This was a lot of fun
by RolandGunslinger (Curate) on May 07, 2004 at 13:00 UTC
    This is pretty cool. Thanks for the source code. Great job!
Re: This was a lot of fun
by Elliott (Pilgrim) on May 14, 2004 at 18:46 UTC
    That's pretty cool - now I see what it's supposed to do, I had to get BBEdit to work on the output so i could tell, on my Mac, what Win folk must be seeing. Reminds me of my own once-loved but now almost forgotten When JAPH retires (v 2.0)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-29 02:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found