develooper Front page | | Postings from July 2002

Re: potential Golf task - seconds -> years, days ...

Thread Next
Steffen Mueller
July 21, 2002 03:45
Re: potential Golf task - seconds -> years, days ...
Message ID:
[cc'ed to]

"Eli Bendersky" <just.answer@in.the.newsgroup> schrieb...
>     Hi all,
> Inspired by a computability discussion in a math group (you know, of
> the type "if every particle could calculate 1e50 ops/second, it would
> take N galaxies...") I started wondering how short can a program
> partitioning an amount of seconds to years, days, hours, minutes
> and seconds be made.
> For example:
> 30844803 seconds is:
> 1 year, 1 day, 0 hours, 0 minutes, 1 second
> The assumptions are simplistic, eg:
> minute = 60 seconds
> hour = 60 minutes
> day = 24 hours
> year = 365 days
> Perl is a language in which thinking of shortest programs to do
> something
> is the most fun, so this looks like a good place to post it.

The Perl Golf mailing list would probably be an even better place to post
this. Anyway, to get the guys on that list started, I cooked up a quick,
simple-minded solution that can still be improved a lot.

#!perl -l
$b=$ARGV[0];@a=(1,60,60,24,365);while($a=pop@a){$a*=$_ for@a;print

As always, I haven't spent a significant amount of time on this, so I expect
some residents to cut this thing in half and make it work

@n=(544290696690,305106661574,116357),$b=16,@c=' ,JPacehklnorstu'=~
push@p,map{$c[$_]}@c[c($b..$#c)];$#c=$b-1}print@p;sub'c{reverse @_}

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About