There has been some debate at our local perl mongers group about when to meet this month, given that we meet on the second Tuesday of the month.
From: Oliver Paukstadt <***> Reply-To: Stuttgart Perl Mongers <stuttgart-pm@pm.org> To: Stuttgart Perl Mongers <stuttgart-pm@pm.org> Subject: Re: [Stuttgart-PM] Treffen DIESE Woche On Mon, 2009-04-06 at 18:59 +0200, Rolf Schaufelberger wrote: > > > > Um das mal dauerhaft und stilgerecht zu lösen : > > > > perl -MDateTime -e ' for (1..20 ) { my $d=DateTime- > > >new(year=>2009,month=>4,day=>$_); if ( $d->weekday_of_month ==2 +&& > > $d->day_of_week ==2 ) { print "$_\n"; last; }}' > > 14 > > Couldn't resist: perl -MDate::Calc=:all -le 'print Date_to_Text(Nth_Weekday_of_Month_Year(2009,4,2,2))' Gruss Oliver
Modules? Not for golf. I came up with this:
perl -le'{@l=localtime($t-=((localtime$t)[3]-1)*86400);$t+=(($l[6]<3?7 +:14)-$l[6]+2)*86400;$t<time?($t+=2592000,redo):print$..localtime$t}'
128 chars not counting perl -le and not counting the surrounding single quotes. I am sure you can do better ;-)
Rules: no modules; if the second Tuesday of the current month has passed, give the second Tuesday of the next month. No requirements on the output format except it must show the correct year, month and day (in any unambiguous order).
update: using gmtime instead of localtime gives 119 chars:
perl -le '{@l=gmtime($t-=((gmtime$t)[3]-1)*86400);$t+=(($l[6]<3?7:14)- +$l[6]+2)*86400;$t<time?($t+=2592000,redo):print$..gmtime$t}'
update 2: joint result of #perlgolf (mtve,shmem), 92 chars:
perl -le 'sub f{gmtime$_*86400}$_+=30while($_+=9+7*(($x=(f$_-=(f)[3]-1 +)[6])>2)-$x)*86400<time;print~~f'
In reply to (Golf) Next second Tuesday by shmem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |