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

147 Chars - Re: Symmetrical Date Golf

by metadoktor (Hermit)
on Feb 28, 2002 at 14:54 UTC ( [id://148228]=note: print w/replies, xml ) Need Help??


in reply to Symmetrical Date Golf

A first shot though I only generated 7198 variations...I must've done something wrong or misinterpreted something in your problem statement.
#!/usr/bin/perl -w use strict; symdate(); sub symdate{ my($h,$n,$d,$m,$y,$r);my@x=qw(1001 2002 3003 0110 1111 2112);for('0000 +10'..'195921'){$r=reverse$_;$h=substr($_,0,2);$n=substr($_,2,2);$d=su +bstr($_,4,2);$m=substr($r,0,2);$y=substr($r,2,4);for(@x){if($_ eq $d. +$m){if(($h>=0)&&($h<24)&&($n>=0)&&($n<60)){print "$h:$n $d/$m $y\n";} +}}} }
Update:

Fixed the logical error and shortened the code down to 179 chars.

sub symdate { my($f,$r);for('000000'..'235930'){$f=$_.reverse;$r='(..)'x6;$f=~s/$r/$ +1:$2 $3\/$4 $5$6/g;for(qw(1001 2002 3003 0110 1111 2112)){if(( $_ eq $3.$4)&&($1<24)&&($2<60)){print"$f\n";}}} }
Update2:

Shortened it down to 147 chars though still not as good as chipmunk's. Btw, it generates 8,640 solutions.

sub symdate { for(qw(01 10 20 30 11 21)){for$h('00'..'23'){for$m('00'..'59'){$s="$h$ +m$_";$r='(..)'x6;$f=$s.reverse$s;$f=~s/$r/$1:$2 $3\/$4 $5$6/;print$f, +"\n";}}} }

metadoktor

"The doktor is in."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://148228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-20 00:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found